Patchwork commit: enable --secret option

login
register
mail settings
Submitter Jordi Gutiérrez Hermoso
Date July 11, 2013, 6:02 p.m.
Message ID <af838119f85b9d4c322e.1373565741@Iris>
Download mbox | patch
Permalink /patch/1831/
State Accepted
Commit 4a0d0616c47daa0a63f582bb611a20a7c4ec95d9
Headers show

Comments

Jordi Gutiérrez Hermoso - July 11, 2013, 6:02 p.m.
# HG changeset patch
# User Jordi Gutiérrez Hermoso <jordigh@octave.org>
# Date 1373562701 14400
#      Thu Jul 11 13:11:41 2013 -0400
# Node ID af838119f85b9d4c322eb175bc4186a63b82af45
# Parent  0e25a9e259314b8b5aa4d73766bd88247fe22bd9
commit: enable --secret option

At the moment, creating secret commits is slightly cumbersome. They
can either be created by changing the default commit phase to secret
or by doing `hg phase --secret --force`. Both of these make secret
commits appear to be like some kind of advanced feature.

Secret commits, however, should be a convenient feature for people who
want to work on a private branch without affecting anyone else. There
should therefore be a prominent and convenient method for creating
secret commits.

Since the default phase is draft and there is no need to use --force
to go from a secret phase to any other phase, this patch
intentionally does not add --draft and --public options.
Sean Farley - July 14, 2013, 9:47 p.m.
jordigh@octave.org writes:

> # HG changeset patch
> # User Jordi Gutiérrez Hermoso <jordigh@octave.org>
> # Date 1373562701 14400
> #      Thu Jul 11 13:11:41 2013 -0400
> # Node ID af838119f85b9d4c322eb175bc4186a63b82af45
> # Parent  0e25a9e259314b8b5aa4d73766bd88247fe22bd9
> commit: enable --secret option
>
> At the moment, creating secret commits is slightly cumbersome. They
> can either be created by changing the default commit phase to secret
> or by doing `hg phase --secret --force`. Both of these make secret
> commits appear to be like some kind of advanced feature.
>
> Secret commits, however, should be a convenient feature for people who
> want to work on a private branch without affecting anyone else. There
> should therefore be a prominent and convenient method for creating
> secret commits.
>
> Since the default phase is draft and there is no need to use --force
> to go from a secret phase to any other phase, this patch
> intentionally does not add --draft and --public options.
>
> diff --git a/mercurial/commands.py b/mercurial/commands.py
> --- a/mercurial/commands.py
> +++ b/mercurial/commands.py
> @@ -1286,6 +1286,7 @@
>      ('', 'close-branch', None,
>       _('mark a branch as closed, hiding it from the branch list')),
>      ('', 'amend', None, _('amend the parent of the working dir')),
> +    ('s', 'secret', None, _('use the secret phase for committing')),
>      ] + walkopts + commitopts + commitopts2 + subrepoopts,
>      _('[OPTION]... [FILE]...'))
>  def commit(ui, repo, *pats, **opts):
> @@ -1330,6 +1331,9 @@
>          # Let --subrepos on the command line override config setting.
>          ui.setconfig('ui', 'commitsubrepos', True)
>  
> +    # Save this for restoring it later
> +    oldcommitphase = ui.config('phases', 'new-commit')
> +
>      if repo.vfs.exists('graftstate'):
>          raise util.Abort(_('cannot commit an interrupted graft operation'),
>                           hint=_('use "hg graft -c" to continue graft'))
> @@ -1371,12 +1375,18 @@
>              if not message:
>                  message = old.description()
>                  editor = cmdutil.commitforceeditor
> -            return repo.commit(message,
> -                               opts.get('user') or old.user(),
> -                               opts.get('date') or old.date(),
> -                               match,
> -                               editor=editor,
> -                               extra=extra)
> +            try:
> +                if opts.get('secret'):
> +                    ui.setconfig('phases', 'new-commit', 'secret')
> +
> +                return repo.commit(message,
> +                                   opts.get('user') or old.user(),
> +                                   opts.get('date') or old.date(),
> +                                   match,
> +                                   editor=editor,
> +                                   extra=extra)
> +            finally:
> +                ui.setconfig('phases', 'new-commit', oldcommitphase)

I was a little wary of setting a global option just to get around
changing the signature of repo.commit but I guess it's the easiest reuse
of current code already in-place.

That being said, I would really like this functionality in core.
Pierre-Yves David - July 18, 2013, 2:49 a.m.
On 11 juil. 2013, at 20:02, Jordi Gutiérrez Hermoso wrote:

