mercurialposixfile-ownership

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 matter anyway... :)


Solution

  • 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.