Patchwork [9,of,9,PoC] mq2: obsolete changesets when their patch is qrm'ed

login
register
mail settings
Submitter Mads Kiilerich
Date Aug. 29, 2014, 8:59 a.m.
Message ID <a947977466a68dbcf886.1409302766@localhost.localdomain>
Download mbox | patch
Permalink /patch/5612/
State Changes Requested
Headers show

Comments

Mads Kiilerich - Aug. 29, 2014, 8:59 a.m.
# HG changeset patch
# User Mads Kiilerich <madski@unity3d.com>
# Date 1409301992 -7200
#      Fri Aug 29 10:46:32 2014 +0200
# Node ID a947977466a68dbcf886a37ec98a274d581ef0f9
# Parent  5f5f3c1fe8196842ce4198ad1f6c11a83ce9f80e
mq2: obsolete changesets when their patch is qrm'ed

Patch

diff --git a/hgext/mq.py b/hgext/mq.py
--- a/hgext/mq.py
+++ b/hgext/mq.py
@@ -1035,15 +1035,33 @@  class queue(object):
                                'patch name'))
 
         realpatches = []
-        for patch in patches:
-            patch = self.lookup(patch, strict=True)
-            info = self.isapplied(patch)
-            if info:
-                raise util.Abort(_("cannot delete applied patch %s") % patch)
-            if patch not in self.series:
-                raise util.Abort(_("patch %s not in series file") % patch)
-            if patch not in realpatches:
-                realpatches.append(patch)
+        tr = repo.transaction('qrm-obsolete')
+        try:
+            for patch in patches:
+                patch = self.lookup(patch, strict=True)
+                info = self.isapplied(patch)
+                if info:
+                    raise util.Abort(_("cannot delete applied patch %s") % patch)
+                if patch not in self.series:
+                    raise util.Abort(_("patch %s not in series file") % patch)
+                if patch not in realpatches:
+                    realpatches.append(patch)
+    
+                pf = os.path.join(self.path, patch)
+                try:
+                    ph = patchheader(self.join(patch), self.plainmode)
+                except IOError:
+                    self.ui.warn(_("unable to read %s\n") % patch)
+                    err = 1
+                    continue
+    
+                if ph.nodeid and ph.nodeid in repo:
+                    orgctx = repo[ph.nodeid]
+                    self.ui.debug('obsoleting removed %s\n' % orgctx)
+                    repo.obsstore.create(tr, orgctx.node(), [])
+            tr.close()
+        finally:
+            tr.release()
 
         numrevs = 0
         if opts.get('rev'):
diff --git a/tests/test-mq-header-date.t b/tests/test-mq-header-date.t
--- a/tests/test-mq-header-date.t
+++ b/tests/test-mq-header-date.t
@@ -710,7 +710,6 @@ 
   Three
   
   6: Three - test - 6.00
-  5: [mq]: 2.patch - test - 5.00
   2: [mq]: 1.patch - test - 4.00
   ==== qref
   adding 3
@@ -727,7 +726,6 @@ 
   @@ -0,0 +1,1 @@
   +3
   7: Three - test - 6.00
-  5: [mq]: 2.patch - test - 5.00
   2: [mq]: 1.patch - test - 4.00
   ==== qref -m
   # HG changeset patch
@@ -743,7 +741,6 @@ 
   @@ -0,0 +1,1 @@
   +3
   8: Drei - test - 6.00
-  5: [mq]: 2.patch - test - 5.00
   2: [mq]: 1.patch - test - 4.00
   ==== qref -d
   # HG changeset patch
@@ -759,7 +756,6 @@ 
   @@ -0,0 +1,1 @@
   +3
   9: Drei - test - 7.00
-  5: [mq]: 2.patch - test - 5.00
   2: [mq]: 1.patch - test - 4.00
   ==== qref -d -m
   # HG changeset patch
@@ -775,7 +771,6 @@ 
   @@ -0,0 +1,1 @@
   +3
   10: Three (again) - test - 8.00
