khanchi97 updated this revision to Diff 7877.

REPOSITORY
  rHG Mercurial

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

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

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

CHANGE DETAILS

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,217 @@
   rollback completed
   abort: pretxnclose-phase.nopublish_D hook exited with status 1
   [255]
+
+Test dry-run functionality
+
+  $ 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 log -G -T phases
+  @  changeset:   7:4ccc844d5454
+  |  tag:         tip
+  |  phase:       draft
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  summary:     7
+  |
+  o  changeset:   6:f19b7f89f44e
+  |  phase:       draft
+  |  parent:      3:14b465a7e25b
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  summary:     6
+  |
+  | o  changeset:   5:fdc0253c25cf
+  | |  phase:       draft
+  | |  user:        test
+  | |  date:        Thu Jan 01 00:00:00 1970 +0000
+  | |  summary:     5
+  | |
+  | o  changeset:   4:b385d13d5ed4
+  |/   phase:       draft
+  |    user:        test
+  |    date:        Thu Jan 01 00:00:00 1970 +0000
+  |    summary:     4
+  |
+  o  changeset:   3:14b465a7e25b
+  |  phase:       draft
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  summary:     3
+  |
+  o  changeset:   2:0316ce92851d
+  |  phase:       draft
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  summary:     2
+  |
+  o  changeset:   1:925d80f479bb
+  |  phase:       draft
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  summary:     1
+  |
+  o  changeset:   0:f7b1eb17ad24
+     phase:       draft
+     user:        test
+     date:        Thu Jan 01 00:00:00 1970 +0000
+     summary:     0
+  
+
+  $ 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 phases
+  @  changeset:   7:4ccc844d5454
+  |  tag:         tip
+  |  phase:       draft
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  summary:     7
+  |
+  o  changeset:   6:f19b7f89f44e
+  |  phase:       draft
+  |  parent:      3:14b465a7e25b
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  summary:     6
+  |
+  | o  changeset:   5:fdc0253c25cf
+  | |  phase:       secret
+  | |  user:        test
+  | |  date:        Thu Jan 01 00:00:00 1970 +0000
+  | |  summary:     5
+  | |
+  | o  changeset:   4:b385d13d5ed4
+  |/   phase:       secret
+  |    user:        test
+  |    date:        Thu Jan 01 00:00:00 1970 +0000
+  |    summary:     4
+  |
+  o  changeset:   3:14b465a7e25b
+  |  phase:       draft
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  summary:     3
+  |
+  o  changeset:   2:0316ce92851d
+  |  phase:       draft
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  summary:     2
+  |
+  o  changeset:   1:925d80f479bb
+  |  phase:       public
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  summary:     1
+  |
+  o  changeset:   0:f7b1eb17ad24
+     phase:       public
+     user:        test
+     date:        Thu Jan 01 00:00:00 1970 +0000
+     summary:     0
+  
+  $ hg phase --draft 0 5 -n
+  cannot move 1 changesets to a higher phase, use --force
+  phase changed for 2 changesets
+  [1]
+  $ hg phase --draft 0 5 --force -n
+  phase changed for 4 changesets
+
+  $ hg log -G -T phases
+  @  changeset:   7:4ccc844d5454
+  |  tag:         tip
+  |  phase:       draft
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  summary:     7
+  |
+  o  changeset:   6:f19b7f89f44e
+  |  phase:       draft
+  |  parent:      3:14b465a7e25b
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  summary:     6
+  |
+  | o  changeset:   5:fdc0253c25cf
+  | |  phase:       secret
+  | |  user:        test
+  | |  date:        Thu Jan 01 00:00:00 1970 +0000
+  | |  summary:     5
+  | |
+  | o  changeset:   4:b385d13d5ed4
+  |/   phase:       secret
+  |    user:        test
+  |    date:        Thu Jan 01 00:00:00 1970 +0000
+  |    summary:     4
+  |
+  o  changeset:   3:14b465a7e25b
+  |  phase:       draft
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  summary:     3
+  |
+  o  changeset:   2:0316ce92851d
+  |  phase:       draft
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  summary:     2
+  |
+  o  changeset:   1:925d80f479bb
+  |  phase:       public
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  summary:     1
+  |
+  o  changeset:   0:f7b1eb17ad24
+     phase:       public
+     user:        test
+     date:        Thu Jan 01 00:00:00 1970 +0000
+     summary:     0
+  
diff --git a/tests/test-completion.t b/tests/test-completion.t
--- a/tests/test-completion.t
+++ b/tests/test-completion.t
@@ -323,7 +323,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
@@ -3828,7 +3828,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
@@ -3868,6 +3868,8 @@
 
     ret = 0
     if targetphase is None:
+        if opts['dry_run']:
+            raise error.Abort(_("cannot use --dry-run without target phase"))
         # display
         for r in revs:
             ctx = repo[r]
@@ -3883,22 +3885,45 @@
             unfi = repo.unfiltered()
             getphase = unfi._phasecache.phase
             olddata = [getphase(unfi, r) for r in unfi]
-            phases.advanceboundary(repo, tr, targetphase, nodes)
-            if opts['force']:
-                phases.retractboundary(repo, tr, targetphase, nodes)
+            if not opts['dry_run']:
+                phases.advanceboundary(repo, tr, targetphase, nodes)
+                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 opts['dry_run']:
+            rejected = []
+            if not opts['force']:
+                rejected = [n for n in nodes
+                            if olddata[cl.rev(n)] < targetphase]
+            affected = set()
+            allphases = range(3)
+            phcache = repo._phasecache.copy()
+            for phase in xrange(targetphase + 1, len(allphases)):
+                nds = [n for n in nodes
+                       if phcache.phase(repo, repo[n].rev()) >= phase]
+                if not nds:
+                    break
+                oldroots = repo._phasecache.phaseroots[phase]
+                affected.update(unfi.revs('%ln::%ln', oldroots, nds))
+            if opts['force']:
+                nds = [n for n in nodes
+                       if phcache.phase(repo, repo[n].rev()) < targetphase]
+                oldroots = repo._phasecache.phaseroots[targetphase]
+                affected.update(unfi.revs('(%ln::) - (%ln::)', nds,
+                                          oldroots))
+            changes = len(affected)
         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:
+            if ret or opts['dry_run']:
                 ui.status(msg)
             else:
                 ui.note(msg)



To: khanchi97, pulkit, #hg-reviewers
Cc: av6, mercurial-devel
_______________________________________________
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Reply via email to