I have following piece of code for fetching a list of all files in current changeset:
def changesets(repo, node):
if node == None:
yield repo[None]
else:
for rev in xrange(repo[node].rev(), len(repo)):
yield repo[rev]
def files(repo, node):
for ctx in changesets(repo, node):
for filename in ctx.files():
...
But it turns out that in changeset.files() returns all files that had been changed, not only those that are marked as committed ones.
Mercurial, of course, actually knows the difference between those two kind of files, so I've checked out the code in mercurial/cmdutil.py
from the mercurial repo, and found this piece of code:
modified, added, removed = ctx.modified(), ctx.added(), ctx.removed()
...
edittext.extend([_("HG: added %s") % f for f in added])
edittext.extend([_("HG: changed %s") % f for f in modified])
edittext.extend([_("HG: removed %s") % f for f in removed])
But the thing is that in pre-commit hook all files are marked as modified, not sure whether this is intentional or is it a bug.
OK, next thing I've tried was to use pretxncommit
or commit
hook instead of precommit
, but in this case ctx has not modified
, added
and removed
methods at all.
So, the question is: How to tell apart changed files and ones that going to be committed in the pre-commit hook?