Mercurial: How do I find the creator of a file?
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 开发者_如何学JAVAmatter anyway... :)
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 revsets or hg help revsets
for more info.
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.
If you only need the author information you can do
hg log -r 'first(file("path/to/file"))' --template '{author}\n'
as I was suggested by krigstask in #mercurial
9 seconds faster too :)
精彩评论