Commits

Dan Villiom Podlaski Christiansen  committed 336f4bc

consolidate revision parsing

Accept HEAD for --rev and --skiprevs as well as --startrev, and make
the error message more closely mirror the regular Mercurial error
message.

  • Participants
  • Parent commits 21197f5
  • Branches stable

Comments (0)

Files changed (2)

File hgsubversion/util.py

             return cache[args]
 
     return f
+
+def parse_revnum(svnrepo, r):
+    try:
+        return int(r or 0)
+    except ValueError:
+        if isinstance(r, str) and r.upper() == 'HEAD':
+            return svnrepo.last_changed_rev
+        else:
+            # TODO: use error.RepoLookupError when we drop 1.3?
+            raise hgutil.Abort("unknown Subversion revision %r" % r)

File hgsubversion/wrappers.py

     old_encoding = util.swap_out_encoding()
     total = None
     try:
-        try:
-            stopat_rev = int(checkout or 0)
-        except ValueError:
-            raise hgutil.Abort('unrecognised Subversion revision %s: '
-                               'only numbers work.' % checkout)
-
         have_replay = not repo.ui.configbool('hgsubversion', 'stupid')
         if not have_replay:
             repo.ui.note('fetching stupidly...\n')
         svn = source.svn
         meta = repo.svnmeta(svn.uuid, svn.subdir)
 
+        stopat_rev = util.parse_revnum(svn, checkout)
+
         layout = repo.ui.config('hgsubversion', 'layout', 'auto')
         if layout == 'auto':
             try:
 
         if start <= 0:
             # we are initializing a new repository
-            start = repo.ui.config('hgsubversion', 'startrev', 0)
-            if isinstance(start, str) and start.upper() == 'HEAD':
-                start = svn.last_changed_rev
-            else:
-                start = int(start)
+            start = util.parse_revnum(svn, repo.ui.config('hgsubversion',
+                                                          'startrev', 0))
 
             if start > 0:
                 if layout == 'standard':
                 start = 0
 
         skiprevs = repo.ui.configlist('hgsubversion', 'unsafeskip', '')
-        try:
-            skiprevs = set(map(int, skiprevs))
-        except ValueError:
-            raise hgutil.Abort('unrecognised Subversion revisions %r: '
-                               'only numbers work.' % checkout)
+        skiprevs = set(util.parse_revnum(svn, r) for r in skiprevs)
 
         oldrevisions = len(meta.revmap)
         if stopat_rev: