Mercurial 2.1.1 - Determine if a changeset is a merge

144 Views Asked by At

In Mercurial 2.4 a template keyword {p2rev} was added that can be used to determine if a changeset is a merge.

hg log -r42 --template {p2rev}

If this returns "-1", there is no second parent, hence the changeset is not a merge, otherwise it is a merge.

But most devs here still are on Mercurial 2.1.1. Using {p2rev} on their machines always returns [blank].

I tried in 2.1.1:

hg log -r42 --template {parents}

and this gives a bit weird output:

  • if there is only 1 parent (not a merge): no output
  • if there are 2 parents (merge): the {rev}:{node} of both parents

What is the best way to determine if a changeset is a merge in Mercurial pre-2.4, say 2.1.1 ?

3

There are 3 best solutions below

1
On

I am using Mercurial 2.2.2 (Ubuntu 12.10) and it seems that this is working (using the Revision Sets query language):

$ hg log -r 'merge()'
changeset:   6:f75b34694a73
parent:      4:129b7b24f6b4
parent:      5:85771af34f42
[...]
summary:     Merge branch 'default' of /foo/proto

changeset:   12:04975792d1f3
parent:      10:42c64107845f
parent:      11:226623b54bd2
[...]
summary:     merged branch 'experimental-bar' into 'default'
0
On

If

hg log -r"42 & merge()" --template x

returns a non-empty string, Then changeset 42 is a merge.
The template returns the letter x if there is a result.

2
On

The hg parents command might do what you want:

hg parents -r 42 --template "{node|short}\n"

For a merge changeset you will get 2 lines of output, and for a non-merge changeset you'll get 1 line.