D376: filemerge: extract `_picklabels` as a helper function
phillco (Phil Cohen)
phabricator at mercurial-scm.org
Mon Aug 14 06:15:48 UTC 2017
phillco created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.
REVISION SUMMARY
This shortens `simplemerge()` and is a bit cleaner, IMO.
REPOSITORY
rHG Mercurial
REVISION DETAIL
https://phab.mercurial-scm.org/D376
AFFECTED FILES
mercurial/simplemerge.py
CHANGE DETAILS
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)
To: phillco, #hg-reviewers
Cc: mercurial-devel
More information about the Mercurial-devel
mailing list