[PATCH 13 of 18] phases: add a secret switch to commit

pierre-yves.david at logilab.fr pierre-yves.david at logilab.fr
Mon Oct 10 07:28:09 CDT 2011


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at logilab.fr>
# Date 1318247752 -7200
# Node ID eb0f9eeafc6f620a749de135c53c89f4cf239e5b
# Parent  22819d45ed2b8cf781a484b745a28ebe299b41b6
phases: add a secret switch to commit

diff --git a/hgext/mq.py b/hgext/mq.py
--- a/hgext/mq.py
+++ b/hgext/mq.py
@@ -3107,17 +3107,17 @@ def reposetup(ui, repo):
                 patches = [s.node for s in self.mq.applied]
                 if parents[0] in patches or parents[1] in patches:
                     raise util.Abort(errmsg)
 
         def commit(self, text="", user=None, date=None, match=None,
-                   force=False, editor=False, extra={}):
+                   force=False, editor=False, extra={}, **kwargs):
             self.abortifwdirpatched(
                 _('cannot commit over an applied mq patch'),
                 force)
 
             return super(mqrepo, self).commit(text, user, date, match, force,
-                                              editor, extra)
+                                              editor, extra, **kwargs)
 
         def checkpush(self, force, revs):
             if self.mq.applied and not force:
                 haspatches = True
                 if revs:
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -1136,10 +1136,12 @@ def clone(ui, source, dest=None, **opts)
 @command('^commit|ci',
     [('A', 'addremove', None,
      _('mark new/missing files as added/removed before committing')),
     ('', 'close-branch', None,
      _('mark a branch as closed, hiding it from the branch list')),
+    ('-s', 'secret', False,
+     _('commit this change as secret')),
     ] + walkopts + commitopts + commitopts2,
     _('[OPTION]... [FILE]...'))
 def commit(ui, repo, *pats, **opts):
     """commit the specified files or all outstanding changes
 
@@ -1172,12 +1174,16 @@ def commit(ui, repo, *pats, **opts):
     e = cmdutil.commiteditor
     if opts.get('force_editor'):
         e = cmdutil.commitforceeditor
 
     def commitfunc(ui, repo, message, match, opts):
+        if opts.get('secret'):
+            minphase = 2
+        else:
+            minphase = 1
         return repo.commit(message, opts.get('user'), opts.get('date'), match,
-                           editor=e, extra=extra)
+                           editor=e, extra=extra, minphase=minphase)
 
     branch = repo[None].branch()
     bheads = repo.branchheads(branch)
 
     node = cmdutil.commit(ui, repo, commitfunc, pats, opts)
diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -1025,11 +1025,11 @@ class localrepository(repo.repository):
             changelist.append(fname)
 
         return fparent1
 
     def commit(self, text="", user=None, date=None, match=None, force=False,
-               editor=False, extra={}):
+               editor=False, extra={}, minphase=1):
         """Add a new revision to current repository.
 
         Revision information is gathered from the working directory,
         match can be used to filter the committed files. If editor is
         supplied, it is called to get a commit message.
@@ -1144,11 +1144,11 @@ class localrepository(repo.repository):
             msgfn = self.savecommitmessage(cctx._text)
 
             p1, p2 = self.dirstate.parents()
             # compute newphase before adding the changeset to prevent
             # issue with the repo.heads() default value
-            newphase = max(1, self.nodephase(p1))
+            newphase = max(minphase, self.nodephase(p1))
             if p2 != nullid:
                 newphase = max(newphase, self.nodephase(p2))
 
             hookp1, hookp2 = hex(p1), (p2 != nullid and hex(p2) or '')
             try:
diff --git a/tests/test-phases.t b/tests/test-phases.t
--- a/tests/test-phases.t
+++ b/tests/test-phases.t
@@ -1,9 +1,9 @@
   $ mkcommit() {
   >    echo "$1" > "$1"
   >    hg add "$1"
-  >    hg ci -m "$1"
+  >    hg ci -m "$1" $2
   > }
   $ alias hglog='hg log --template "{rev} {phase} {desc}\n"'
 
   $ hg init initialrepo
   $ cd initialrepo
@@ -80,6 +80,37 @@ Simpliest test: change the phase of the 
   3 0 D
   2 0 C
   1 0 B
   0 0 A
 
+Test creating changeset as secret
 
+  $ mkcommit H --secret
+  $ hglog
+  7 2 H
+  6 1 G
+  5 0 F
+  4 0 E
+  3 0 D
+  2 0 C
+  1 0 B
+  0 0 A
+
+Test the secret property is inherited
+XXX do it on merge too
+
+  $ mkcommit I
+  $ hglog
+  8 2 I
+  7 2 H
+  6 1 G
+  5 0 F
+  4 0 E
+  3 0 D
+  2 0 C
+  1 0 B
+  0 0 A
+
+
+
+
+


More information about the Mercurial-devel mailing list