[PATCH] log: fix behavior with empty repositories (issue3497)

Alexander Plavin me at aplavin.ru
Tue Apr 16 16:13:44 CDT 2013


# HG changeset patch
# User Alexander Plavin <me at aplavin.ru>
# Date 1366144194 -14400
# Node ID 75afb1573eeeba0073b65ad0287b90660363d6d5
# Parent  860e17295344a0e0b0bd88f023252fd82930fc1c
log: fix behavior with empty repositories (issue3497)

Make output in this special case consistent with general case one.

diff -r 860e17295344 -r 75afb1573eee mercurial/cmdutil.py
--- a/mercurial/cmdutil.py	Wed Apr 10 20:45:10 2013 +0400
+++ b/mercurial/cmdutil.py	Wed Apr 17 00:29:54 2013 +0400
@@ -1022,8 +1022,6 @@
 
     follow = opts.get('follow') or opts.get('follow_first')
 
-    if not len(repo):
-        return []
     if opts.get('rev'):
         revs = scmutil.revrange(repo, opts.get('rev'))
     elif follow:
diff -r 860e17295344 -r 75afb1573eee mercurial/revlog.py
--- a/mercurial/revlog.py	Wed Apr 10 20:45:10 2013 +0400
+++ b/mercurial/revlog.py	Wed Apr 17 00:29:54 2013 +0400
@@ -771,6 +771,10 @@
                 nl = [n for n in nl if hex(n).startswith(id)]
                 if len(nl) > 0:
                     if len(nl) == 1:
+                        if nl[0] == nullid:
+                            # dummy null revision always exists,
+                            # it shouldn't be returned here
+                            return None
                         self._pcache[id] = nl[0]
                         return nl[0]
                     raise LookupError(id, self.indexfile,
diff -r 860e17295344 -r 75afb1573eee mercurial/revset.py
--- a/mercurial/revset.py	Wed Apr 10 20:45:10 2013 +0400
+++ b/mercurial/revset.py	Wed Apr 17 00:29:54 2013 +0400
@@ -238,12 +238,10 @@
     return [x for x in r if x in s]
 
 def dagrange(repo, subset, x, y):
-    if subset:
-        r = list(repo)
-        xs = _revsbetween(repo, getset(repo, r, x), getset(repo, r, y))
-        s = set(subset)
-        return [r for r in xs if r in s]
-    return []
+    r = list(repo)
+    xs = _revsbetween(repo, getset(repo, r, x), getset(repo, r, y))
+    s = set(subset)
+    return [r for r in xs if r in s]
 
 def andset(repo, subset, x, y):
     return getset(repo, getset(repo, subset, x), y)
diff -r 860e17295344 -r 75afb1573eee tests/test-alias.t
--- a/tests/test-alias.t	Wed Apr 10 20:45:10 2013 +0400
+++ b/tests/test-alias.t	Wed Apr 17 00:29:54 2013 +0400
@@ -267,10 +267,13 @@
   $ hg init sub
   $ cd sub
   $ hg count 'branch(default)'
+  abort: unknown revision 'default'!
   0
   $ hg -v count 'branch(default)'
+  abort: unknown revision 'default'!
   0
   $ hg -R .. count 'branch(default)'
+  abort: unknown revision 'default'!
   0
   $ hg --cwd .. count 'branch(default)'
   2
diff -r 860e17295344 -r 75afb1573eee tests/test-glog.t
--- a/tests/test-glog.t	Wed Apr 10 20:45:10 2013 +0400
+++ b/tests/test-glog.t	Wed Apr 17 00:29:54 2013 +0400
@@ -1542,6 +1542,7 @@
   $ testlog --follow
   []
   []
+  abort: unknown revision '0'!
   $ echo a > a
   $ echo aa > aa
   $ echo f > f
diff -r 860e17295344 -r 75afb1573eee tests/test-log.t
--- a/tests/test-log.t	Wed Apr 10 20:45:10 2013 +0400
+++ b/tests/test-log.t	Wed Apr 17 00:29:54 2013 +0400
@@ -1,3 +1,20 @@
+Log on empty repository: checking consistency
+
+  $ hg init empty
+  $ cd empty
+  $ hg log
+  $ hg log -r 1
+  abort: unknown revision '1'!
+  [255]
+  $ hg log -r -1:0
+  abort: unknown revision '-1'!
+  [255]
+  $ hg log -r 'branch(name)'
+  abort: unknown revision 'name'!
+  [255]
+  $ hg log -r null -q
+  -1:000000000000
+
 The g is crafted to have 2 filelog topological heads in a linear
 changeset graph
 


More information about the Mercurial-devel mailing list