[PATCH] imported patch revpair-extended

yozh at mx1.ru yozh at mx1.ru
Sun Feb 15 11:31:40 CST 2009


# HG changeset patch
# User Stepan Koltsov <stepancheg at yandex-team.ru>
# Date 1234718985 -10800
# Node ID e96b2c92dca2fdd3633041c09f05083fda175838
# Parent  e3ff0d7b66881dee451cf483b3516347b05c0660
imported patch revpair-extended

diff -r e3ff0d7b6688 -r e96b2c92dca2 mercurial/cmdutil.py
--- a/mercurial/cmdutil.py	Sun Feb 15 20:29:43 2009 +0300
+++ b/mercurial/cmdutil.py	Sun Feb 15 20:29:45 2009 +0300
@@ -7,11 +7,12 @@
 
 from node import hex, nullid, nullrev, short
 from i18n import _
-import os, sys, bisect, stat
+import os, sys, bisect, stat, re
 import mdiff, bdiff, util, templater, templatefilters, patch, errno, error
 import match as _match
 
-revrangesep = ':'
+def split_revrange(val):
+    return re.split("(?<!:):(?!:)", val, 1)
 
 def findpossible(cmd, table, strict=False):
     """
@@ -118,14 +119,17 @@
         return repo.dirstate.parents()[0], None
     end = None
     if len(revs) == 1:
-        if revrangesep in revs[0]:
-            start, end = revs[0].split(revrangesep, 1)
+        revrangelist = split_revrange(revs[0])
+        if len(revrangelist) == 2:
+            start, end = revrangelist
             start = revfix(repo, start, 0)
             end = revfix(repo, end, len(repo) - 1)
+        elif len(revrangelist) == 1:
+            start = revfix(repo, revrangelist[0], None)
         else:
-            start = revfix(repo, revs[0], None)
+            raise util.Abort(_('internal error'))
     elif len(revs) == 2:
-        if revrangesep in revs[0] or revrangesep in revs[1]:
+        if len(split_revrange(revs[0])) > 1 or len(split_revrange(revs[1])) > 1:
             raise util.Abort(_('too many revisions specified'))
         start = revfix(repo, revs[0], None)
         end = revfix(repo, revs[1], None)
@@ -143,8 +147,9 @@
 
     seen, l = {}, []
     for spec in revs:
-        if revrangesep in spec:
-            start, end = spec.split(revrangesep, 1)
+        revrangelist = split_revrange(spec)
+        if len(revrangelist) > 1:
+            start, end = revrangelist
             start = revfix(repo, start, 0)
             end = revfix(repo, end, len(repo) - 1)
             step = start > end and -1 or 1
@@ -153,12 +158,14 @@
                     continue
                 seen[rev] = 1
                 l.append(rev)
-        else:
+        elif len(revrangelist) == 1:
             rev = revfix(repo, spec, None)
             if rev in seen:
                 continue
             seen[rev] = 1
             l.append(rev)
+        else:
+            raise util.Abort(_('internal error'))
 
     return l
 
diff -r e3ff0d7b6688 -r e96b2c92dca2 mercurial/localrepo.py
--- a/mercurial/localrepo.py	Sun Feb 15 20:29:43 2009 +0300
+++ b/mercurial/localrepo.py	Sun Feb 15 20:29:45 2009 +0300
@@ -463,6 +463,15 @@
                 if pn in bheads:
                     bheads.remove(pn)
 
+    def _branchbase(self, key):
+        node = self[key]
+        if node.rev() == 0:
+            return node.node()
+        node = node.parents()[0]
+        while len(node.children()) == 1 and node.rev() != 0:
+            node = node.parents()[0]
+        return node.node()
+    
     def lookup(self, key):
         if isinstance(key, int):
             return self.changelog.node(key)
@@ -487,6 +496,9 @@
                 key = hex(key)
         except:
             pass
+        if key.startswith("branch-base::"):
+            return self._branchbase(key[len("branch-base::"):])
+           
         raise error.RepoError(_("unknown revision '%s'") % key)
 
     def local(self):
diff -r e3ff0d7b6688 -r e96b2c92dca2 tests/test-branchbase
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-branchbase	Sun Feb 15 20:29:45 2009 +0300
@@ -0,0 +1,42 @@
+#!/bin/sh -e
+
+ec() {
+    echo "#" "$@"
+    "$@"
+}
+
+ec hg init x
+
+ec cd x
+
+echo "some commit" > f.txt
+hg add f.txt
+hg ci -m 'some message' # 0
+
+echo "branch base" > f.txt
+hg ci -m 'branch base' # 1
+
+hg up 1
+echo 2 > f.txt
+hg ci -m '2' # 2
+
+hg up 1
+echo 3 > f.txt
+hg ci -m '3' # 3
+
+echo 4 > f.txt
+hg ci -m '4' # 4
+
+# these should produce same result
+ec hg log -r branch-base::.
+ec hg log -r branch-base::3
+
+# Branch base of root is a first changeset
+ec hg log -r branch-base::1
+ec hg log -r branch-base::0
+
+# testing diff works
+
+ec hg diff -r branch-base::3:3 # 1 to 3
+
+# vim: set ts=4 sw=4 et:
diff -r e3ff0d7b6688 -r e96b2c92dca2 tests/test-branchbase.out
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-branchbase.out	Sun Feb 15 20:29:45 2009 +0300
@@ -0,0 +1,36 @@
+# hg init x
+# cd x
+0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+created new head
+# hg log -r branch-base::.
+changeset:   1:3a26a10b008c
+user:        test
+date:        Thu Jan 01 00:00:00 1970 +0000
+summary:     branch base
+
+# hg log -r branch-base::3
+changeset:   1:3a26a10b008c
+user:        test
+date:        Thu Jan 01 00:00:00 1970 +0000
+summary:     branch base
+
+# hg log -r branch-base::1
+changeset:   0:ab9c02aca3ed
+user:        test
+date:        Thu Jan 01 00:00:00 1970 +0000
+summary:     some message
+
+# hg log -r branch-base::0
+changeset:   0:ab9c02aca3ed
+user:        test
+date:        Thu Jan 01 00:00:00 1970 +0000
+summary:     some message
+
+# hg diff -r branch-base::3:3
+diff -r 3a26a10b008c -r 1c819642afae f.txt
+--- a/f.txt	Thu Jan 01 00:00:00 1970 +0000
++++ b/f.txt	Thu Jan 01 00:00:00 1970 +0000
+@@ -1,1 +1,1 @@
+-branch base
++3


More information about the Mercurial-devel mailing list