Patchwork [5,of,5] histedit: proper phase conservation (issue3724)

login
register
mail settings
Submitter Pierre-Yves David
Date Jan. 16, 2013, 6:28 p.m.
Message ID <3d998b743fc0c9a7cbc0.1358360899@crater2.logilab.fr>
Download mbox | patch
Permalink /patch/659/
State Accepted
Commit 35513c59f376a39a60f1d8f602bea23725d6a61d
Headers show

Comments

Pierre-Yves David - Jan. 16, 2013, 6:28 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@logilab.fr>
# Date 1358360463 -3600
# Node ID 3d998b743fc0c9a7cbc00282cd9ea92e1bc78cf3
# Parent  f4fa682477205f666708bdc46a4bf75753213322
histedit: proper phase conservation (issue3724)

Before this changeset, histedit created all new changesets according
phases.new-commit option without any regards for the phases of the original
changesets.

This changeset fix that using the phase of rewritten changeset to decide the
phase of the resulting changeset. In case of reordering or folding, we keep
secret item secret as it seems the safer path.

temporary commit creation are not affected. They are head only and stripped at
the end of the histedit.

As for the resolution of issue3681 (obsolescence cycle prevention), we do not
handle changesets created by edit command.

Patch

diff --git a/hgext/histedit.py b/hgext/histedit.py
--- a/hgext/histedit.py
+++ b/hgext/histedit.py
@@ -184,15 +184,21 @@  def commitfuncfor(repo, src):
     - Add a 'histedit_source' entry in extra.
 
     Note that fold have its own separated logic because its handling is a bit
     different and non factorisable.
     """
+    phasemin = src.phase()
     def commitfunc(**kwargs):
-        extra = kwargs.get('extra', {}).copy()
-        extra['histedit_source'] = src.hex()
-        kwargs['extra'] = extra
-        return repo.commit(**kwargs)
+        phasebackup = repo.ui.backupconfig('phases', 'new-commit')
+        try:
+            repo.ui.setconfig('phases', 'new-commit', phasemin)
+            extra = kwargs.get('extra', {}).copy()
+            extra['histedit_source'] = src.hex()
+            kwargs['extra'] = extra
+            return repo.commit(**kwargs)
+        finally:
+            repo.ui.restoreconfig(phasebackup)
     return commitfunc
 
 
 
 def applychanges(ui, repo, ctx, opts):
@@ -355,11 +361,17 @@  def finishfold(ui, repo, ctx, oldctx, ne
     # histedit_source
     # note: ctx is likely a temporary commit but that the best we can do here
     #       This is sufficient to solve issue3681 anyway
     extra['histedit_source'] = '%s,%s' % (ctx.hex(), oldctx.hex())
     commitopts['extra'] = extra
-    n = collapse(repo, ctx, repo[newnode], commitopts)
+    phasebackup = repo.ui.backupconfig('phases', 'new-commit')
+    try:
+        phasemin = max(ctx.phase(), oldctx.phase())
+        repo.ui.setconfig('phases', 'new-commit', phasemin)
+        n = collapse(repo, ctx, repo[newnode], commitopts)
+    finally:
+        repo.ui.restoreconfig(phasebackup)
     if n is None:
         return ctx, []
     hg.update(repo, n)
     replacements = [(oldctx.node(), (newnode,)),
                      (ctx.node(), (n,)),
diff --git a/tests/test-histedit-obsolete.t b/tests/test-histedit-obsolete.t
--- a/tests/test-histedit-obsolete.t
+++ b/tests/test-histedit-obsolete.t
@@ -151,14 +151,16 @@  Test that rewriting leaving instability 
 
 stabilise
 
   $ hg rebase  -r 'unstable()' -d .
 
-Check that histedit respect phases
-=========================================
 
-(not directly related to the test file but doesn't deserve it's own test case)
+Test phases support
+===========================================
+
+Check that histedit respect immutability
+-------------------------------------------
 
   $ cat >> $HGRCPATH << EOF
   > [ui]
   > logtemplate= {rev}:{node|short} ({phase}) {desc|firstline}\n
   > EOF
@@ -175,5 +177,228 @@  Check that histedit respect phases
   $ hg histedit -r '.~2'
   abort: cannot edit immutable changeset: cb9a9f314b8b
   [255]
 
 
+Prepare further testing
+-------------------------------------------
+
+  $ for x in g h i j k ; do
+  >     echo $x > $x
+  >     hg add $x
+  >     hg ci -m $x
+  > done
+  $ hg phase --force --secret .~2
+  $ hg log -G
+  @  16:ee118ab9fa44 (secret) k
+  |
+  o  15:3a6c53ee7f3d (secret) j
+  |
+  o  14:b605fb7503f2 (secret) i
+  |
+  o  13:7395e1ff83bd (draft) h
+  |
+  o  12:6b70183d2492 (draft) g
+  |
+  o  11:b449568bf7fc (draft) f
+  |
+  o  10:40db8afa467b (public) c
+  |
+  o  0:cb9a9f314b8b (public) a
+  
+  $ cd ..
+
+simple phase conservation
+-------------------------------------------
+
+Resulting changeset should conserve the phase of the original one whatever the
+phases.new-commit option is.
+
+New-commit as draft (default)
+
+  $ cp -r base simple-draft
+  $ cd simple-draft
+  $ cat > commands.txt <<EOF
+  > edit b449568bf7fc 11 f
+  > pick 6b70183d2492 12 g
+  > pick 7395e1ff83bd 13 h
+  > pick b605fb7503f2 14 i
+  > pick 3a6c53ee7f3d 15 j
+  > pick ee118ab9fa44 16 k
+  > EOF
+  $ hg histedit -r 'b449568bf7fc' --commands commands.txt
+  0 files updated, 0 files merged, 6 files removed, 0 files unresolved
+  adding f
+  abort: Make changes as needed, you may commit or record as needed now.
+  When you are finished, run hg histedit --continue to resume.
+  [255]
+  $ echo f >> f
+  $ hg histedit --continue
+  0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  $ hg log -G
+  @  22:12e89af74238 (secret) k
+  |
+  o  21:636a8687b22e (secret) j
+  |
+  o  20:ccaf0a38653f (secret) i
+  |
+  o  19:11a89d1c2613 (draft) h
+  |
+  o  18:c1dec7ca82ea (draft) g
+  |
+  o  17:087281e68428 (draft) f
+  |
+  o  10:40db8afa467b (public) c
+  |
+  o  0:cb9a9f314b8b (public) a
+  
+  $ cd ..
+
+
+New-commit as draft (default)
+
+  $ cp -r base simple-secret
+  $ cd simple-secret
+  $ cat >> .hg/hgrc << EOF
+  > [phases]
+  > new-commit=secret
+  > EOF
+  $ cat > commands.txt <<EOF
+  > edit b449568bf7fc 11 f
+  > pick 6b70183d2492 12 g
+  > pick 7395e1ff83bd 13 h
+  > pick b605fb7503f2 14 i
+  > pick 3a6c53ee7f3d 15 j
+  > pick ee118ab9fa44 16 k
+  > EOF
+  $ hg histedit -r 'b449568bf7fc' --commands commands.txt
+  0 files updated, 0 files merged, 6 files removed, 0 files unresolved
+  adding f
+  abort: Make changes as needed, you may commit or record as needed now.
+  When you are finished, run hg histedit --continue to resume.
+  [255]
+  $ echo f >> f
+  $ hg histedit --continue
+  0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  $ hg log -G
+  @  22:12e89af74238 (secret) k
+  |
+  o  21:636a8687b22e (secret) j
+  |
+  o  20:ccaf0a38653f (secret) i
+  |
+  o  19:11a89d1c2613 (draft) h
+  |
+  o  18:c1dec7ca82ea (draft) g
+  |
+  o  17:087281e68428 (draft) f
+  |
+  o  10:40db8afa467b (public) c
+  |
+  o  0:cb9a9f314b8b (public) a
+  
+  $ cd ..
+
+
+Changeset reordering
+-------------------------------------------
+
+If a secret changeset is put before a draft one, all descendant should be secret.
+It seems more important to present the secret phase.
+
+  $ cp -r base reorder
+  $ cd reorder
+  $ cat > commands.txt <<EOF
+  > pick b449568bf7fc 11 f
+  > pick 3a6c53ee7f3d 15 j
+  > pick 6b70183d2492 12 g
+  > pick b605fb7503f2 14 i
+  > pick 7395e1ff83bd 13 h
+  > pick ee118ab9fa44 16 k
+  > EOF
+  $ hg histedit -r 'b449568bf7fc' --commands commands.txt
+  0 files updated, 0 files merged, 5 files removed, 0 files unresolved
+  0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  $ hg log -G
+  @  21:558246857888 (secret) k
+  |
+  o  20:28bd44768535 (secret) h
+  |
+  o  19:d5395202aeb9 (secret) i
+  |
+  o  18:21edda8e341b (secret) g
+  |
+  o  17:5ab64f3a4832 (secret) j
+  |
+  o  11:b449568bf7fc (draft) f
+  |
+  o  10:40db8afa467b (public) c
+  |
+  o  0:cb9a9f314b8b (public) a
+  
+  $ cd ..
+
+Changeset folding
+-------------------------------------------
+
+Folding a secret changeset with a draft one turn the result secret (again,
+better safe than sorry). Folding between same phase changeset still works
+
+Note that there is a few reordering in this series for more extensive test
+
+  $ cp -r base folding
+  $ cd folding
+  $ cat >> .hg/hgrc << EOF
+  > [phases]
+  > new-commit=secret
+  > EOF
+  $ cat > commands.txt <<EOF
+  > pick 7395e1ff83bd 13 h
+  > fold b449568bf7fc 11 f
+  > pick 6b70183d2492 12 g
+  > fold 3a6c53ee7f3d 15 j
+  > pick b605fb7503f2 14 i
+  > fold ee118ab9fa44 16 k
+  > EOF
+  $ hg histedit -r 'b449568bf7fc' --commands commands.txt
+  0 files updated, 0 files merged, 6 files removed, 0 files unresolved
+  0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  0 files updated, 0 files merged, 2 files removed, 0 files unresolved
+  2 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  0 files updated, 0 files merged, 2 files removed, 0 files unresolved
+  2 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  0 files updated, 0 files merged, 2 files removed, 0 files unresolved
+  2 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  saved backup bundle to $TESTTMP/folding/.hg/strip-backup/58019c66f35f-backup.hg (glob)
+  saved backup bundle to $TESTTMP/folding/.hg/strip-backup/83d1858e070b-backup.hg (glob)
+  saved backup bundle to $TESTTMP/folding/.hg/strip-backup/859969f5ed7e-backup.hg (glob)
+  $ hg log -G
+  @  19:f9daec13fb98 (secret) i
+  |
+  o  18:49807617f46a (secret) g
+  |
+  o  17:050280826e04 (draft) h
+  |
+  o  10:40db8afa467b (public) c
+  |
+  o  0:cb9a9f314b8b (public) a
+  
+  $ cd ..