Commits

Bryan O'Sullivan committed 1b261e0

Abstract away the details of where svn revs are stored in a commit

  • Participants
  • Parent commits 78ffbe4

Comments (0)

Files changed (2)

File hgsubversion/svncommands.py

 import cPickle as pickle
 import sys
 import traceback
+import urlparse
 
 from mercurial import commands
 from mercurial import hg
     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())
     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():
             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:
             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]
 
         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:

File hgsubversion/util.py

     # 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 ''