Patchwork D376: filemerge: extract `_picklabels` as a helper function

login
register
mail settings
Submitter phabricator
Date Aug. 15, 2017, 9:32 p.m.
Message ID <bb3b915d26c0535fe08bf0f435ead422@localhost.localdomain>
Download mbox | patch
Permalink /patch/23054/
State Not Applicable
Headers show

Comments

phabricator - Aug. 15, 2017, 9:32 p.m.
This revision was automatically updated to reflect the committed changes.
Closed by commit rHGaa6c290a77fa: filemerge: extract `_picklabels` as a helper function (authored by phillco).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D376?vs=857&id=958

REVISION DETAIL
  https://phab.mercurial-scm.org/D376

AFFECTED FILES
  mercurial/simplemerge.py

CHANGE DETAILS




To: phillco, #hg-reviewers
Cc: mercurial-devel

Patch

diff --git a/mercurial/simplemerge.py b/mercurial/simplemerge.py
--- a/mercurial/simplemerge.py
+++ b/mercurial/simplemerge.py
@@ -408,6 +408,20 @@ 
             raise error.Abort(msg)
     return text
 
+def _picklabels(defaults, overrides):
+    name_a, name_b, name_base = defaults
+
+    if len(overrides) > 0:
+        name_a = overrides[0]
+    if len(overrides) > 1:
+        name_b = overrides[1]
+    if len(overrides) > 2:
+        name_base = overrides[2]
+    if len(overrides) > 3:
+        raise error.Abort(_("can only specify three labels."))
+
+    return [name_a, name_b, name_base]
+
 def simplemerge(ui, localfile, basefile, otherfile,
                 localctx=None, basectx=None, otherctx=None, repo=None, **opts):
     """Performs the simplemerge algorithm.
@@ -446,23 +460,11 @@ 
             self.ctx.write(self.text, self.ctx.flags())
 
     mode = opts.get('mode','merge')
-    if mode == 'union':
-        name_a = None
-        name_b = None
-        name_base = None
-    else:
-        name_a = localfile
-        name_b = otherfile
-        name_base = None
-        labels = opts.get('label', [])
-        if len(labels) > 0:
-            name_a = labels[0]
-        if len(labels) > 1:
-            name_b = labels[1]
-        if len(labels) > 2:
-            name_base = labels[2]
-        if len(labels) > 3:
-            raise error.Abort(_("can only specify three labels."))
+    name_a, name_b, name_base = None, None, None
+    if mode != 'union':
+        name_a, name_b, name_base = _picklabels([localfile,
+                                                 otherfile, None],
+                                                opts.get('label', []))
 
     try:
         localtext = readctx(localctx) if localctx else readfile(localfile)