As I've said in answers before, when playing with Mercurial revsets are your friend. That said, what you want doesn't appear to be covered by the revset documentation, but is mentioned in the help for the log command.
In your code you appear to be wanting a diff
of what has changed between the "newest" two tags, and the following should do the job for you:
hg diff -r "last(tagged(),2)"
I realise you're working in Python, but the above command will do the grunt work, and your Python code can focus on less menial tasks. The important part is the bit in the quotes, which I'll explain.
tagged()
is a list of all revisions that are tagged - it should refer to the same revisions as hg tags
, however it will only list each revision once, whereas hg tags
will show multiple tags for a single revision, if that's the case.
last(set,[n])
filters the set (in this case the tagged sets) to show the last n
items (n
is 1 if omitted).
The result of this is a revset that contains the last two tagged changes, which in the example above we pass into hg diff
.
Update: OK, I was thrown by the diff
in your Python. On reading again, it looks like you want basically the log
output between the last two tags? Using revsets this becomes a little more convoluted, but using the above knowledge you can create a revset like so:
hg log -r "last(tagged(),2):last(tagged())"
We're effectively picking the last two tags, and the last one tag (!!) and performing a log of all inclusive sets between them. The log
output can be tweaked with --template
, as LazyBadger has shown in his answer. I would go for a simplistic --template "{node}\t{tags}\n"
, but have a look here for more information on the fun you can have.