Patchwork [01,of,13] cleanupnodes: expand long "one-liner"

login
register
mail settings
Submitter Boris Feld
Date Sept. 27, 2018, 5:08 p.m.
Message ID <4b1a3cbca27b5b846543.1538068113@localhost.localdomain>
Download mbox | patch
Permalink /patch/35141/
State Accepted
Headers show

Comments

Boris Feld - Sept. 27, 2018, 5:08 p.m.
# HG changeset patch
# User Boris Feld <boris.feld@octobus.net>
# Date 1537983753 -7200
#      Wed Sep 26 19:42:33 2018 +0200
# Node ID 4b1a3cbca27b5b8465435d29a476c8c1391d2904
# Parent  bce1c1af7518e87a6b8ee0761d8976c4b75da1b1
# EXP-Topic trackfold
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r 4b1a3cbca27b
cleanupnodes: expand long "one-liner"

When a one-liner gets 3 lines longs, it loses its expressivity benefits. We
expand it into a simple for loop. This makes future changes of the code in
that area clearer.

Patch

diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py
--- a/mercurial/scmutil.py
+++ b/mercurial/scmutil.py
@@ -968,9 +968,11 @@  def cleanupnodes(repo, replacements, ope
             isobs = unfi.obsstore.successors.__contains__
             torev = unfi.changelog.rev
             sortfunc = lambda ns: torev(ns[0])
-            rels = [(unfi[n], tuple(unfi[m] for m in s))
-                    for n, s in sorted(replacements.items(), key=sortfunc)
-                    if s or not isobs(n)]
+            rels = []
+            for n, s in sorted(replacements.items(), key=sortfunc):
+                if s or not isobs(n):
+                    rel = (unfi[n], tuple(unfi[m] for m in s))
+                    rels.append(rel)
             if rels:
                 obsolete.createmarkers(repo, rels, operation=operation,
                                        metadata=metadata)