Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Mercurial next commit hash

Tags:

mercurial

I am at revision 56, hash 6af16aa3edf8. Next revision will be 57, with hash ???. Is there a way to know the hash of revision 57? I need it in a pre-commit hook.

WHY THO?

I developed a script, called via pre-commit hook, that update some version files. That way, the compiled executables can give all info about the revision they are build from. I'm adding the revision number of the current commit in my version file, simply retrieved with "parent revision number + 1". Since the revision number is not reliable when collaborating with other people on the same repository, I prefer to add the hash, too. Don't know how to retrieve it...

like image 248
il_mix Avatar asked Jul 17 '26 15:07

il_mix


1 Answers

No, you cannot predict the next hash even when you know its changeset completely. The commit time also plays a role there:

~/hg-test $ hg ci -m "b in foo"
~/hg-test $ hg id
d65d61e6898a tip
~/hg-test $ hg rollback
~/hg-test $ hg ci -m "b in foo"
~/hg-test $ hg id
c7f5ff744e43 tip

https://www.mercurial-scm.org/wiki/Nodeid

I suggest to solve your problem such: In your build tools, query whether the project is built from a repository. If so: retrieve the repository information. E.g.

ver = $(hg log -r. -T"{node|short} from {date|isodate}")

will give you

c7f5ff744e43 from 2017-07-26 14:05 +0200

Generate the version file from that information in your build chain on the fly

For distribution purposes, generate and amend this file to the package, so that the build process, when it finds it is not started from a repository checkout, still has a version file it can make use of.

like image 96
planetmaker Avatar answered Jul 22 '26 05:07

planetmaker



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!