mrtnlrsn
mrtnlrsn

Reputation: 1255

Mercurial: How to find last time my branch was merged into default

Is there some Mercurial revision set magic that can be used to find the last changeset on the default branch that merged a specific branch (let's call it mybranch)?

Or equally good find the last revision of mybranch that was merged into default`?

In addition a way to list changesets grafted from mybranch to default would be nice.

Upvotes: 4

Views: 408

Answers (1)

Lazy Badger
Lazy Badger

Reputation: 97270

hg help revsets as source, starting from the last question

List of grafted changesets

"destination([set])" 
Changesets that were created by a graft, transplant or rebase operation, with the given
revisions specified as the source.
Omitting the optional set is the same as passing all().

For "... changesets grafted from mybranch to default" revset will be

destination(branch("mybranch")) & branch("default")

Even better: you can store it as revsetalias (TBT!)

[revsetalias]
grafted(from, to) = destination(branch(from)) & branch(to)

and use it for any pair of branches (expandning to custom amount of sources will be your future task).

Last merged revision

Step-by-step

  • "...last changeset on the default branch that merged a specific branch" is a) mergeset b) latest if merged more once c) one of it's parents belongs to branch-in-question
  • you have to test revset and if I mixed up parents, exchange p1 & p2 in revset (can't debug now)
  • Revset have to be prepared for the most common task "Get the latest mergepoint of branch FROM to branch TO"

merge() & branch("to") - all mergepoints in TO

p2(merge() & branch("to")) & branch("from") - parents of the above merges only FROM

child(p2(merge() & branch("to")) & branch("from")) & branch("to") - childs of the above parents only in TO (because they can have childs in other branches too)

last(child(p2(merge() & branch("to")) & branch("from")) & branch("to")) - latest mergepoint if merges happened more than once.

Set of revsetaliases (for better readability) as result

[revsetalias]
ms(to) = merge() & branch(to)

ms2b(to,from) = (child(p2(ms(to))) & branch(from)) & branch(to)

fp_ms(to,from) = p2(ms(to)) & branch(from)

and your revset for:

  • latest mergepoint last(ms2b("default","mybranch"))
  • latest foreign parent last(fp_ms("default","mybranch"))

Addition & Demonstration

I fixed my ms2b(), as shown in THG's repobrowser screenshot below. Merges from stable to default "as is"

children(p2(merge() & branch(default)) & branch(stable)) & branch(default)

With parameters and previously prepared revsetaliases

ms2b(to,from) = children(p2(ms(to)) & branch(from)) & branch(to)

RepoBrowser w/filter

Upvotes: 4

Related Questions