> # HG changeset patch
> # User Jordi Gutiérrez Hermoso <jordigh@octave.org>
> # Date 1373562701 14400
> #      Thu Jul 11 13:11:41 2013 -0400
> # Node ID af838119f85b9d4c322eb175bc4186a63b82af45
> # Parent  0e25a9e259314b8b5aa4d73766bd88247fe22bd9
> commit: enable --secret option

I had not time to actually test it but the patch looks good to me.
Pierre-Yves David - July 18, 2013, 2:51 a.m.
On 14 juil. 2013, at 23:47, Sean Farley wrote:

>> @@ -1371,12 +1375,18 @@
>>             if not message:
>>                 message = old.description()
>>                 editor = cmdutil.commitforceeditor
>> -            return repo.commit(message,
>> -                               opts.get('user') or old.user(),
>> -                               opts.get('date') or old.date(),
>> -                               match,
>> -                               editor=editor,
>> -                               extra=extra)
>> +            try:
>> +                if opts.get('secret'):
>> +                    ui.setconfig('phases', 'new-commit', 'secret')
>> +
>> +                return repo.commit(message,
>> +                                   opts.get('user') or old.user(),
>> +                                   opts.get('date') or old.date(),
>> +                                   match,
>> +                                   editor=editor,
>> +                                   extra=extra)
>> +            finally:
>> +                ui.setconfig('phases', 'new-commit', oldcommitphase)
> 
> I was a little wary of setting a global option just to get around
> changing the signature of repo.commit but I guess it's the easiest reuse
> of current code already in-place.

That is, sadly, the official way to do it. The other option would be to alter the whole call stack of commit at was dimmed not worthy.
Matt Mackall - July 18, 2013, 3:05 a.m.
On Thu, 2013-07-11 at 14:02 -0400, Jordi Gutiérrez Hermoso wrote:
> # HG changeset patch
> # User Jordi Gutiérrez Hermoso <jordigh@octave.org>
> # Date 1373562701 14400
> #      Thu Jul 11 13:11:41 2013 -0400
> # Node ID af838119f85b9d4c322eb175bc4186a63b82af45
> # Parent  0e25a9e259314b8b5aa4d73766bd88247fe22bd9
> commit: enable --secret option

Queued for default, thanks.

Patch

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -1286,6 +1286,7 @@ 
     ('', 'close-branch', None,
      _('mark a branch as closed, hiding it from the branch list')),
     ('', 'amend', None, _('amend the parent of the working dir')),
+    ('s', 'secret', None, _('use the secret phase for committing')),
     ] + walkopts + commitopts + commitopts2 + subrepoopts,
     _('[OPTION]... [FILE]...'))
 def commit(ui, repo, *pats, **opts):
@@ -1330,6 +1331,9 @@ 
         # Let --subrepos on the command line override config setting.
         ui.setconfig('ui', 'commitsubrepos', True)
 
+    # Save this for restoring it later
+    oldcommitphase = ui.config('phases', 'new-commit')
+
     if repo.vfs.exists('graftstate'):
         raise util.Abort(_('cannot commit an interrupted graft operation'),
                          hint=_('use "hg graft -c" to continue graft'))
@@ -1371,12 +1375,18 @@ 
             if not message:
                 message = old.description()
                 editor = cmdutil.commitforceeditor
-            return repo.commit(message,
-                               opts.get('user') or old.user(),
-                               opts.get('date') or old.date(),
-                               match,
-                               editor=editor,
-                               extra=extra)
+            try:
+                if opts.get('secret'):
+                    ui.setconfig('phases', 'new-commit', 'secret')
+
+                return repo.commit(message,
+                                   opts.get('user') or old.user(),
+                                   opts.get('date') or old.date(),
+                                   match,
+                                   editor=editor,
+                                   extra=extra)
+            finally:
+                ui.setconfig('phases', 'new-commit', oldcommitphase)
 
         current = repo._bookmarkcurrent
         marks = old.bookmarks()
@@ -1399,8 +1409,15 @@ 
             e = cmdutil.commitforceeditor
 
         def commitfunc(ui, repo, message, match, opts):
-            return repo.commit(message, opts.get('user'), opts.get('date'),
-                               match, editor=e, extra=extra)
+            try:
+                if opts.get('secret'):
+                    ui.setconfig('phases', 'new-commit', 'secret')
+
+                return repo.commit(message, opts.get('user'), opts.get('date'),
+                                   match, editor=e, extra=extra)
+            finally:
+                ui.setconfig('phases', 'new-commit', oldcommitphase)
+
 
         node = cmdutil.commit(ui, repo, commitfunc, pats, opts)