Commits

Pierre-Yves David  committed 0599fb0

add an obsolete parent revset and related alias

  • Participants
  • Parent commits c2f7a85
  • Branches default

Comments (0)

Files changed (3)

 here=`readlink -f "$0"`
 repo_root=`dirname "$here"`
 
+# I gotta change this for cat soon
 echo "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" >&2
 echo "XXX Add the line below to the [extensions] section of you hgrc XXX" >&2
 echo "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" >&2
 echo
 echo "# history rewriting UI"
 echo "evolve=${repo_root}/hgext/evolve.py"
+echo
+echo
+echo '[alias]'
+echo "### useful alias to check future amend result"
+echo "# equivalent to the qdiff command for mq"
+echo
+echo "# diff"
+echo 'pdiff=diff --rev .^'
+echo
+echo "# status"
+echo 'pstatus=status --rev .^'
+echo
+echo "# diff with the previous amend"
+echo "odiff=diff --rev 'limit(obsparents(.),1)' --rev ."
+
+

File hgext/obsolete.py

     args = revset.getargs(x, 0, 0, 'unstable takes no arguments')
     return [r for r in subset if r in repo._extinctset]
 
+
+def _obsparents(repo, narrow, s):
+    cs = set()
+    nm = repo.changelog.nodemap
+    for r in s:
+        for p in repo._obssubrels.get(repo[r].node(), ()):
+            pr = nm.get(p, None)
+            if pr is not None:
+                cs.add(pr)
+    return cs
+
+
+def revsetobsparents(repo, subset, x):
+    """obsolete parents of a changeset"""
+    s = revset.getset(repo, range(len(repo)), x)
+    cs = _obsparents(repo, subset, s)
+    return [r for r in subset if r in cs]
+
 ### Other Extension compat
 ############################
 
     revset.symbols["unstable"] = revsetunstable
     revset.symbols["suspended"] = revsetsuspended
     revset.symbols["extinct"] = revsetextinct
+    revset.symbols["obsparents"] = revsetobsparents
 
 
     try:

File tests/test-obsolete.t

   > publish=False
   > [obsolete]
   > secret-unstable=no
+  > [alias]
+  > odiff=diff --rev 'limit(obsparents(.),1)' --rev .
   > [extensions]
   > EOF
   $ echo "obsolete=$(echo $(dirname $TESTDIR))/hgext/obsolete.py" >> $HGRCPATH
   2
   - 4538525df7e2
 
+Test that obsolete parent a properly computed
+
+  $ qlog -r 'obsparents(.)' --hidden
+  2
+  - 4538525df7e2
+  $ qlog -r .
+  3
+  - 0d3f46688ccc
+  $ hg odiff
+  diff -r 4538525df7e2 -r 0d3f46688ccc c
+  --- a/c	Thu Jan 01 00:00:00 1970 +0000
+  +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
+  @@ -1,1 +0,0 @@
+  -c
+  diff -r 4538525df7e2 -r 0d3f46688ccc obsol_c
+  --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+  +++ b/obsol_c	Thu Jan 01 00:00:00 1970 +0000
+  @@ -0,0 +1,1 @@
+  +obsol_c
+
 test obsolete changeset with no-obsolete descendant
   $ hg up 1 -q
   $ mkcommit "obsol_c'" # 4 (on 1)