Patchwork [1,of,4] strip: simplify some repeated conditions

login
register
mail settings
Submitter via Mercurial-devel
Date Sept. 19, 2016, 5:30 p.m.
Message ID <fcd760d062be51c78eae.1474306221@martinvonz.mtv.corp.google.com>
Download mbox | patch
Permalink /patch/16667/
State Accepted
Headers show

Comments

via Mercurial-devel - Sept. 19, 2016, 5:30 p.m.
# HG changeset patch
# User Martin von Zweigbergk <martinvonz@google.com>
# Date 1473959936 25200
#      Thu Sep 15 10:18:56 2016 -0700
# Node ID fcd760d062be51c78eaea0281bc253ce1022f09f
# Parent  2c302c6544511b37abe61ee2cc5278e4f61d5e71
strip: simplify some repeated conditions

We check "if saveheads or savebases" in several places to see if we
should or have created a bundle of the changesets to apply after
truncating the revlogs. One of the conditions is actually just "if
saveheads", but since there can't be savebases without saveheads, that
is effectively the same condition. It seems simpler to check only once
and from then on see if we created the file.
Yuya Nishihara - Sept. 20, 2016, 2:03 p.m.
On Mon, 19 Sep 2016 10:30:21 -0700, Martin von Zweigbergk via Mercurial-devel wrote:
> # HG changeset patch
> # User Martin von Zweigbergk <martinvonz@google.com>
> # Date 1473959936 25200
> #      Thu Sep 15 10:18:56 2016 -0700
> # Node ID fcd760d062be51c78eaea0281bc253ce1022f09f
> # Parent  2c302c6544511b37abe61ee2cc5278e4f61d5e71
> strip: simplify some repeated conditions

Queued the series, thanks.

Patch

diff -r 2c302c654451 -r fcd760d062be mercurial/repair.py
--- a/mercurial/repair.py	Wed Sep 14 17:12:39 2016 +0200
+++ b/mercurial/repair.py	Thu Sep 15 10:18:56 2016 -0700
@@ -147,7 +147,8 @@ 
                        vfs.join(backupfile))
         repo.ui.log("backupbundle", "saved backup bundle to %s\n",
                     vfs.join(backupfile))
-    if saveheads or savebases:
+    chgrpfile = None
+    if saveheads:
         # do not compress partial bundle if we remove it from disk later
         chgrpfile = _bundle(repo, savebases, saveheads, node, 'temp',
                             compress=False)
@@ -184,7 +185,7 @@ 
                 if troffset == 0:
                     repo.store.markremoved(file)
 
-        if saveheads or savebases:
+        if chgrpfile:
             ui.note(_("adding branch\n"))
             f = vfs.open(chgrpfile, "rb")
             gen = exchange.readbundle(ui, f, chgrpfile, vfs)
@@ -229,12 +230,12 @@ 
         if backupfile:
             ui.warn(_("strip failed, full bundle stored in '%s'\n")
                     % vfs.join(backupfile))
-        elif saveheads:
+        elif chgrpfile:
             ui.warn(_("strip failed, partial bundle stored in '%s'\n")
                     % vfs.join(chgrpfile))
         raise
     else:
-        if saveheads or savebases:
+        if chgrpfile:
             # Remove partial backup only if there were no exceptions
             vfs.unlink(chgrpfile)