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

login
register
mail settings
Submitter Pierre-Yves David
Date Jan. 16, 2013, 6:28 p.m.
Message ID <92817b424cf7c73a23ba.1358360895@crater2.logilab.fr>
Download mbox | patch
Permalink /patch/658/
State Accepted
Commit b38c10502af9a61ffc6a94c09787703dada3d4bd
Headers show

Comments

Pierre-Yves David - Jan. 16, 2013, 6:28 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@ens-lyon.org>
# Date 1358359866 -3600
# Node ID 92817b424cf7c73a23babf4c2f9d876b6c892cba
# Parent  e3f5cef11d6a8eafdbaefa9b6c3d0e91fc3273fc
histedit: factor most commit creation in a function

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.
Pierre-Yves David - Jan. 16, 2013, 7:27 p.m.
On 16 janv. 2013, at 20:25, Kevin Bullock wrote:

> On 16 Jan 2013, at 12:28 PM, pierre-yves.david@logilab.fr wrote:
> 
>> # HG changeset patch
>> # User Pierre-Yves David <pierre-yves.david@ens-lyon.org>
>> # Date 1358359866 -3600
>> # Node ID 92817b424cf7c73a23babf4c2f9d876b6c892cba
>> # Parent  e3f5cef11d6a8eafdbaefa9b6c3d0e91fc3273fc
>> histedit: factor most commit creation in a function
>> 
>> 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
> 
> Huh? Where did 'src' go?

Nowhere, this function does not do anything yet.
Augie Fackler - Jan. 18, 2013, 3:33 p.m.
On Wed, Jan 16, 2013 at 07:28:15PM +0100, pierre-yves.david@logilab.fr wrote:
> # HG changeset patch
> # User Pierre-Yves David <pierre-yves.david@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
Augie Fackler - Jan. 18, 2013, 3:37 p.m.
On Fri, Jan 18, 2013 at 10:33 AM, Augie Fackler <raf@durin42.com> wrote:

> On Wed, Jan 16, 2013 at 07:28:15PM +0100, pierre-yves.david@logilab.frwrote:
> > # HG changeset patch
> > # User Pierre-Yves David <pierre-yves.david@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.
>

Correction: I'm going to crew this (but hang on to my bookmark of it just
in case) since mpm seems to be completely caught up with 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
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel
>

Patch

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