Bug 3114 - follow() revset aborts with a confusing error message in certain cases
Summary: follow() revset aborts with a confusing error message in certain cases
Status: RESOLVED FIXED
Alias: None
Product: Mercurial
Classification: Unclassified
Component: Mercurial (show other bugs)
Version: unspecified
Hardware: All All
: normal bug
Assignee: Bugzilla
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-11-18 15:33 UTC by brodie
Modified: 2012-05-13 05:10 UTC (History)
4 users (show)

See Also:
Python Version: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description brodie 2011-11-18 15:33 UTC
$ hg init foo
  $ cd foo

First, note the behavior with an empty repo:

  $ hg log -r 'follow(a)' --template '{rev}\n'
  $ hg log -r 'follow(foo)' --template '{rev}\n'

There's no output. Makes sense. Let's add a file:

  $ echo a > a
  $ hg ci -Am a

Now, with the working directory at revision 1, let's try to find a and foo:

  $ hg log -r 'follow(a)' --template '{rev}\n'
  0
  $ hg log -r 'follow(foo)' --template '{rev}\n'
  abort: foo@f88987657351: not found in manifest!

If we update back to null:

  $ hg up null
  $ hg log -r 'follow(a)' --template '{rev}\n'
  abort: a@000000000000: not found in manifest!
  $ hg log -r 'follow(foo)' --template '{rev}\n'
  abort: foo@000000000000: not found in manifest!

In every case where I get an error message, I would've expected to get no output instead. After 
all, file(foo) does that:

  $ hg log -r 'file(foo)' --template '{rev}\n'

Also, note that, even more confusingly, --follow a doesn't behave exactly the same way:

  $ hg up null
  $ hg log -f a --template '{rev}\n'
  0
  $ hg up 0
  $ hg log -f a --template '{rev}\n'
  0

However, --follow foo does blow up:

  $ hg log -f foo --template '{rev}\n'
  abort: cannot follow nonexistent file: "foo"

It doesn't seem there's any exact revset equivalent to --follow.
Comment 1 Matt Mackall 2011-11-18 15:45 UTC
Does this do what you want?

diff -r e7119b091809 mercurial/revset.py
--- a/mercurial/revset.py	Thu Nov 17 23:02:18 2011 -0600
+++ b/mercurial/revset.py	Fri Nov 18 15:43:19 2011 -0600
@@ -434,7 +434,10 @@
     p = repo['.'].rev()
     if l:
         x = getstring(l[0], _("follow expected a filename"))
-        s = set(ctx.rev() for ctx in repo['.'][x].ancestors())
+        if x in repo['.']:
+            s = set(ctx.rev() for ctx in repo['.'][x].ancestors())
+        else:
+            return []
     else:
         s = set(repo.changelog.ancestors(p))
Comment 2 brodie 2011-11-18 16:13 UTC
I think that would make more sense, yeah.

The thing I noticed with --follow giving matching a revision when I was at 
null seems to be an edge case. The default rev range in that case was null:0.

Also, it would be nice if there were a way to find a file across renames with 
a revset without having to have a working copy.
Comment 3 HG Bot 2011-11-20 17:00 UTC
Fixed by http://selenic.com/repo/hg/rev/5edaf47cd462
Matt Mackall <mpm@selenic.com>
revset: follow(nosuchfile) should give an empty set (issue3114)

(please test the fix)
Comment 4 Bugzilla 2012-05-12 09:25 UTC

--- Bug imported by bugzilla@serpentine.com 2012-05-12 09:25 EDT  ---

This bug was previously known as _bug_ 3114 at http://mercurial.selenic.com/bts/issue3114