Determining what files were touched in a changeset algorithmically

Haszlakiewicz, Eric EHASZLA at transunion.com
Thu Jun 23 13:32:49 CDT 2011


> -----Original Message-----
> From: mercurial-bounces at selenic.com [mailto:mercurial-
> 
> I am working on some analysis tools for hg logs.
> 
> hg log --template "{files}" is the naive way to do this.
> 
> Demonstration of problem:
> 
> $ hg log -r 34 --template "{file_mods}\n"
> baz baz baz foo bar spacey.txt
> 
> What files were modified?
> 
> In order to determine this, I have to run manifest on 34 and perform
> some lexical analysis for all files in that changeset to determine
> which files actually got modified.
> 
> Reviewing the hg source code, the rendering code (showlist function in
> http://selenic.com/hg/file/8deebb577751/mercurial/templatekw.py
> <http://selenic.com/hg/file/8deebb577751/mercurial/templatekw.py> )
> performs a join with spaces here. This is... problematic for fast
> algorithmic determination.

You can do this with a custom template map file, which can be selected with the --style option.  For example, see the map-cmdline.gward referred to in this thread:

http://mercurial.808500.n3.nabble.com/How-to-get-a-list-of-changed-files-td808109.html

It has lines like:

changeset = '...{file_mods}{file_adds}{file_dels}{file_copies_switch}...'
file_mod = '  M {file_mod}\n'
end_file_mods = ''
file_add = '  A {file_add}\n'
end_file_adds = ''
file_del = '  R {file_del}\n'
end_file_dels = ''

 to display the changes in a much more readable fashion.  (IMO this should be the default, since the current default is pretty horrible)

Since mercurial explicitly doesn't allow newlines in filenames (due to protocol limitations, at least with earlier versions of hg), using a newline as the delimiter is guaranteed to work for every file that might be in a repository.

eric



More information about the Mercurial mailing list