-  5: [mq]: 2.patch - test - 5.00
   2: [mq]: 1.patch - test - 4.00
   ==== qnew -m
   adding 4
@@ -793,7 +788,6 @@ 
   +4
   12: Four - test
   10: Three (again) - test
-  5: [mq]: 2.patch - test
   2: [mq]: 1.patch - test
   ==== qref -d
   # HG changeset patch
@@ -810,7 +804,6 @@ 
   +4
   13: Four - test
   10: Three (again) - test
-  5: [mq]: 2.patch - test
   2: [mq]: 1.patch - test
   popping 4.patch
   now at: 3.patch
@@ -823,9 +816,7 @@ 
   # Date 10 0
   15: imported patch 5.patch - test - 10.00
   14: [mq]: 5.patch - test - 1.00
-  13: Four - test - 9.00
   10: Three (again) - test - 8.00
-  5: [mq]: 2.patch - test - 5.00
   2: [mq]: 1.patch - test - 4.00
   ==== hg qref
   adding 5
@@ -843,9 +834,7 @@ 
   +5
   16: [mq]: 5.patch - test - 10.00
   14: [mq]: 5.patch - test - 1.00
-  13: Four - test - 9.00
   10: Three (again) - test - 8.00
-  5: [mq]: 2.patch - test - 5.00
   2: [mq]: 1.patch - test - 4.00
   ==== hg qref -d
   Date: 11 0
@@ -862,9 +851,7 @@ 
   +5
   17: [mq]: 5.patch - test - 11.00
   14: [mq]: 5.patch - test - 1.00
-  13: Four - test - 9.00
   10: Three (again) - test - 8.00
-  5: [mq]: 2.patch - test - 5.00
   2: [mq]: 1.patch - test - 4.00
   ==== qnew with plain header
   popping 6.patch
@@ -876,9 +863,7 @@ 
   18: [mq]: 6.patch - test
   17: [mq]: 5.patch - test
   14: [mq]: 5.patch - test
-  13: Four - test
   10: Three (again) - test
-  5: [mq]: 2.patch - test
   2: [mq]: 1.patch - test
   ==== hg qref
   adding 6
@@ -893,9 +878,7 @@ 
   18: [mq]: 6.patch - test - 12.00
   17: [mq]: 5.patch - test - 11.00
   14: [mq]: 5.patch - test - 1.00
-  13: Four - test - 9.00
   10: Three (again) - test - 8.00
-  5: [mq]: 2.patch - test - 5.00
   2: [mq]: 1.patch - test - 4.00
   ==== hg qref -d
   Date: 13 0
@@ -909,9 +892,7 @@ 
   18: [mq]: 6.patch - test - 12.00
   17: [mq]: 5.patch - test - 11.00
   14: [mq]: 5.patch - test - 1.00
-  13: Four - test - 9.00
   10: Three (again) - test - 8.00
-  5: [mq]: 2.patch - test - 5.00
   2: [mq]: 1.patch - test - 4.00
   popping 6.patch
   now at: 5.patch
@@ -933,9 +914,7 @@ 
   18: [mq]: 6.patch - test
   17: [mq]: 5.patch - test
   14: [mq]: 5.patch - test
-  13: Four - test
   10: Three (again) - test
-  5: [mq]: 2.patch - test
   2: [mq]: 1.patch - test
   ==== qref -d
   # HG changeset patch
@@ -954,9 +933,7 @@ 
   18: [mq]: 6.patch - test
   17: [mq]: 5.patch - test
   14: [mq]: 5.patch - test
-  13: Four - test
   10: Three (again) - test
-  5: [mq]: 2.patch - test
   2: [mq]: 1.patch - test
   popping 6.patch
   now at: 5.patch
@@ -973,14 +950,11 @@ 
   @@ -0,0 +1,1 @@
   +7
   26: [mq]: 7.patch - test
-  24: [mq]: 6.patch - jane
   21: [mq]: 6.patch - test
   18: [mq]: 6.patch - test
   17: [mq]: 5.patch - test
   14: [mq]: 5.patch - test
