views:

66

answers:

2

ATM I do it this way which is far slow and incorrect:

for i in `find -type f`; do
  echo $i`LANG=C hg log -v $i | grep user | tail -1 | awk '{print " "; print $2}'`;
done

When someone has moved a file to a new name, yes he is the creator of that new file, but not of the code which he moved. I could extract the revision number out of the first commit and check somehow if this file was renamed.. (sounds very complex)

I just want to know it, for some reason :), since we have no code ownership in our project, it does not matter anyway... :)

A: 

You can make things a little more efficient by changing your hg log command to:

hg log -r : -l 1 $i --template "{files} {author} {rev}\n"

The -r : reverses the order of the log output and the -l 1 shows just the first entry in the log; together, they show the earliest revision of whatever filename is in $i. The --template switch customizes the output, in this case, I'm showing the filename, the author and the revision where the file was introduced. See hg help templating for more information.

Another optimization would be to use the output of hg manifest piped through xargs; find -type f will return all files, so if you've got object files or other untracked files in the working directory, you'll be running hg log on them unnecessarily.

Unfortunately, this won't help you find where people have copied files without telling Mercurial about it.

Niall C.
Adding `-f` will make Mercurial follow the history back across renames.
Martin Geisler
+2  A: 

If you're using a new-ish version of hg, you can use revsets to make this super-easy:

hg log -r 'adds(\"path/to/file\")'

(you might have to change the escaping of that, depending on your shell.)

The adds function finds the changesets where the given file was added. There are a bunch of other functions; see http://selenic.com/hg/help/revsets or hg help revsets for more info.

kevingessner
Excelent!, I just created a mercurial backport for that :D, great.
brubelsabs
But if I see it correctly, even when hg mv was used, the tracking ends when the file was renamed :(. Unfortunately I found no better function then `adds`, but the command line is much more easier then mine above..
brubelsabs