[PATCH 1 of 5] histedit: factor most commit creation in a function

Augie Fackler raf at durin42.com
Fri Jan 18 09:33:15 CST 2013


On Wed, Jan 16, 2013 at 07:28:15PM +0100, pierre-yves.david at logilab.fr wrote:
> # HG changeset patch
> # User Pierre-Yves David <pierre-yves.david at ens-lyon.org>
> # Date 1358359866 -3600
> # Node ID 92817b424cf7c73a23babf4c2f9d876b6c892cba
> # Parent  e3f5cef11d6a8eafdbaefa9b6c3d0e91fc3273fc
> histedit: factor most commit creation in a function

Queued this whole series with an English tweak in patch 1 and Kevin's
minor test tweak in patch 3. I'll probably queue this someplace other
than crew so that mpm can grab it easily without having to suck in all
of crew.

> 
> Later commits add two important items to histedit:
> - Obsolescence cycle prevention
> - Proper phase conservation
> 
> Those logics must be applied to all simple operations (pick, edit, mess) and
> will require verbose code.
> 
> So we introduce a new function that will provide an entry point for this new.
> logic.
> 
> The function build a closure to have a clear distinction between commit
> arguments and data provided to the function to fulfil its logic.
> 
> diff --git a/hgext/histedit.py b/hgext/histedit.py
> --- a/hgext/histedit.py
> +++ b/hgext/histedit.py
> @@ -174,10 +174,26 @@ editcomment = _("""# Edit history betwee
>  #  d, drop = remove commit from history
>  #  m, mess = edit message without changing commit content
>  #
>  """)
>  
> +def commitfuncfor(repo, src):
> +    """Build a commit function for the replacement of <src>
> +
> +    This function ensure we apply the same treatement to all changesets.
> +
> +    No such treatment is done yet.
> +
> +    Note that fold have its own separated logic because its handling is a bit
> +    different and non factorisable.
> +    """
> +    def commitfunc(**kwargs):
> +        return repo.commit(**kwargs)
> +    return commitfunc
> +
> +
> +
>  def applychanges(ui, repo, ctx, opts):
>      """Merge changeset from ctx (only) in the current working directory"""
>      wcpar = repo.dirstate.parents()[0]
>      if ctx.p1().node() == wcpar:
>          # edition ar "in place" we do not need to make any merge,
> @@ -277,12 +293,13 @@ def pick(ui, repo, ctx, ha, opts):
>      stats = applychanges(ui, repo, oldctx, opts)
>      if stats and stats[3] > 0:
>          raise util.Abort(_('Fix up the change and run '
>                             'hg histedit --continue'))
>      # drop the second merge parent
> -    n = repo.commit(text=oldctx.description(), user=oldctx.user(),
> -                    date=oldctx.date(), extra=oldctx.extra())
> +    commit = commitfuncfor(repo, oldctx)
> +    n = commit(text=oldctx.description(), user=oldctx.user(),
> +               date=oldctx.date(), extra=oldctx.extra())
>      if n is None:
>          ui.warn(_('%s: empty changeset\n')
>                       % node.hex(ha))
>          return ctx, []
>      new = repo[n]
> @@ -354,12 +371,13 @@ def message(ui, repo, ctx, ha, opts):
>      if stats and stats[3] > 0:
>          raise util.Abort(_('Fix up the change and run '
>                             'hg histedit --continue'))
>      message = oldctx.description() + '\n'
>      message = ui.edit(message, ui.username())
> -    new = repo.commit(text=message, user=oldctx.user(), date=oldctx.date(),
> -                      extra=oldctx.extra())
> +    commit = commitfuncfor(repo, oldctx)
> +    new = commit(text=message, user=oldctx.user(), date=oldctx.date(),
> +                 extra=oldctx.extra())
>      newctx = repo[new]
>      if oldctx.node() != newctx.node():
>          return newctx, [(oldctx.node(), (new,))]
>      # We didn't make an edit, so just indicate no replaced nodes
>      return newctx, []
> @@ -556,13 +574,14 @@ def bootstrapcontinue(ui, repo, parentct
>              message = ctx.description() + '\n'
>          if action in ('e', 'edit', 'm', 'mess'):
>              editor = cmdutil.commitforceeditor
>          else:
>              editor = False
> -        new = repo.commit(text=message, user=ctx.user(),
> -                          date=ctx.date(), extra=ctx.extra(),
> -                          editor=editor)
> +        commit = commitfuncfor(repo, ctx)
> +        new = commit(text=message, user=ctx.user(),
> +                     date=ctx.date(), extra=ctx.extra(),
> +                     editor=editor)
>          if new is not None:
>              newchildren.append(new)
>  
>      replacements = []
>      # track replacements


More information about the Mercurial-devel mailing list