[PATCH] commit: enable --secret option
Sean Farley
sean.michael.farley at gmail.com
Sun Jul 14 16:47:42 CDT 2013
jordigh at octave.org writes:
> # HG changeset patch
> # User Jordi Gutiérrez Hermoso <jordigh at 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.
More information about the Mercurial-devel
mailing list