[PATCH 5 of 8 V2] revset: add destination() predicate

Matt Harbison matt_harbison at yahoo.com
Thu Jun 7 23:58:23 CDT 2012


# HG changeset patch
# User Matt Harbison <matt_harbison at yahoo.com>
# Date 1337487212 14400
# Node ID 543798868ac78ed1c733cde9a3d37d1c50a07440
# Parent  2cf3fa0007c22037a8e3a1beaecec29d0bbc03ed
revset: add destination() predicate

This predicate is used to find source csets that were copied using graft,
transplant or rebase --keep.  A revset of destination csets can be supplied, in
which case, only the sources of those csets will be selected.  Otherwise the
parent(s) of the working directory are implicitly supplied.

    hg log -r destination()                # all src csets that were copied
    hg log -r destination(branch(default)) # all src csets copied onto default

The source of grafted csets is transitive due to the implementation of graft,
which maintains the same source value in extra when grafting a previously
grafted cset.  Given a repo with a cset S that is grafted to create G(S), which
itself is grafted to become G(G(S))

    o-S
   /
  o-o-G(S)
   \
    o-G(G(S))

    hg log -r destination( G(S) )      # { S }
    hg log -r destination( G(G(S)) )   # { S }, NOT { G(S) }

Sources of transplants and rebases, or combinations of {graft|rebase|transplant}
are not naturally transitive, due to their implementations NOT preserving the
previous source marker.  While graft preserves the source marker it left, it
does not preserve the marker when grafting a transplant or rebase.  For example

    o-S
   /
  o-o-T(S)
   \
    o-T(T(S))

    hg log -r destination( T(S) )      # { S }
    hg log -r destination( T(T(S)) )   # { T(S) }, NOT { S }

Note that the convert extension does not update the 'extra' map in its
destination csets, and therefore copies made prior to the convert will be
missing from the resulting set.

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -564,6 +564,18 @@
     # Like ``descendants(set)`` but follows only the first parents.
     return _descendants(repo, subset, x, followfirst=True)
 
+def destination(repo, subset, x):
+    """``destination([set])``
+    Changesets that were the source of graft, transplant or rebase operations
+    which yielded the given revisions, or the parent of the working directory.
+    """
+    if x:
+        s = getset(repo, subset, x)
+    else:
+        s = tuple(p.rev() for p in repo[None].parents())
+
+    return [r for r in (_getrevsource(repo, r) for r in s) if r is not None]
+
 def draft(repo, subset, x):
     """``draft()``
     Changeset in draft phase."""
@@ -1365,6 +1377,7 @@
     "desc": desc,
     "descendants": descendants,
     "_firstdescendants": _firstdescendants,
+    "destination": destination,
     "draft": draft,
     "extra": extra,
     "file": hasfile,
diff --git a/tests/test-revset.t b/tests/test-revset.t
--- a/tests/test-revset.t
+++ b/tests/test-revset.t
@@ -994,4 +994,52 @@
   date:        Thu Jan 01 00:00:00 1970 +0000
   summary:     rebase src
   
+  $ hg log -r "destination(tagged(graft1))"
+  changeset:   2:1b6f6802c4d8
+  branch:      b1
+  tag:         graft_origin
+  user:        test
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  summary:     graft src
+  
+  $ hg log -r "destination(tagged(graft2))"
+  changeset:   2:1b6f6802c4d8
+  branch:      b1
+  tag:         graft_origin
+  user:        test
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  summary:     graft src
+  
+  $ hg log -r "destination(tagged(tp1))"
+  changeset:   4:3a74c3d1dc16
+  branch:      b1
+  tag:         tp_origin
+  user:        test
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  summary:     transplant src
+  
+  $ hg log -r "destination(tagged(tp2))"
+  changeset:   10:9dc2dd8ef04a
+  branch:      b2
+  tag:         tp1
+  user:        test
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  summary:     transplant src
+  
+  $ hg log -r "destination(tagged(grafted_transplant))"
+  changeset:   18:7e3d7b573a92
+  tag:         tp2
+  user:        test
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  summary:     transplant src
+  
+  $ hg log -r "destination(tagged(transplanted_graft))"
+  changeset:   16:181b4cc9a9ed
+  tag:         graft2
+  parent:      0:cb9a9f314b8b
+  user:        test
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  summary:     graft src
+  
+
   $ cd ..


More information about the Mercurial-devel mailing list