[PATCH] [hg annotate nonexistent exits on error (issue1590)

Loic Dachary loic at dachary.org
Wed Mar 16 16:45:37 CDT 2011


# HG changeset patch
# User loic at dachary.org
# Date 1300311694 -3600
# Node ID b3a0db338d9b01781448b8d938b9ac70d289d569
# Parent  30a0e3519f69142288d3d5b6d64a966cf171163d
Add the ignoremissing argument to context.py:walk.
It is True by default. When ignoremissing is false, context.py:walk returns
a tuple of the form (filename, bool). For instance ('foo', True) if the file
'foo' is found in the repository and ('bar', False) if the file was not found.
The command.py:annotate is modified to use this information and raise an
exception when a file is not found instead of silently ignoring it.

diff -r 30a0e3519f69 -r b3a0db338d9b mercurial/commands.py
--- a/mercurial/commands.py	Tue Mar 15 16:53:46 2011 -0500
+++ b/mercurial/commands.py	Wed Mar 16 22:41:34 2011 +0100
@@ -129,7 +129,10 @@
     ctx = cmdutil.revsingle(repo, opts.get('rev'))
     m = cmdutil.match(repo, pats, opts)
     follow = not opts.get('no_follow')
-    for abs in ctx.walk(m):
+    for (abs, found) in ctx.walk(m, False):
+        if not found:
+            raise util.Abort(_('%s did not match any file') % abs)
+
         fctx = ctx[abs]
         if not opts.get('text') and util.binary(fctx.data()):
             ui.write(_("%s: binary file\n") % ((pats and m.rel(abs)) or abs))
diff -r 30a0e3519f69 -r b3a0db338d9b mercurial/context.py
--- a/mercurial/context.py	Tue Mar 15 16:53:46 2011 -0500
+++ b/mercurial/context.py	Wed Mar 16 22:41:34 2011 +0100
@@ -186,7 +186,7 @@
         n = self._repo.changelog.ancestor(self._node, n2)
         return changectx(self._repo, n)
 
-    def walk(self, match):
+    def walk(self, match, ignoremissing=True):
         fset = set(match.files())
         # for dirstate.walk, files=['.'] means "walk the whole tree".
         # follow that here, too
@@ -198,10 +198,18 @@
                     fset.remove(ffn)
                     break
             if match(fn):
-                yield fn
+                if ignoremissing:
+                    yield fn
+                else:
+                    yield (fn, True)
         for fn in sorted(fset):
             if match.bad(fn, _('no such file in rev %s') % self) and match(fn):
-                yield fn
+                if ignoremissing:
+                    yield fn
+                else:
+                    yield (fn, True)
+            elif not ignoremissing:
+                yield (fn, False)
 
     def sub(self, path):
         return subrepo.subrepo(self, path)
diff -r 30a0e3519f69 -r b3a0db338d9b tests/test-issue1590.t
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-issue1590.t	Wed Mar 16 22:41:34 2011 +0100
@@ -0,0 +1,11 @@
+http://mercurial.selenic.com/bts/issue1590
+
+The exit status of annotate when a file does not exist must
+not be 0
+
+  $ hg init
+
+  $ hg annotate nonexistent
+  nonexistent: no such file in rev 000000000000
+  abort: nonexistent did not match any file
+  [255]


More information about the Mercurial-devel mailing list