mq: don't update the working copy on strip if parents aren't stripped
authorDirkjan Ochtman <dirkjan@ochtman.nl>
Tue, 03 Jun 2008 12:10:14 +0200
changeset 6635 d90d83ebea9e
parent 6634 d6caebe9c293
child 6644 8c01ce1f2530
child 6648 2519976a998b
mq: don't update the working copy on strip if parents aren't stripped * * *
hgext/mq.py
tests/test-mq-strip
tests/test-mq-strip.out
tests/test-mq.out
--- a/hgext/mq.py	Tue Jun 03 09:31:36 2008 +0200
+++ b/hgext/mq.py	Tue Jun 03 12:10:14 2008 +0200
@@ -2060,14 +2060,28 @@
     return 0
 
 def strip(ui, repo, rev, **opts):
-    """strip a revision and all later revs on the same branch"""
-    rev = repo.lookup(rev)
+    """strip a revision and all its descendants from the repository
+
+    If one of the working dir's parent revisions is stripped, the working
+    directory will be updated to the parent of the stripped revision.
+    """
     backup = 'all'
     if opts['backup']:
         backup = 'strip'
     elif opts['nobackup']:
         backup = 'none'
-    update = repo.dirstate.parents()[0] != revlog.nullid
+
+    rev = repo.lookup(rev)
+    p = repo.dirstate.parents()
+    cl = repo.changelog
+    update = True
+    if p[0] == revlog.nullid:
+        update = False
+    elif p[1] == revlog.nullid and rev != cl.ancestor(p[0], rev):
+        update = False
+    elif rev not in (cl.ancestor(p[0], rev), cl.ancestor(p[1], rev)):
+        update = False
+
     repo.mq.strip(repo, rev, backup=backup, update=update)
     return 0
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-mq-strip	Tue Jun 03 12:10:14 2008 +0200
@@ -0,0 +1,51 @@
+echo "[extensions]" >> $HGRCPATH
+echo "mq=" >> $HGRCPATH
+
+teststrip() {
+    hg up -C $1
+    echo % before update $1, strip $2
+    hg parents
+    hg strip $2 2>&1 | sed 's/\(saving bundle to \).*/\1/'
+    echo % after update $1, strip $2
+    hg parents
+    hg unbundle -q .hg/strip-backup/*
+    rm .hg/strip-backup/*
+}
+
+hg init test
+cd test
+
+echo foo > bar
+hg ci -Ama
+
+echo more >> bar
+hg ci -Amb
+
+echo blah >> bar
+hg ci -Amc
+
+hg up 1
+echo blah >> bar
+hg ci -Amd
+
+echo final >> bar
+hg ci -Ame
+
+hg log
+
+teststrip 4 4
+teststrip 4 3
+teststrip 1 4
+teststrip 4 2
+teststrip 4 1
+teststrip null 4
+
+hg log
+
+hg up -C 2
+hg merge 4
+echo % before strip of merge parent
+hg parents
+hg strip 4 2>&1 | sed 's/\(saving bundle to \).*/\1/'
+echo % after strip of merge parent
+hg parents
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-mq-strip.out	Tue Jun 03 12:10:14 2008 +0200
@@ -0,0 +1,173 @@
+adding bar
+1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+created new head
+changeset:   4:443431ffac4f
+tag:         tip
+user:        test
+date:        Thu Jan 01 00:00:00 1970 +0000
+summary:     e
+
+changeset:   3:65bd5f99a4a3
+parent:      1:ef3a871183d7
+user:        test
+date:        Thu Jan 01 00:00:00 1970 +0000
+summary:     d
+
+changeset:   2:264128213d29
+user:        test
+date:        Thu Jan 01 00:00:00 1970 +0000
+summary:     c
+
+changeset:   1:ef3a871183d7
+user:        test
+date:        Thu Jan 01 00:00:00 1970 +0000
+summary:     b
+
+changeset:   0:9ab35a2d17cb
+user:        test
+date:        Thu Jan 01 00:00:00 1970 +0000
+summary:     a
+
+0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+% before update 4, strip 4
+changeset:   4:443431ffac4f
+tag:         tip
+user:        test
+date:        Thu Jan 01 00:00:00 1970 +0000
+summary:     e
+
+1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+saving bundle to 
+% after update 4, strip 4
+changeset:   3:65bd5f99a4a3
+tag:         tip
+parent:      1:ef3a871183d7
+user:        test
+date:        Thu Jan 01 00:00:00 1970 +0000
+summary:     d
+
+1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+% before update 4, strip 3
+changeset:   4:443431ffac4f
+tag:         tip
+user:        test
+date:        Thu Jan 01 00:00:00 1970 +0000
+summary:     e
+
+1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+saving bundle to 
+% after update 4, strip 3
+changeset:   1:ef3a871183d7
+user:        test
+date:        Thu Jan 01 00:00:00 1970 +0000
+summary:     b
+
+0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+% before update 1, strip 4
+changeset:   1:ef3a871183d7
+user:        test
+date:        Thu Jan 01 00:00:00 1970 +0000
+summary:     b
+
+saving bundle to 
+% after update 1, strip 4
+changeset:   1:ef3a871183d7
+user:        test
+date:        Thu Jan 01 00:00:00 1970 +0000
+summary:     b
+
+1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+% before update 4, strip 2
+changeset:   4:443431ffac4f
+tag:         tip
+user:        test
+date:        Thu Jan 01 00:00:00 1970 +0000
+summary:     e
+
+saving bundle to 
+saving bundle to 
+adding branch
+adding changesets
+adding manifests
+adding file changes
+added 2 changesets with 2 changes to 1 files
+% after update 4, strip 2
+changeset:   3:443431ffac4f
+tag:         tip
+user:        test
+date:        Thu Jan 01 00:00:00 1970 +0000
+summary:     e
+
+1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+% before update 4, strip 1
+changeset:   4:264128213d29
+tag:         tip
+parent:      1:ef3a871183d7
+user:        test
+date:        Thu Jan 01 00:00:00 1970 +0000
+summary:     c
+
+1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+saving bundle to 
+% after update 4, strip 1
+changeset:   0:9ab35a2d17cb
+tag:         tip
+user:        test
+date:        Thu Jan 01 00:00:00 1970 +0000
+summary:     a
+
+0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+% before update null, strip 4
+saving bundle to 
+% after update null, strip 4
+changeset:   4:264128213d29
+tag:         tip
+parent:      1:ef3a871183d7
+user:        test
+date:        Thu Jan 01 00:00:00 1970 +0000
+summary:     c
+
+changeset:   3:443431ffac4f
+user:        test
+date:        Thu Jan 01 00:00:00 1970 +0000
+summary:     e
+
+changeset:   2:65bd5f99a4a3
+user:        test
+date:        Thu Jan 01 00:00:00 1970 +0000
+summary:     d
+
+changeset:   1:ef3a871183d7
+user:        test
+date:        Thu Jan 01 00:00:00 1970 +0000
+summary:     b
+
+changeset:   0:9ab35a2d17cb
+user:        test
+date:        Thu Jan 01 00:00:00 1970 +0000
+summary:     a
+
+1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+(branch merge, don't forget to commit)
+% before strip of merge parent
+changeset:   2:65bd5f99a4a3
+user:        test
+date:        Thu Jan 01 00:00:00 1970 +0000
+summary:     d
+
+changeset:   4:264128213d29
+tag:         tip
+parent:      1:ef3a871183d7
+user:        test
+date:        Thu Jan 01 00:00:00 1970 +0000
+summary:     c
+
+1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+saving bundle to 
+% after strip of merge parent
+changeset:   1:ef3a871183d7
+user:        test
+date:        Thu Jan 01 00:00:00 1970 +0000
+summary:     b
+
--- a/tests/test-mq.out	Tue Jun 03 09:31:36 2008 +0200
+++ b/tests/test-mq.out	Tue Jun 03 12:10:14 2008 +0200
@@ -48,7 +48,7 @@
  qseries      print the entire series file
  qtop         print the name of the current patch
  qunapplied   print the patches not yet applied
- strip        strip a revision and all later revs on the same branch
+ strip        strip a revision and all its descendants from the repository
 
 use "hg -v help mq" to show aliases and global options
 adding a