changeset 18991:c1af1fb314bc

log: fix behavior with empty repositories (issue3497) Make output in this special case consistent with general case one.
author Alexander Plavin <me@aplavin.ru>
date Wed, 17 Apr 2013 00:29:54 +0400
parents 7373be706f02
children a54ddfae8907
files mercurial/cmdutil.py mercurial/revlog.py mercurial/revset.py tests/test-alias.t tests/test-glog.t tests/test-log.t
diffstat 6 files changed, 29 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/cmdutil.py	Tue Apr 16 13:22:29 2013 -0500
+++ 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:
--- a/mercurial/revlog.py	Tue Apr 16 13:22:29 2013 -0500
+++ 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,
--- a/mercurial/revset.py	Tue Apr 16 13:22:29 2013 -0500
+++ 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)
--- a/tests/test-alias.t	Tue Apr 16 13:22:29 2013 -0500
+++ 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
--- a/tests/test-glog.t	Tue Apr 16 13:22:29 2013 -0500
+++ 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
--- a/tests/test-log.t	Tue Apr 16 13:22:29 2013 -0500
+++ 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