[PATCH] mq: do not strip revision if applied mq is descendant (issue1881)

Vishakh H vsh426 at gmail.com
Mon Jul 5 05:11:03 CDT 2010


# HG changeset patch
# User Vishakh H <vsh426 at gmail.com>
# Date 1278268639 -19800
# Branch stable
# Node ID fdd2d7955d697155a0449952cff5079631e2c968
# Parent  b2468fb58b2bbbe5711119437449f253fda68318
mq: do not strip revision if applied mq is descendant (issue1881)

check if there are applied patches and whether strip rev is ancestor of
qparent or is one of applied patches. two different messages are for the
benefit of the user.

diff --git a/hgext/mq.py b/hgext/mq.py
--- a/hgext/mq.py
+++ b/hgext/mq.py
@@ -2404,8 +2404,15 @@
         backup = 'none'
 
     rev = repo.lookup(rev)
+    cl = repo.changelog
+    q = repo.mq
+    if q.applied:
+        if rev == cl.ancestor(repo.lookup('qparent'), rev):
+            raise util.Abort(_("cannot strip revision when applied "
+                "patches are descendants"))
+        if rev == cl.ancestor(repo.lookup('qtip'), rev):
+            raise util.Abort(_("cannot strip applied patch"))
     p = repo.dirstate.parents()
-    cl = repo.changelog
     update = True
     if p[0] == nullid:
         update = False
diff --git a/tests/test-strip-applied b/tests/test-strip-applied
new file mode 100755
--- /dev/null
+++ b/tests/test-strip-applied
@@ -0,0 +1,30 @@
+#!/bin/sh
+#do not strip revision if it or its descendants are applied mq patches
+
+. $TESTDIR/helpers.sh
+
+hg init stripmq
+cd stripmq
+echo '[extensions]' >> $HGRCPATH
+echo 'mq =' >> $HGRCPATH
+echo 'graphlog =' >> $HGRCPATH
+touch foo
+hg ci -Aqm'add foo'
+echo a > foo
+hg ci -m"ancestor of applied queue"
+echo b > foo
+hg ci -m"unrelated to queue"
+hg up -q -r -2
+echo c >> foo
+hg qnew patch-to-strip
+
+echo % repo graph
+hg glog --template '{rev}:{desc}\n'
+echo % applied patches
+hg qapplied
+echo % try to strip applied patch rev 3
+hg strip tip
+echo % try to strip its ancestor rev 1
+hg strip 1
+echo % strip unrelated safe revision 2
+hg strip 2 | hidebackup
diff --git a/tests/test-strip-applied.out b/tests/test-strip-applied.out
new file mode 100644
--- /dev/null
+++ b/tests/test-strip-applied.out
@@ -0,0 +1,17 @@
+% repo graph
+@  3:[mq]: patch-to-strip
+|
+| o  2:unrelated to queue
+|/
+o  1:ancestor of applied queue
+|
+o  0:add foo
+
+% applied patches
+patch-to-strip
+% try to strip applied patch rev 3
+abort: cannot strip applied patch
+% try to strip its ancestor rev 1
+abort: cannot strip revision when applied patches are descendants
+% strip unrelated safe revision 2
+saved backup bundle to 


More information about the Mercurial-devel mailing list