Patchwork D3187: phase: add dry-run functionality

login
register
mail settings
Submitter phabricator
Date June 3, 2018, 2:48 p.m.
Message ID <84e4d1349b4f98270ef0de9c801a60a0@localhost.localdomain>
Download mbox | patch
Permalink /patch/31953/
State Not Applicable
Headers show

Comments

phabricator - June 3, 2018, 2:48 p.m.
khanchi97 updated this revision to Diff 8962.
khanchi97 edited the summary of this revision.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D3187?vs=8896&id=8962

REVISION DETAIL
  https://phab.mercurial-scm.org/D3187

AFFECTED FILES
  mercurial/commands.py
  tests/test-completion.t
  tests/test-phases.t

CHANGE DETAILS




To: khanchi97, pulkit, #hg-reviewers
Cc: av6, mercurial-devel

Patch

diff --git a/tests/test-phases.t b/tests/test-phases.t
--- a/tests/test-phases.t
+++ b/tests/test-phases.t
@@ -826,3 +826,122 @@ 
   rollback completed
   abort: pretxnclose-phase.nopublish_D hook exited with status 1
   [255]
+
+Test dry-run functionality, first lets prepare wrdir:
+
+  $ cd ..
+  $ hg init dryrunrepo
+  $ cd dryrunrepo
+  $ echo a > a
+  $ hg ci -qAm 0
+  test-debug-phase: new rev 0:  x -> 1
+  test-hook-close-phase: f7b1eb17ad24730a1651fccd46c43826d1bbc2ac:   -> draft
+  $ echo b > b
+  $ hg ci -qAm 1
+  test-debug-phase: new rev 1:  x -> 1
+  test-hook-close-phase: 925d80f479bb026b0fb3deb27503780b13f74123:   -> draft
+  $ echo c > c
+  $ hg ci -qAm 2
+  test-debug-phase: new rev 2:  x -> 1
+  test-hook-close-phase: 0316ce92851d493393d2181900388caa05d256c3:   -> draft
+  $ echo d > d
+  $ hg ci -qAm 3
+  test-debug-phase: new rev 3:  x -> 1
+  test-hook-close-phase: 14b465a7e25bf201e963c055be0e780414cff648:   -> draft
+  $ echo e > e
+  $ hg ci -qAm 4
+  test-debug-phase: new rev 4:  x -> 1
+  test-hook-close-phase: b385d13d5ed4ceb2b67ced172470734a60187cd1:   -> draft
+  $ echo f > f
+  $ hg ci -qAm 5
+  test-debug-phase: new rev 5:  x -> 1
+  test-hook-close-phase: fdc0253c25cfd67fe42b7be81e3abc9f92bebbd5:   -> draft
+  $ hg up 3 -q
+  $ echo g > g
+  $ hg ci -qAm 6
+  test-debug-phase: new rev 6:  x -> 1
+  test-hook-close-phase: f19b7f89f44eee9ffe34ba58b4e4ee3b3cea1f34:   -> draft
+  $ echo h > h
+  $ hg ci -qAm 7
+  test-debug-phase: new rev 7:  x -> 1
+  test-hook-close-phase: 4ccc844d545402eb0f39cd294227cd38de3ece20:   -> draft
+
+  $ hg phase --public 1
+  test-debug-phase: move rev 0: 1 -> 0
+  test-debug-phase: move rev 1: 1 -> 0
+  test-hook-close-phase: f7b1eb17ad24730a1651fccd46c43826d1bbc2ac:  draft -> public
+  test-hook-close-phase: 925d80f479bb026b0fb3deb27503780b13f74123:  draft -> public
+  $ hg phase --secret 4 --force
+  test-debug-phase: move rev 2: 1 -> 2
+  test-debug-phase: move rev 3: 1 -> 2
+  test-debug-phase: move rev 4: 1 -> 2
+  test-debug-phase: move rev 5: 1 -> 2
+  test-hook-close-phase: 0316ce92851d493393d2181900388caa05d256c3:  draft -> secret
+  test-hook-close-phase: 14b465a7e25bf201e963c055be0e780414cff648:  draft -> secret
+  test-hook-close-phase: b385d13d5ed4ceb2b67ced172470734a60187cd1:  draft -> secret
+  test-hook-close-phase: fdc0253c25cfd67fe42b7be81e3abc9f92bebbd5:  draft -> secret
+
+  $ hg log -G -T "{rev} : {node | short} : {phase}"
+  @  7 : 4ccc844d5454 : draft
+  |
+  o  6 : f19b7f89f44e : draft
+  |
+  | o  5 : fdc0253c25cf : secret
+  | |
+  | o  4 : b385d13d5ed4 : secret
+  |/
+  o  3 : 14b465a7e25b : draft
+  |
+  o  2 : 0316ce92851d : draft
+  |
+  o  1 : 925d80f479bb : public
+  |
+  o  0 : f7b1eb17ad24 : public
+  
+Now, lets check working of --dry-run:
+
+  $ hg phase --secret --force 1 -n
+  revisions whose phase can be changed:
+  [1, 2, 3, 6, 7]
+
+  $ hg log -G -T "{rev} : {node | short} : {phase}"
+  @  7 : 4ccc844d5454 : draft
+  |
+  o  6 : f19b7f89f44e : draft
+  |
+  | o  5 : fdc0253c25cf : secret
+  | |
+  | o  4 : b385d13d5ed4 : secret
+  |/
+  o  3 : 14b465a7e25b : draft
+  |
+  o  2 : 0316ce92851d : draft
+  |
+  o  1 : 925d80f479bb : public
+  |
+  o  0 : f7b1eb17ad24 : public
+  
+
+  $ hg phase --public  5 7 -n
+  revisions whose phase can be changed:
+  [2, 3, 4, 5, 6, 7]
+
+  $ hg log -G -T "{rev} : {node | short} : {phase}"
+  @  7 : 4ccc844d5454 : draft
+  |
+  o  6 : f19b7f89f44e : draft
+  |
+  | o  5 : fdc0253c25cf : secret
+  | |
+  | o  4 : b385d13d5ed4 : secret
+  |/
+  o  3 : 14b465a7e25b : draft
+  |
+  o  2 : 0316ce92851d : draft
+  |
+  o  1 : 925d80f479bb : public
+  |
+  o  0 : f7b1eb17ad24 : public
+  
+
+  $ cd ..
diff --git a/tests/test-completion.t b/tests/test-completion.t
--- a/tests/test-completion.t
+++ b/tests/test-completion.t
@@ -324,7 +324,7 @@ 
   outgoing: force, rev, newest-first, bookmarks, branch, patch, git, limit, no-merges, stat, graph, style, template, ssh, remotecmd, insecure, subrepos
   parents: rev, style, template
   paths: template
