changeset 884:1b261e0f85aa

Abstract away the details of where svn revs are stored in a commit
author Bryan O'Sullivan <bryano@fb.com>
date Mon, 30 Apr 2012 16:08:02 -0700
parents 78ffbe411695
children 99a15c6a283c
files hgsubversion/svncommands.py hgsubversion/util.py
diffstat 2 files changed, 15 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/hgsubversion/svncommands.py
+++ b/hgsubversion/svncommands.py
@@ -3,6 +3,7 @@ import posixpath
 import cPickle as pickle
 import sys
 import traceback
+import urlparse
 
 from mercurial import commands
 from mercurial import hg
@@ -140,19 +141,18 @@ def rebuildmeta(ui, repo, args, **opts):
     for rev in repo:
         util.progress(ui, 'prepare', rev, total=numrevs)
         ctx = repo[rev]
-        extra = ctx.extra()
-        convinfo = extra.get('convert_revision', None)
+        convinfo = util.getsvnrev(ctx, None)
         if not convinfo:
             continue
         svnrevnum = int(convinfo.rsplit('@', 1)[1])
         youngest = max(youngest, svnrevnum)
 
-        if extra.get('close', None) is None:
+        if ctx.extra().get('close', None) is None:
             continue
 
         droprev = lambda x: x.rsplit('@', 1)[0]
         parentctx = ctx.parents()[0]
-        parentinfo = parentctx.extra().get('convert_revision', '@')
+        parentinfo = util.getsvnrev(parentctx, '@')
 
         if droprev(parentinfo) == droprev(convinfo):
             closed.add(parentctx.rev())
@@ -163,7 +163,7 @@ def rebuildmeta(ui, repo, args, **opts):
     for rev in repo:
         util.progress(ui, 'rebuild', rev, total=numrevs)
         ctx = repo[rev]
-        convinfo = ctx.extra().get('convert_revision', None)
+        convinfo = util.getsvnrev(ctx, None)
         if not convinfo:
             continue
         if '.hgtags' in ctx.files():
@@ -174,7 +174,7 @@ def rebuildmeta(ui, repo, args, **opts):
             newdata = ctx.filectx('.hgtags').data()
             for newtag in newdata[len(parentdata):-1].split('\n'):
                 ha, tag = newtag.split(' ', 1)
-                tagged = repo[ha].extra().get('convert_revision', None)
+                tagged = util.getsvnrev(repo[ha], None)
                 if tagged is None:
                     tagged = -1
                 else:
@@ -252,7 +252,7 @@ def rebuildmeta(ui, repo, args, **opts):
             parent = ctx
             while parent.node() != node.nullid:
                 parentextra = parent.extra()
-                parentinfo = parentextra.get('convert_revision')
+                parentinfo = util.getsvnrev(parent)
                 assert parentinfo
                 parent = parent.parents()[0]
 
@@ -408,7 +408,7 @@ def info(ui, repo, **opts):
         ui.status('Not a child of an svn revision.\n')
         return 0
     r, br = hashes[pn]
-    subdir = parent.extra()['convert_revision'][40:].split('@')[0]
+    subdir = util.getsvnrev(parent)[40:].split('@')[0]
     if meta.layout == 'single':
         branchpath = ''
     elif br == None:
--- a/hgsubversion/util.py
+++ b/hgsubversion/util.py
@@ -231,11 +231,17 @@ def issamefile(parentctx, childctx, f):
     # parentctx is not an ancestor of childctx, files are unrelated
     return False
 
+
+def getsvnrev(ctx, defval=None):
+    '''Extract SVN revision from commit metadata'''
+    return ctx.extra().get('convert_revision', defval)
+
+
 def _templatehelper(ctx, kw):
     '''
     Helper function for displaying information about converted changesets.
     '''
-    convertinfo = ctx.extra().get('convert_revision', '')
+    convertinfo = getsvnrev(ctx, '')
 
     if not convertinfo or not convertinfo.startswith('svn:'):
         return ''