4

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?

shabunc
  • 23,119
  • 19
  • 77
  • 102
  • Please note that "changed" and "committed" files in the context of Mercurial are two completely separate topics. You can change a file, and then commit it. You can add a file and then commit it. Basically, your question title doesn't make much sense, because it would imply you want to know the difference between files that are changed, and about to be committed, and files that have previously been committed... Can you elaborate on what you actually want to get the answer to? Concrete examples would go a long way. – Lasse V. Karlsen Jul 04 '14 at 20:20
  • @LasseV.Karlsen but mercurial **does** know the difference **before** commit, since it shows in commit template exactly files that are going to be committed, not the changed ones. But yes, let me be more precise, how to get files that are marked as committed. Say, I've changes files A, B and C, and afterwards i'm doing hg ci B - changed files are A, B, C, file that is marked committed is B. – shabunc Jul 04 '14 at 23:45

0 Answers0