# HG changeset patch # User Pierre-Yves David # Date 2013-01-16 18:21:03 # Node ID 35513c59f376a39a60f1d8f602bea23725d6a61d # Parent c6e3fa134da595c81d65bb08e82a924cc8cd4bc4 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. diff --git a/hgext/histedit.py b/hgext/histedit.py --- a/hgext/histedit.py +++ b/hgext/histedit.py @@ -186,11 +186,17 @@ def commitfuncfor(repo, src): Note that fold have its own separated logic because its handling is a bit different and not easily factored out of the fold method. """ + 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 @@ -357,7 +363,13 @@ def finishfold(ui, repo, ctx, oldctx, ne # 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) 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 @@ -153,10 +153,12 @@ 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] @@ -177,3 +179,226 @@ Check that histedit respect phases [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 < 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 < 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 < 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 < 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 ..