[PATCH 2 of 8 evolve-ext, V2] metaedit: separate the fold and no-fold logic

Mateusz Kwapich mitrandir at fb.com
Tue Dec 6 11:41:11 EST 2016


# HG changeset patch
# User Mateusz Kwapich <mitrandir at fb.com>
# Date 1481029031 28800
#      Tue Dec 06 04:57:11 2016 -0800
# Branch stable
# Node ID b8cbdf6356d770b70df92b13095c11438b8ad1a1
# Parent  78b75ed14103cee05ed13948025310919adde559
metaedit: separate the fold and no-fold logic

As I want to implement the metaedit for multiple changesets I need to separate
the logic doing a metaedit with fold from the logic that is doing metaedit
without fold.

This change intentionally copies code so it's easier to follow when its
modified in the next changeset in that series.

diff --git a/hgext/evolve.py b/hgext/evolve.py
--- a/hgext/evolve.py
+++ b/hgext/evolve.py
@@ -3257,29 +3257,44 @@ def metaedit(ui, repo, *revs, **opts):
             if commitopts.get('message') or commitopts.get('logfile'):
                 commitopts['edit'] = False
             else:
-                if opts['fold']:
-                    msgs = ["HG: This is a fold of %d changesets." % len(allctx)]
-                    msgs += ["HG: Commit message of changeset %s.\n\n%s\n" %
-                             (c.rev(), c.description()) for c in allctx]
-                else:
-                    msgs = [head.description()]
-                commitopts['message'] =  "\n".join(msgs)
                 commitopts['edit'] = True
 
             # TODO: if the author and message are the same, don't create a new
             # hash. Right now we create a new hash because the date can be
             # different.
-            newid, created = rewrite(repo, root, allctx, head,
-                                     [root.p1().node(), root.p2().node()],
-                                     commitopts=commitopts)
-            if created:
-                if p1.rev() in revs:
-                    newp1 = newid
-                phases.retractboundary(repo, tr, targetphase, [newid])
-                obsolete.createmarkers(repo, [(ctx, (repo[newid],))
-                                              for ctx in allctx])
+            if opts['fold']:
+                if commitopts['edit']:
+                    msgs = ["HG: This is a fold of %d changesets." %
+                            len(allctx)]
+                    msgs += ["HG: Commit message of changeset %s.\n\n%s\n" %
+                             (c.rev(), c.description()) for c in allctx]
+                    commitopts['message'] = "\n".join(msgs)
+
+                newid, created = rewrite(repo, root, allctx, head,
+                                         [root.p1().node(), root.p2().node()],
+                                         commitopts=commitopts)
+                if created:
+                    if p1.rev() in revs:
+                        newp1 = newid
+                    phases.retractboundary(repo, tr, targetphase, [newid])
+                    obsolete.createmarkers(repo, [(ctx, (repo[newid],))
+                                                  for ctx in allctx])
+                else:
+                    ui.status(_("nothing changed\n"))
             else:
-                ui.status(_("nothing changed\n"))
+                if commitopts['edit']:
+                    commitopts['message'] = head.description()
+                newid, created = rewrite(repo, root, allctx, head,
+                                         [root.p1().node(), root.p2().node()],
+                                         commitopts=commitopts)
+                if created:
+                    if p1.rev() in revs:
+                        newp1 = newid
+                    phases.retractboundary(repo, tr, targetphase, [newid])
+                    obsolete.createmarkers(repo, [(ctx, (repo[newid],))
+                                                  for ctx in allctx])
+                else:
+                    ui.status(_("nothing changed\n"))
             tr.close()
         finally:
             tr.release()


More information about the Mercurial-devel mailing list