How to find rename data (was Re: problem with extdiff extension)

Matt Mackall mpm at selenic.com
Wed Aug 24 15:59:54 UTC 2011


On Wed, 2011-08-24 at 00:00 -0700, James Walker wrote:
> On 8/23/11 2:12 PM, Matt Mackall wrote:
> > On Tue, 2011-08-23 at 00:14 -0700, James Walker wrote:
> >> Or failing that, I wish I knew some way to take a current pathname and a
> >> revision, and ask Mercurial: What was the pathname, if any, of this file
> >> at that revision?
> >
> > The most straightforward way is:
> >
> > hg log -vf filename
> 
> 
> Maybe I'm missing something, but that doesn't seem like as good a 
> solution as I would hope for.  If I say
> 
>    hg log -vf foo
> 
> and go back a few changesets and see one that involves the files bar and 
> baz, I know that one of them is the past incarnation of foo, but which 
> one?  Maybe I can find another changeset that mentions baz but not bar, 
> or vice versa, but maybe not.
> 
> I'll grant that a human could look at a log and almost always figure out 
> what happened, but I'd like a method that can be automated.

Start with something like this:

$ hg status --rev 10 --copies mercurial/localrepo.py
A mercurial/localrepo.py
  mercurial/hg.py

This says localrepo.py was copied from hg.py some time between the
checkout and rev 10. 

We can even figure out where that happened:

$ hg log -v -r 'limit(follow("mercurial/localrepo.py") and
file("mercurial/localrepo.py"), 1)'
changeset:   1089:142b5d5ec9cc
user:        mpm at selenic.com
date:        Sat Aug 27 14:21:25 2005 -0700
files:       mercurial/changelog.py mercurial/dirstate.py
mercurial/filelog.py mercurial/hg.py mercurial/httprepo.py
mercurial/localrepo.py mercurial/manifest.py mercurial/node.py
mercurial/remoterepo.py mercurial/repo.py mercurial/revlog.py
mercurial/sshrepo.py
description:
Break apart hg.py

- move the various parts of hg.py into their own files
- create node.py to store node manipulation functions


The magical -r argument can be read as:

"Find all revisions in the history of localrepo.py where it still has
that name and show just the first one"

See 'hg help revsets' for more info.

But we usually don't need anything nearly that complicated. This command
works where this file hasn't existed multiple times:

$ hg log -l 1 -r 0: mercurial/localrepo.py
changeset:   1089:142b5d5ec9cc
user:        mpm at selenic.com
date:        Sat Aug 27 14:21:25 2005 -0700
summary:     Break apart hg.py

"Starting at rev 0, list one commit mentioning localrepo.py"

Here we can see exactly what happened in that crazy commit: lots of
files copied from hg.py. These are all 'copies' and not 'renames'
because hg.py continues to exist.

$ hg status --change 1089 -C
M mercurial/hg.py
M mercurial/revlog.py
A mercurial/changelog.py
  mercurial/hg.py
A mercurial/dirstate.py
  mercurial/hg.py
A mercurial/filelog.py
  mercurial/hg.py
A mercurial/httprepo.py
  mercurial/hg.py
A mercurial/localrepo.py
  mercurial/hg.py
A mercurial/manifest.py
  mercurial/hg.py
A mercurial/node.py
A mercurial/remoterepo.py
  mercurial/hg.py
A mercurial/repo.py
A mercurial/sshrepo.py
  mercurial/hg.py

And lastly, we can do:

$ hg diff --git -r 10 mercurial/localrepo.py
diff --git a/mercurial/hg.py b/mercurial/localrepo.py
copy from mercurial/hg.py
copy to mercurial/localrepo.py
--- a/mercurial/hg.py
+++ b/mercurial/localrepo.py
@@ -1,575 +1,2058 @@
-# hg.py - repository classes for mercurial
+# localrepo.py - read/write repository class for mercurial
 #
-# Copyright 2005 Matt Mackall <mpm at selenic.com>
...


-- 
Mathematics is the supreme nostalgia of our time.





More information about the Mercurial mailing list