Patchwork [2,of,8,V3] addremove: warn when addremove fails to operate on a named path

login
register
mail settings
Submitter Matt Harbison
Date Dec. 12, 2014, 3:35 a.m.
Message ID <c9c90f5a0d75593301d7.1418355314@Envy>
Download mbox | patch
Permalink /patch/7056/
State Accepted
Commit 83bbedc16b3f71e34fb67007c437a54baf4faeac
Headers show

Comments

Matt Harbison - Dec. 12, 2014, 3:35 a.m.
# HG changeset patch
# User Matt Harbison <matt_harbison@yahoo.com>
# Date 1417030056 18000
#      Wed Nov 26 14:27:36 2014 -0500
# Node ID c9c90f5a0d75593301d725a0784fca57f429e606
# Parent  b86d74857424e1869c51acd937dc38ba6a0009c8
addremove: warn when addremove fails to operate on a named path

It looks like a bad path is the only mode of failure for addremove.  This
warning is probably useful for the standalone command, but more important for
'commit -A'.  That command doesn't currently abort if the addremove fails, but
it will be made to do so prior to adding subrepo support, since not all subrepos
will support addremove.  We could just abort here, but it looks like addremove
has always silently ignored bad paths, except for the exit code.
Martin von Zweigbergk - Dec. 12, 2014, 4:49 p.m.
On Thu Dec 11 2014 at 7:35:56 PM Matt Harbison <mharbison72@gmail.com>
wrote:

> +#if windows
> +  $ hg -v addremove nonexistant
> +  nonexistant: The system cannot find the file specified
> +  [1]
> +#else
> +  $ hg -v addremove nonexistant
> +  nonexistant: No such file or directory
> +  [1]
> +#endif
>

I once used a glob in a case like this ("nonexistant: * (glob)"). It's
shorter and should work on systems that produce yet another message, but
it's also less specific. What do the more experienced Mercurial developers
say? I haven't tried to search for examples myself (sorry).
Augie Fackler - Dec. 12, 2014, 5:03 p.m.
On Fri, Dec 12, 2014 at 04:49:26PM +0000, Martin von Zweigbergk wrote:
> On Thu Dec 11 2014 at 7:35:56 PM Matt Harbison <mharbison72@gmail.com>
> wrote:
>
> > +#if windows
> > +  $ hg -v addremove nonexistant
> > +  nonexistant: The system cannot find the file specified
> > +  [1]
> > +#else
> > +  $ hg -v addremove nonexistant
> > +  nonexistant: No such file or directory
> > +  [1]
> > +#endif
> >
>
> I once used a glob in a case like this ("nonexistant: * (glob)"). It's
> shorter and should work on systems that produce yet another message, but
> it's also less specific. What do the more experienced Mercurial developers
> say? I haven't tried to search for examples myself (sorry).

I don't feel strongly one way or the other. Both seem fine.

> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel

Patch

diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py
--- a/mercurial/scmutil.py
+++ b/mercurial/scmutil.py
@@ -721,9 +721,15 @@ 
         similarity = float(opts.get('similarity') or 0)
 
     rejected = []
-    m.bad = lambda x, y: rejected.append(x)
+    origbad = m.bad
+    def badfn(f, msg):
+        if f in m.files():
+            origbad(f, msg)
+        rejected.append(f)
 
+    m.bad = badfn
     added, unknown, deleted, removed, forgotten = _interestingfiles(repo, m)
+    m.bad = origbad
 
     unknownset = set(unknown + forgotten)
     toprint = unknownset.copy()
diff --git a/tests/test-addremove.t b/tests/test-addremove.t
--- a/tests/test-addremove.t
+++ b/tests/test-addremove.t
@@ -22,6 +22,16 @@ 
   $ hg forget foo
   $ hg -v addremove
   adding foo
+  $ hg forget foo
+#if windows
+  $ hg -v addremove nonexistant
+  nonexistant: The system cannot find the file specified
+  [1]
+#else
+  $ hg -v addremove nonexistant
+  nonexistant: No such file or directory
+  [1]
+#endif
   $ cd ..
 
   $ hg init subdir