-  phase: public, draft, secret, force, rev
+  phase: public, draft, secret, force, rev, dry-run
   recover: 
   rename: after, force, include, exclude, dry-run
   resolve: all, list, mark, unmark, no-status, tool, include, exclude, template
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -3898,7 +3898,7 @@ 
      ('s', 'secret', False, _('set changeset phase to secret')),
      ('f', 'force', False, _('allow to move boundary backward')),
      ('r', 'rev', [], _('target revision'), _('REV')),
-    ],
+    ] + dryrunopts,
     _('[-p|-d|-s] [-f] [-r] [REV...]'))
 def phase(ui, repo, *revs, **opts):
     """set or show the current phase name
@@ -3918,6 +3918,7 @@ 
     (For more information about the phases concept, see :hg:`help phases`.)
     """
     opts = pycompat.byteskwargs(opts)
+    dryrun = opts.get('dry_run')
     # search for a unique phase argument
     targetphase = None
     for idx, name in enumerate(phases.phasenames):
@@ -3938,6 +3939,8 @@ 
 
     ret = 0
     if targetphase is None:
+        if dryrun:
+            raise error.Abort(_("cannot use --dry-run without target phase"))
         # display
         for r in revs:
             ctx = repo[r]
@@ -3953,27 +3956,36 @@ 
             unfi = repo.unfiltered()
             getphase = unfi._phasecache.phase
             olddata = [getphase(unfi, r) for r in unfi]
-            phases.advanceboundary(repo, tr, targetphase, nodes)
+            advchanges = phases.advanceboundary(repo, tr, targetphase, nodes,
+                                                dryrun=dryrun)
             if opts['force']:
-                phases.retractboundary(repo, tr, targetphase, nodes)
-        getphase = unfi._phasecache.phase
-        newdata = [getphase(unfi, r) for r in unfi]
-        changes = sum(newdata[r] != olddata[r] for r in unfi)
-        cl = unfi.changelog
-        rejected = [n for n in nodes
-                    if newdata[cl.rev(n)] < targetphase]
-        if rejected:
-            ui.warn(_('cannot move %i changesets to a higher '
-                      'phase, use --force\n') % len(rejected))
-            ret = 1
-        if changes:
-            msg = _('phase changed for %i changesets\n') % changes
-            if ret:
-                ui.status(msg)
+                retchanges = phases.retractboundary(repo, tr, targetphase,
+                                                    nodes, dryrun=dryrun)
+        if dryrun:
+            changes = advchanges
+            if opts.get('force'):
+                changes.update(retchanges)
+            ui.status(_("revisions whose phase can be "
+                        "changed:\n{}\n".format(list(changes))))
+        else:
+            getphase = unfi._phasecache.phase
+            newdata = [getphase(unfi, r) for r in unfi]
+            changes = sum(newdata[r] != olddata[r] for r in unfi)
+            cl = unfi.changelog
+            rejected = [n for n in nodes
+                        if newdata[cl.rev(n)] < targetphase]
+            if rejected:
+                ui.warn(_('cannot move %i changesets to a higher '
+                          'phase, use --force\n') % len(rejected))
+                ret = 1
+            if changes:
+                msg = _('phase changed for %i changesets\n') % changes
+                if ret:
+                    ui.status(msg)
+                else:
+                    ui.note(msg)
             else:
-                ui.note(msg)
-        else:
-            ui.warn(_('no phases changed\n'))
+                ui.warn(_('no phases changed\n'))
     return ret
 
 def postincoming(ui, repo, modheads, optupdate, checkout, brev):