-  13: Four - test
   10: Three (again) - test
-  5: [mq]: 2.patch - test
   2: [mq]: 1.patch - test
   ==== qref -u
   # HG changeset patch
@@ -995,14 +969,11 @@ 
   @@ -0,0 +1,1 @@
   +7
   27: [mq]: 7.patch - john - 13.00
-  24: [mq]: 6.patch - jane - 12.00
   21: [mq]: 6.patch - test - 13.00
   18: [mq]: 6.patch - test - 12.00
   17: [mq]: 5.patch - test - 11.00
   14: [mq]: 5.patch - test - 1.00
-  13: Four - test - 9.00
   10: Three (again) - test - 8.00
-  5: [mq]: 2.patch - test - 5.00
   2: [mq]: 1.patch - test - 4.00
   ==== qnew
   adding 8
@@ -1018,14 +989,11 @@ 
   +8
   29: [mq]: 8.patch - test
   27: [mq]: 7.patch - john
-  24: [mq]: 6.patch - jane
   21: [mq]: 6.patch - test
   18: [mq]: 6.patch - test
   17: [mq]: 5.patch - test
   14: [mq]: 5.patch - test
-  13: Four - test
   10: Three (again) - test
-  5: [mq]: 2.patch - test
   2: [mq]: 1.patch - test
   ==== qref -u -d
   # HG changeset patch
@@ -1041,14 +1009,11 @@ 
   +8
   30: [mq]: 8.patch - john
   27: [mq]: 7.patch - john
-  24: [mq]: 6.patch - jane
   21: [mq]: 6.patch - test
   18: [mq]: 6.patch - test
   17: [mq]: 5.patch - test
   14: [mq]: 5.patch - test
-  13: Four - test
   10: Three (again) - test
-  5: [mq]: 2.patch - test
   2: [mq]: 1.patch - test
   popping 8.patch
   now at: 7.patch
@@ -1067,16 +1032,12 @@ 
   @@ -0,0 +1,1 @@
   +9
   32: Nine - test
-  30: [mq]: 8.patch - john
   27: [mq]: 7.patch - john
-  24: [mq]: 6.patch - jane
   21: [mq]: 6.patch - test
   18: [mq]: 6.patch - test
   17: [mq]: 5.patch - test
   14: [mq]: 5.patch - test
-  13: Four - test
   10: Three (again) - test
-  5: [mq]: 2.patch - test
   2: [mq]: 1.patch - test
   ==== qref -u -d
   # HG changeset patch
@@ -1093,16 +1054,12 @@ 
   @@ -0,0 +1,1 @@
   +9
   33: Nine - john
-  30: [mq]: 8.patch - john
   27: [mq]: 7.patch - john
-  24: [mq]: 6.patch - jane
   21: [mq]: 6.patch - test
   18: [mq]: 6.patch - test
   17: [mq]: 5.patch - test
   14: [mq]: 5.patch - test
-  13: Four - test
   10: Three (again) - test
-  5: [mq]: 2.patch - test
   2: [mq]: 1.patch - test
   popping 9.patch
   now at: 7.patch
@@ -1118,16 +1075,11 @@ 
   applying 5.patch
   applying 7.patch
   now at: 7.patch
-  33: Nine - john - 15.00
-  30: [mq]: 8.patch - john - 14.00
   27: [mq]: 7.patch - john - 13.00
-  24: [mq]: 6.patch - jane - 12.00
   21: [mq]: 6.patch - test - 13.00
   18: [mq]: 6.patch - test - 12.00
   17: [mq]: 5.patch - test - 11.00
   14: [mq]: 5.patch - test - 1.00
-  13: Four - test - 9.00
   10: Three (again) - test - 8.00
-  5: [mq]: 2.patch - test - 5.00
   2: [mq]: 1.patch - test - 4.00
   $ rm -r sandbox
