Mercurial API -- "debug"
David Dyer-Bennet
dd-b at dd-b.net
Tue Jun 15 14:04:47 UTC 2010
On Mon, June 14, 2010 16:39, Matt Mackall wrote:
> On Mon, 2010-06-14 at 16:20 -0500, David Dyer-Bennet wrote:
>> The Wiki docs on the Mercurial API seem rather thin. Am I missing the
>> preferred data source? Or is this one of those situations where I'm
>> supposed to directly read the source? I'm used to an API being
>> documented.
>
> Whoever said you ought to write a hook in Python using Mercurial's API
> was not giving you the best advice in my opinion. The API is not
> 'public' in the sense that it's neither stable or documented. Nor should
> it be necessary for typical hook uses.
My interpretation of earlier responses here on the list.
>> (I'm successfully iterating through a list of the files in the changeset
>> being created by a commit, though, that's nice! This does indeed get
>> around the problem I noticed last week with parsing filenames produced
>> by
>> hg log -r <node> --template etc. that contained spaces (including in
>> directory names)).
>
> There's a chapter in the book about templating that explains how to deal
> with file lists:
>
> http://hgbook.red-bean.com/read/customizing-the-output-of-mercurial.html
>
> Search for "listing files on multiple lines". I'm planning to revamp the
> templating engine soon so that this will become something like:
>
> hg log --template "changeset {rev}:\n{map(' {file}\n', files)}"
>
> with no need for a style map.
I've looked at the templating stuff, but didn't quite notice that it
provided me ways to separate out the individual list elements.
While it'll work in practice, it doesn't work in theory. On Unix, the
only characters actually forbidden in file names are '/' and NUL; hence
using the line breaks to parse out the individual names isn't safe.
However, actually using newline in file names is extraordinarily rare,
it's probably safe enough in practice.
--
David Dyer-Bennet, dd-b at dd-b.net; http://dd-b.net/
Snapshots: http://dd-b.net/dd-b/SnapshotAlbum/data/
Photos: http://dd-b.net/photography/gallery/
Dragaera: http://dragaera.info
More information about the Mercurial
mailing list