diff --git a/mercurial/revset.py b/mercurial/revset.py --- a/mercurial/revset.py +++ b/mercurial/revset.py @@ -888,6 +888,34 @@ def obsolete(repo, subset, x): getargs(x, 0, 0, _("obsolete takes no arguments")) return [r for r in subset if repo[r].obsolete()] +def origin(repo, subset, x): + """``origin([set])`` + Changesets that were specified as a source for the grafts, transplants or + rebases that created the given revisions. Omitting the optional set is the + same as passing all(). If a changeset created by these operations is itself + specified as a source for one of these operations, only the source changeset + for the first operation is selected. + """ + if x is not None: + args = set(getset(repo, range(len(repo)), x)) + else: + args = set(getall(repo, range(len(repo)), x)) + + def _firstsrc(rev): + src = _getrevsource(repo, rev) + if src is None: + return None + + while True: + prev = _getrevsource(repo, src) + + if prev is None: + return src + src = prev + + o = set([_firstsrc(r) for r in args]) + return [r for r in subset if r in o] + def outgoing(repo, subset, x): """``outgoing([path])`` Changesets not found in the specified destination repository, or the @@ -1392,6 +1420,7 @@ symbols = { "min": minrev, "modifies": modifies, "obsolete": obsolete, + "origin": origin, "outgoing": outgoing, "p1": p1, "p2": p2, diff --git a/tests/test-graft.t b/tests/test-graft.t --- a/tests/test-graft.t +++ b/tests/test-graft.t @@ -358,3 +358,50 @@ Resolve conflicted graft with rename diff --git a/a b/b rename from a rename to b + +Test simple origin(), with and without args + $ hg log -r 'origin()' + changeset: 1:5d205f8b35b6 + user: bar + date: Thu Jan 01 00:00:00 1970 +0000 + summary: 1 + + changeset: 2:5c095ad7e90f + user: test + date: Thu Jan 01 00:00:00 1970 +0000 + summary: 2 + + changeset: 3:4c60f11aa304 + user: baz + date: Thu Jan 01 00:00:00 1970 +0000 + summary: 3 + + changeset: 4:9c233e8e184d + user: test + date: Thu Jan 01 00:00:00 1970 +0000 + summary: 4 + + changeset: 5:97f8bfe72746 + branch: stable + parent: 3:4c60f11aa304 + user: test + date: Thu Jan 01 00:00:00 1970 +0000 + summary: 5 + + $ hg log -r 'origin(7)' + changeset: 2:5c095ad7e90f + user: test + date: Thu Jan 01 00:00:00 1970 +0000 + summary: 2 + +Now transplant a graft to test following through copies + $ hg up -q 0 + $ hg branch -q dev + $ hg ci -qm "dev branch" + $ hg --config extensions.transplant= transplant -q 7 + $ hg log -r 'origin(.)' + changeset: 2:5c095ad7e90f + user: test + date: Thu Jan 01 00:00:00 1970 +0000 + summary: 2 +