diff --git a/tests/test-mq-qdelete.t b/tests/test-mq-qdelete.t
--- a/tests/test-mq-qdelete.t
+++ b/tests/test-mq-qdelete.t
@@ -58,10 +58,6 @@  Delete the same patch twice in one comma
   $ hg qapplied
 
   $ hg log -G --template '{rev} {desc}\n'
-  o  3 [mq]: pc
-  |
-  o  2 [mq]: pb
-  |
   @  1 [mq]: pa
   |
   o  0 base
@@ -89,10 +85,6 @@  Delete the same patch twice in one comma
   |
   o  4 [mq]: pd
   |
-  | o  3 [mq]: pc
-  | |
-  | o  2 [mq]: pb
-  |/
   o  1 [mq]: pa
   |
   o  0 base
@@ -195,7 +187,6 @@  resilience to inconsistency: qfinish -a 
   3.diff
   $ hg qapplied
   $ hg qpush
-  (working directory not at a head)
   applying 3.diff
   now at: 3.diff
   $ echo next >>  base
diff --git a/tests/test-mq-qdiff.t b/tests/test-mq-qdiff.t
--- a/tests/test-mq-qdiff.t
+++ b/tests/test-mq-qdiff.t
@@ -56,7 +56,6 @@  qdiff filename:
   $ printf '1\n2\n3\n4\nhello world\ngoodbye world\n7\n8\n9\n' > lines
   $ hg ci -Amlines -d '2 0'
   adding lines
-  created new head
 
   $ hg qnew -mmqbase2 mqbase2
   $ printf '\n\n1\n2\n3\n4\nhello  world\n     goodbye world\n7\n8\n9\n' > lines
diff --git a/tests/test-mq-qimport.t b/tests/test-mq-qimport.t
--- a/tests/test-mq-qimport.t
+++ b/tests/test-mq-qimport.t
@@ -128,7 +128,6 @@  import patch that already exists
   abort: patch "url.diff" already exists
   [255]
   $ hg qpush
-  (working directory not at a head)
   applying url.diff
   now at: url.diff
   $ cat foo
@@ -277,22 +276,21 @@  set up hgweb
   $ hg qimport http://localhost:$HGPORT/raw-rev/0///
   adding 0 to series file
 
-check qimport phase - temporarily broken until we make non-stripped old
-changesets "go away":
+check qimport phase:
 
-# $ hg -q qpush
-# now at: 0
-# $ hg phase qparent
-# 1: draft
-# $ hg qimport -r qparent
-# $ hg phase qbase
-# 1: draft
-# $ hg qfinish qbase
-# $ echo '[mq]' >> $HGRCPATH
-# $ echo 'secret=true' >> $HGRCPATH
-# $ hg qimport -r qparent
-# $ hg phase qbase
-# 1: secret
+  $ hg -q qpush
+  now at: 0
+  $ hg phase qparent
+  4: draft
+  $ hg qimport -r qparent
+  $ hg phase qbase
+  4: draft
+  $ hg qfinish qbase
+  $ echo '[mq]' >> $HGRCPATH
+  $ echo 'secret=true' >> $HGRCPATH
+  $ hg qimport -r qparent
+  $ hg phase qbase
+  4: secret
 
   $ cd ..
 
diff --git a/tests/test-mq-subrepo.t b/tests/test-mq-subrepo.t
--- a/tests/test-mq-subrepo.t
+++ b/tests/test-mq-subrepo.t
@@ -451,9 +451,10 @@  as same result (in node hash) as one inc
   $ echo 'sub = sub' > .hgsub
   $ hg add .hgsub
   $ rm -f .hgsubstate
-  $ hg qnew -u test -d '0 0' import-at-qnew
+Cheat: use a different date to avoid hitting hash that has been obsoleted
+  $ hg qnew -u test -d '1 0' import-at-qnew
   $ hg parents --template '{node}\n'
-  f69e96d86e75a6d4fd88285dc9697acb23951041
+  de66d026d0648e525de1c12150c068f339f7e18a
   $ hg parents --template '{files}\n'
   .hgsub .hgsubstate
 
