changeset 404:28e4b47b2179

add a working incoming wrapper command
author Dirkjan Ochtman <dirkjan@ochtman.nl>
date Wed, 10 Jun 2009 14:55:26 +0200
parents 37c96b78b8c0
children a98b8d424221
files hgsubversion/__init__.py hgsubversion/svncommands.py hgsubversion/svnrepo.py hgsubversion/wrappers.py
diffstat 4 files changed, 33 insertions(+), 49 deletions(-) [+]
line wrap: on
line diff
--- a/hgsubversion/__init__.py
+++ b/hgsubversion/__init__.py
@@ -50,6 +50,7 @@ wrapcmds = { # cmd: generic, target, fix
     ]),
     'pull': (True, 'sources', True, True, []),
     'push': (True, 'destinations', True, True, []),
+    'incoming': (False, 'sources', True, True, []),
     'clone': (False, 'sources', True, True, [
         ('T', 'tagpaths', '',
          'list of paths to search for tags in Subversion repositories'),
--- a/hgsubversion/svncommands.py
+++ b/hgsubversion/svncommands.py
@@ -13,48 +13,6 @@ import utility_commands
 import svnexternals
 
 
-def incoming(ui, svn_url, hg_repo_path, skipto_rev=0, stupid=None,
-             tag_locations='tags', authors=None, filemap=None, **opts):
-    """show incoming revisions from Subversion
-    """
-    svn_url = util.normalize_url(svn_url)
-
-    initializing_repo = False
-    user, passwd = util.getuserpass(opts)
-    svn = svnwrap.SubversionRepo(svn_url, user, passwd)
-    author_host = ui.config('hgsubversion', 'defaulthost', svn.uuid)
-    tag_locations = tag_locations.split(',')
-    hg_editor = hg_delta_editor.HgChangeReceiver(hg_repo_path,
-                                                 ui_=ui,
-                                                 subdir=svn.subdir,
-                                                 author_host=author_host,
-                                                 tag_locations=tag_locations,
-                                                 authors=authors,
-                                                 filemap=filemap,
-                                                 uuid=svn.uuid)
-    start = max(hg_editor.last_known_revision(), skipto_rev)
-    initializing_repo = (hg_editor.last_known_revision() <= 0)
-
-    if initializing_repo and start > 0:
-        raise hgutil.Abort('Revision skipping at repository initialization '
-                           'remains unimplemented.')
-
-    rev_stuff = (('revision', 'revnum'),
-                 ('user', 'author'),
-                 ('date', 'date'),
-                 ('message', 'message')
-                )
-
-    ui.status('incoming changes from %s\n' % svn_url)
-
-    for r in svn.revisions(start=start):
-        ui.status('\n')
-        for label, attr in rev_stuff:
-            l1 = label+':'
-            ui.status('%s%s\n' % (l1.ljust(13),
-                                  str(r.__getattribute__(attr)).strip(), ))
-
-
 def verify(ui, repo, *args, **opts):
     '''verify current revision against Subversion repository
     '''
@@ -249,7 +207,6 @@ table = {
     'update': update,
     'help': help,
     'rebuildmeta': rebuildmeta,
-    'incoming': incoming,
     'updateexternals': svnexternals.updateexternals,
     'verify': verify,
 }
--- a/hgsubversion/svnrepo.py
+++ b/hgsubversion/svnrepo.py
@@ -68,12 +68,6 @@ def generate_repo_class(ui, repo):
         def findoutgoing(self, remote, base=None, heads=None, force=False):
             return wrappers.outgoing(repo, remote, heads, force)
 
-        @remotesvn
-        def findcommonincoming(self, remote, base=None, heads=None,
-                               force=False):
-            raise hgutil.Abort('cannot display incoming changes from '
-                               'Subversion repositories, yet')
-
     repo.__class__ = svnlocalrepo
 
 class svnremoterepo(mercurial.repo.repository):
--- a/hgsubversion/wrappers.py
+++ b/hgsubversion/wrappers.py
@@ -24,6 +24,13 @@ pullfuns = {
     False: stupidmod.convert_rev,
 }
 
+revmeta = [
+    ('revision', 'revnum'),
+    ('user', 'author'),
+    ('date', 'date'),
+    ('message', 'message'),
+]
+
 def parents(orig, ui, repo, *args, **opts):
     """show Mercurial & Subversion parents of the working dir or revision
     """
@@ -40,6 +47,31 @@ def parents(orig, ui, repo, *args, **opt
     return 0
 
 
+def incoming(orig, ui, repo, source='default', **opts):
+    """show incoming revisions from Subversion
+    """
+
+    source, revs, checkout = hg.parseurl(ui.expandpath(source))
+    other = hg.repository(ui, source)
+    if 'subversion' not in other.capabilities:
+        return orig(ui, repo, source, **opts)
+
+    user, passwd = util.getuserpass(opts)
+    svn = svnwrap.SubversionRepo(other.svnurl, user, passwd)
+    hg_editor = hg_delta_editor.HgChangeReceiver(repo=repo)
+    start = hg_editor.last_known_revision()
+
+    ui.status('incoming changes from %s\n' % other.svnurl)
+    for r in svn.revisions(start=start):
+        ui.status('\n')
+        for label, attr in revmeta:
+            l1 = label + ':'
+            val = str(getattr(r, attr)).strip()
+            if not ui.verbose:
+                val = val.split('\n')[0]
+            ui.status('%s%s\n' % (l1.ljust(13), val))
+
+
 def outgoing(repo, dest=None, heads=None, force=False):
     """show changesets not found in the Subversion repository
     """