Is there any way to get an immutable file ID for a file in repository?
I need an identifier which will survive a file rename. So if there was file Test01.txt and it was renamed to Test02.txt (using TortoiseHG rename menu item or the hg rename command). I want to have some ID which will correspond to Test01.txt at revision 1 and Test02.txt at revision 2.
Mercurial does not give any ID to files. This is different from some other systems, such as Bazaar, where each file (and directory) has a unique ID that follows the file throughout it’s life time.
The structure in a Mercurial repository is as follows:
So if you add
Test01.txtin revision 0, then you’ll have a chain like thisIf you now rename and make a new commit, you will create a new changelog and manifest entry, and create a new filelog for
Test02.txt:The new
Test02.txtfilelog entry will reference theTest01.txtentry. This is how Mercurial can keep track of renames:The best “file ID” you can talk about is therefore the ID of the first entry in the original file log. You can dig it out with
hg debugindex:The “nodeid” column gives you the IDs for the revlog entries in the filelog for
Test01.txt. Here we see that the first revision of the file has ID0936f74a5857. This is just a short, 12 character prefix of the full 40 character SHA-1 hash. If you need the full hash, then read on…The “linkrev” tells you that this version of the file is referenced by changeset 0. You can lookup the data in that changelog entry with
hg debugdata -c 0, but for our purposes the normalhg logcommand also has the information:We’re interested in the manifest ID. You can now look up the data in the correct manifest entry with:
There is really a
NULbyte between the file name and the filelog ID, but it’s not visible in your terminal. You now have the full filelog ID for the first revision of theTest01.txtfile.You also need to go from
Test02.txttoTest01.txt. You can usehg log --followandhg debugrenamefor this: usehg logto get the revisions concerning the file, and usehg debugrenameto see what the file was renamed from in each step.