@@ -479,7 +480,7 @@  check whether qrefresh imports updated .
   $ cat .hgsubstate
   88ac1bef5ed43b689d1d200b59886b675dec474b sub
   $ hg diff -c tip
-  diff -r f69e96d86e75 -r 3c89d6089ecb .hgsubstate
+  diff -r de66d026d064 -r d058aa413692 .hgsubstate
   --- a/.hgsubstate
   +++ b/.hgsubstate
   @@ -1,1 +1,1 @@
@@ -489,10 +490,10 @@  check whether qrefresh imports updated .
   # HG changeset patch
   # Date 0 0
   # User test
-  # Node ID 3c89d6089ecbe4de9d1aff0cd5c565ce5ac36341
-  # Parent f69e96d86e75a6d4fd88285dc9697acb23951041
+  # Node ID d058aa413692a45fb3b007f3de4d1a96fbb4a592
+  # Parent de66d026d0648e525de1c12150c068f339f7e18a
   
-  diff -r f69e96d86e75 .hgsubstate
+  diff -r de66d026d064 .hgsubstate
   --- a/.hgsubstate
   +++ b/.hgsubstate
   @@ -1,1 +1,1 @@
@@ -505,7 +506,7 @@  check whether qrefresh imports updated .
   $ cat .hgsubstate
   88ac1bef5ed43b689d1d200b59886b675dec474b sub
   $ hg diff -c tip
-  diff -r f69e96d86e75 -r 3c89d6089ecb .hgsubstate
+  diff -r de66d026d064 -r d058aa413692 .hgsubstate
   --- a/.hgsubstate
   +++ b/.hgsubstate
   @@ -1,1 +1,1 @@
@@ -515,10 +516,10 @@  check whether qrefresh imports updated .
   # HG changeset patch
   # Date 0 0
   # User test
-  # Node ID 3c89d6089ecbe4de9d1aff0cd5c565ce5ac36341
-  # Parent f69e96d86e75a6d4fd88285dc9697acb23951041
+  # Node ID d058aa413692a45fb3b007f3de4d1a96fbb4a592
+  # Parent de66d026d0648e525de1c12150c068f339f7e18a
   
-  diff -r f69e96d86e75 .hgsubstate
+  diff -r de66d026d064 .hgsubstate
   --- a/.hgsubstate
   +++ b/.hgsubstate
   @@ -1,1 +1,1 @@
@@ -544,8 +545,8 @@  check whether qrefresh imports updated .
   1 files updated, 0 files merged, 0 files removed, 0 files unresolved
   $ hg commit -Am '#2 in parent (but will be rolled back soon)'
   $ hg rollback
-  repository tip rolled back to revision 4 (undo commit)
-  working directory now based on revision 4
+  repository tip rolled back to revision 5 (undo commit)
+  working directory now based on revision 5
   $ hg status
   M .hgsubstate
   $ hg qnew -u test -d '0 0' checkstate-at-qnew
diff --git a/tests/test-mq.t b/tests/test-mq.t
--- a/tests/test-mq.t
+++ b/tests/test-mq.t
@@ -1172,6 +1172,7 @@  test qdel/qrm
   $ hg qdel baz
   $ echo p >> .hg/patches/series
   $ hg qrm p
+  unable to read p
   $ hg qser
   bar
 
diff --git a/tests/test-mq2.t b/tests/test-mq2.t
--- a/tests/test-mq2.t
+++ b/tests/test-mq2.t
@@ -160,10 +160,6 @@ 
   $ hg qrm a2
 (should also have stripped b that couldn't be stripped before)
   $ hg log -G --template "{rev} {node|short} {phase} {desc|firstline}\n"
-  o  6 cd192c2f0104 draft a2
-  |
-  o  5 c27d00b1f47f draft b
-  |
   @  4 dfa6dafa9c6c draft yada
   |
   o  0 cb9a9f314b8b draft a