Patchwork [4,of,6,V2] filemerge: allow the formating of three labels instead of two

login
register
mail settings
Submitter Pierre-Yves David
Date Aug. 5, 2014, 11:30 p.m.
Message ID <ecfd2f513564593a31a8.1407281444@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/5271/
State Accepted
Headers show

Comments

Pierre-Yves David - Aug. 5, 2014, 11:30 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@fb.com>
# Date 1407277058 25200
#      Tue Aug 05 15:17:38 2014 -0700
# Node ID ecfd2f513564593a31a8859fa1aa5e7fa5d69bcf
# Parent  4399f677c588e96fd760bbcaccb746bd01d0857b
filemerge: allow the formating of three labels instead of two

When a third label is provided (to included the base content) it is properly
processed as the two others. Nothing change if only two label are provided.

Patch

diff --git a/mercurial/filemerge.py b/mercurial/filemerge.py
--- a/mercurial/filemerge.py
+++ b/mercurial/filemerge.py
@@ -310,27 +310,31 @@  def _formatconflictmarker(repo, ctx, tem
     '{ifeq(branch, "default", "", "{branch} ")}' +
     '- {author|user}: {desc|firstline}')
 
 _defaultconflictlabels = ['local', 'other']
 
-def _formatlabels(repo, fcd, fco, labels):
+def _formatlabels(repo, fcd, fco, fca, labels):
     """Formats the given labels using the conflict marker template.
 
     Returns a list of formatted labels.
     """
     cd = fcd.changectx()
     co = fco.changectx()
+    ca = fca.changectx()
 
     ui = repo.ui
     template = ui.config('ui', 'mergemarkertemplate', _defaultconflictmarker)
     template = templater.parsestring(template, quoted=False)
     tmpl = templater.templater(None, cache={'conflictmarker': template})
 
-    pad = max(len(labels[0]), len(labels[1]))
+    pad = max(len(l) for l in labels)
 
-    return [_formatconflictmarker(repo, cd, tmpl, labels[0], pad),
-            _formatconflictmarker(repo, co, tmpl, labels[1], pad)]
+    newlabels = [_formatconflictmarker(repo, cd, tmpl, labels[0], pad),
+                 _formatconflictmarker(repo, co, tmpl, labels[1], pad)]
+    if len(labels) > 2:
+        newlabels.append(_formatconflictmarker(repo, ca, tmpl, labels[2], pad))
+    return newlabels
 
 def filemerge(repo, mynode, orig, fcd, fco, fca, labels=None):
     """perform a 3-way merge in the working directory
 
     mynode = parent node before merge
@@ -389,11 +393,11 @@  def filemerge(repo, mynode, orig, fcd, f
 
     markerstyle = ui.config('ui', 'mergemarkers', 'basic')
     if not labels:
         labels = _defaultconflictlabels
     if markerstyle != 'basic':
-        labels = _formatlabels(repo, fcd, fco, labels)
+        labels = _formatlabels(repo, fcd, fco, fca, labels)
 
     needcheck, r = func(repo, mynode, orig, fcd, fco, fca, toolconf,
                         (a, b, c, back), labels=labels)
     if not needcheck:
         if r: