##// END OF EJS Templates
sidedata-exchange: rewrite sidedata on-the-fly whenever possible...
sidedata-exchange: rewrite sidedata on-the-fly whenever possible When a A exchanges with B, the difference of their supported sidedata categories is made, and the responsibility is always with the client to generated it: - If A pushes to B and B requires category `foo` that A does not have, A will need to generate it when sending it to B. - If A pulls from B and A needs category `foo`, it will generate `foo` before the end of the transaction. - Any category that is not required is removed. If peers are not compatible, abort. It is forbidden to rewrite sidedata for a rev that already has sidedata, since that would introduce unreachable (garbage) data in the data file, something we're not prepared for yet. Differential Revision: https://phab.mercurial-scm.org/D10032

File last commit:

r47064:98e3a693 default
r47452:ba8e508a default
Show More
simplemerge.py
566 lines | 18.2 KiB | text/x-python | PythonLexer
Matt Mackall
merge: move the bulk of simplemerge into core...
r6002 # Copyright (C) 2004, 2005 Canonical Ltd
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
Martin Geisler
Remove FSF mailing address from GPL headers...
r15782 # along with this program; if not, see <http://www.gnu.org/licenses/>.
Matt Mackall
merge: move the bulk of simplemerge into core...
r6002
# mbp: "you know that thing where cvs gives you conflict markers?"
# s: "i hate that."
Gregory Szorc
simplemerge: use absolute_import
r25974 from __future__ import absolute_import
from .i18n import _
Joerg Sonnenberger
node: import symbols explicitly...
r46729 from .node import nullid
Gregory Szorc
simplemerge: use absolute_import
r25974 from . import (
Pierre-Yves David
error: get Abort from 'error' instead of 'util'...
r26587 error,
Gregory Szorc
simplemerge: use absolute_import
r25974 mdiff,
Pulkit Goyal
py3: convert kwargs' keys' to str using pycompat.strkwargs()...
r33017 pycompat,
flags: actually merge flags in simplemerge...
r45398 util,
Yuya Nishihara
stringutil: bulk-replace call sites to point to new module...
r37102 )
Augie Fackler
formatting: blacken the codebase...
r43346 from .utils import stringutil
Matt Mackall
merge: move the bulk of simplemerge into core...
r6002
class CantReprocessAndShowBase(Exception):
pass
Augie Fackler
formatting: blacken the codebase...
r43346
Matt Mackall
merge: move the bulk of simplemerge into core...
r6002 def intersect(ra, rb):
"""Given two ranges return the range where they intersect or None.
>>> intersect((0, 10), (0, 6))
(0, 6)
>>> intersect((0, 10), (5, 15))
(5, 10)
>>> intersect((0, 10), (10, 15))
>>> intersect((0, 9), (10, 15))
>>> intersect((0, 9), (7, 15))
(7, 9)
"""
assert ra[0] <= ra[1]
assert rb[0] <= rb[1]
sa = max(ra[0], rb[0])
sb = min(ra[1], rb[1])
if sa < sb:
return sa, sb
else:
return None
Augie Fackler
formatting: blacken the codebase...
r43346
Matt Mackall
merge: move the bulk of simplemerge into core...
r6002 def compare_range(a, astart, aend, b, bstart, bend):
Augie Fackler
formating: upgrade to black 20.8b1...
r46554 """Compare a[astart:aend] == b[bstart:bend], without slicing."""
Matt Mackall
many, many trivial check-code fixups
r10282 if (aend - astart) != (bend - bstart):
Matt Mackall
merge: move the bulk of simplemerge into core...
r6002 return False
Augie Fackler
formatting: blacken the codebase...
r43346 for ia, ib in zip(
pycompat.xrange(astart, aend), pycompat.xrange(bstart, bend)
):
Matt Mackall
merge: move the bulk of simplemerge into core...
r6002 if a[ia] != b[ib]:
return False
else:
return True
Augie Fackler
formatting: blacken the codebase...
r43346
Matt Mackall
merge: move the bulk of simplemerge into core...
r6002 class Merge3Text(object):
"""3-way merge of texts.
Given strings BASE, OTHER, THIS, tries to produce a combined text
incorporating the changes from both BASE->OTHER and BASE->THIS."""
Augie Fackler
formatting: blacken the codebase...
r43346
Matt Mackall
merge: move the bulk of simplemerge into core...
r6002 def __init__(self, basetext, atext, btext, base=None, a=None, b=None):
self.basetext = basetext
self.atext = atext
self.btext = btext
if base is None:
base = mdiff.splitnewlines(basetext)
if a is None:
a = mdiff.splitnewlines(atext)
if b is None:
b = mdiff.splitnewlines(btext)
self.base = base
self.a = a
self.b = b
Augie Fackler
formatting: blacken the codebase...
r43346 def merge_lines(
self,
name_a=None,
name_b=None,
name_base=None,
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 start_marker=b'<<<<<<<',
mid_marker=b'=======',
end_marker=b'>>>>>>>',
Augie Fackler
formatting: blacken the codebase...
r43346 base_marker=None,
localorother=None,
minimize=False,
):
Augie Fackler
formating: upgrade to black 20.8b1...
r46554 """Return merge in cvs-like form."""
Matt Mackall
merge: move the bulk of simplemerge into core...
r6002 self.conflicts = False
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 newline = b'\n'
Matt Mackall
merge: move the bulk of simplemerge into core...
r6002 if len(self.a) > 0:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if self.a[0].endswith(b'\r\n'):
newline = b'\r\n'
elif self.a[0].endswith(b'\r'):
newline = b'\r'
Erik Huelsmann
simplemerge: add 'mode' kwarg which - when 'union' - suppresses markers...
r26069 if name_a and start_marker:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 start_marker = start_marker + b' ' + name_a
Erik Huelsmann
simplemerge: add 'mode' kwarg which - when 'union' - suppresses markers...
r26069 if name_b and end_marker:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 end_marker = end_marker + b' ' + name_b
Matt Mackall
merge: move the bulk of simplemerge into core...
r6002 if name_base and base_marker:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 base_marker = base_marker + b' ' + name_base
Matt Mackall
merge: move the bulk of simplemerge into core...
r6002 merge_regions = self.merge_regions()
Ryan McElroy
merge: minimize conflicts when common base is not shown (issue4447)...
r28072 if minimize:
merge_regions = self.minimize(merge_regions)
Matt Mackall
merge: move the bulk of simplemerge into core...
r6002 for t in merge_regions:
what = t[0]
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if what == b'unchanged':
Matt Mackall
merge: move the bulk of simplemerge into core...
r6002 for i in range(t[1], t[2]):
yield self.base[i]
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 elif what == b'a' or what == b'same':
Matt Mackall
merge: move the bulk of simplemerge into core...
r6002 for i in range(t[1], t[2]):
yield self.a[i]
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 elif what == b'b':
Matt Mackall
merge: move the bulk of simplemerge into core...
r6002 for i in range(t[1], t[2]):
yield self.b[i]
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 elif what == b'conflict':
if localorother == b'local':
Jordi Gutiérrez Hermoso
simplemerge: enable option to resolve conflicts one way...
r26223 for i in range(t[3], t[4]):
yield self.a[i]
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 elif localorother == b'other':
Jordi Gutiérrez Hermoso
simplemerge: enable option to resolve conflicts one way...
r26223 for i in range(t[5], t[6]):
yield self.b[i]
else:
self.conflicts = True
if start_marker is not None:
yield start_marker + newline
for i in range(t[3], t[4]):
yield self.a[i]
if base_marker is not None:
yield base_marker + newline
for i in range(t[1], t[2]):
yield self.base[i]
if mid_marker is not None:
yield mid_marker + newline
for i in range(t[5], t[6]):
yield self.b[i]
if end_marker is not None:
yield end_marker + newline
Matt Mackall
merge: move the bulk of simplemerge into core...
r6002 else:
raise ValueError(what)
def merge_groups(self):
"""Yield sequence of line groups. Each one is a tuple:
'unchanged', lines
Lines unchanged from base
'a', lines
Lines taken from a
'same', lines
Lines taken from a (and equal to b)
'b', lines
Lines taken from b
'conflict', base_lines, a_lines, b_lines
Lines from base were changed to either a or b and conflict.
"""
for t in self.merge_regions():
what = t[0]
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if what == b'unchanged':
Augie Fackler
formatting: blacken the codebase...
r43346 yield what, self.base[t[1] : t[2]]
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 elif what == b'a' or what == b'same':
Augie Fackler
formatting: blacken the codebase...
r43346 yield what, self.a[t[1] : t[2]]
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 elif what == b'b':
Augie Fackler
formatting: blacken the codebase...
r43346 yield what, self.b[t[1] : t[2]]
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 elif what == b'conflict':
Augie Fackler
formatting: blacken the codebase...
r43346 yield (
what,
self.base[t[1] : t[2]],
self.a[t[3] : t[4]],
self.b[t[5] : t[6]],
)
Matt Mackall
merge: move the bulk of simplemerge into core...
r6002 else:
raise ValueError(what)
def merge_regions(self):
"""Return sequences of matching and conflicting regions.
This returns tuples, where the first value says what kind we
have:
'unchanged', start, end
Take a region of base[start:end]
'same', astart, aend
b and a are different from base but give the same result
'a', start, end
Non-clashing insertion from a[start:end]
Ryan McElroy
merge: add some useful documentation
r28070 'conflict', zstart, zend, astart, aend, bstart, bend
Conflict between a and b, with z as common ancestor
Matt Mackall
merge: move the bulk of simplemerge into core...
r6002 Method is as follows:
The two sequences align only on regions which match the base
Matt Mackall
check-code: catch misspellings of descendant...
r14549 and both descendants. These are found by doing a two-way diff
Matt Mackall
merge: move the bulk of simplemerge into core...
r6002 of each one against the base, and then finding the
intersections between those regions. These "sync regions"
are by definition unchanged in both and easily dealt with.
The regions in between can be in any of three cases:
conflicted, or changed on only one side.
"""
# section a[0:ia] has been disposed of, etc
iz = ia = ib = 0
Brodie Rao
cleanup: eradicate long lines
r16683 for region in self.find_sync_regions():
zmatch, zend, amatch, aend, bmatch, bend = region
Augie Fackler
formatting: blacken the codebase...
r43346 # print 'match base [%d:%d]' % (zmatch, zend)
Matt Mackall
merge: move the bulk of simplemerge into core...
r6002
matchlen = zend - zmatch
assert matchlen >= 0
assert matchlen == (aend - amatch)
assert matchlen == (bend - bmatch)
len_a = amatch - ia
len_b = bmatch - ib
len_base = zmatch - iz
assert len_a >= 0
assert len_b >= 0
assert len_base >= 0
Augie Fackler
formatting: blacken the codebase...
r43346 # print 'unmatched a=%d, b=%d' % (len_a, len_b)
Matt Mackall
merge: move the bulk of simplemerge into core...
r6002
if len_a or len_b:
# try to avoid actually slicing the lists
Augie Fackler
formatting: blacken the codebase...
r43346 equal_a = compare_range(
self.a, ia, amatch, self.base, iz, zmatch
)
equal_b = compare_range(
self.b, ib, bmatch, self.base, iz, zmatch
)
same = compare_range(self.a, ia, amatch, self.b, ib, bmatch)
Matt Mackall
merge: move the bulk of simplemerge into core...
r6002
if same:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 yield b'same', ia, amatch
Matt Mackall
merge: move the bulk of simplemerge into core...
r6002 elif equal_a and not equal_b:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 yield b'b', ib, bmatch
Matt Mackall
merge: move the bulk of simplemerge into core...
r6002 elif equal_b and not equal_a:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 yield b'a', ia, amatch
Matt Mackall
merge: move the bulk of simplemerge into core...
r6002 elif not equal_a and not equal_b:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 yield b'conflict', iz, zmatch, ia, amatch, ib, bmatch
Matt Mackall
merge: move the bulk of simplemerge into core...
r6002 else:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 raise AssertionError(b"can't handle a=b=base but unmatched")
Matt Mackall
merge: move the bulk of simplemerge into core...
r6002
ia = amatch
ib = bmatch
iz = zmatch
# if the same part of the base was deleted on both sides
# that's OK, we can just skip it.
if matchlen > 0:
assert ia == amatch
assert ib == bmatch
assert iz == zmatch
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 yield b'unchanged', zmatch, zend
Matt Mackall
merge: move the bulk of simplemerge into core...
r6002 iz = zend
ia = aend
ib = bend
Ryan McElroy
merge: introduce method to minimize merge regions...
r28071 def minimize(self, merge_regions):
"""Trim conflict regions of lines where A and B sides match.
Mads Kiilerich
spelling: fixes of non-dictionary words
r30332 Lines where both A and B have made the same changes at the beginning
Ryan McElroy
merge: introduce method to minimize merge regions...
r28071 or the end of each merge region are eliminated from the conflict
region and are instead considered the same.
"""
for region in merge_regions:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if region[0] != b"conflict":
Ryan McElroy
merge: introduce method to minimize merge regions...
r28071 yield region
continue
Augie Fackler
simplemerge: disable a pytype error where it's just confused...
r43787 # pytype thinks this tuple contains only 3 things, but
# that's clearly not true because this code successfully
# executes. It might be wise to rework merge_regions to be
# some kind of attrs type.
(
issue,
z1,
z2,
a1,
a2,
b1,
b2,
) = region # pytype: disable=bad-unpacking
Ryan McElroy
merge: introduce method to minimize merge regions...
r28071 alen = a2 - a1
blen = b2 - b1
# find matches at the front
ii = 0
Augie Fackler
formatting: blacken the codebase...
r43346 while (
ii < alen and ii < blen and self.a[a1 + ii] == self.b[b1 + ii]
):
Ryan McElroy
merge: introduce method to minimize merge regions...
r28071 ii += 1
startmatches = ii
# find matches at the end
ii = 0
Augie Fackler
formatting: blacken the codebase...
r43346 while (
ii < alen
and ii < blen
and self.a[a2 - ii - 1] == self.b[b2 - ii - 1]
):
Ryan McElroy
merge: introduce method to minimize merge regions...
r28071 ii += 1
endmatches = ii
if startmatches > 0:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 yield b'same', a1, a1 + startmatches
Ryan McElroy
merge: introduce method to minimize merge regions...
r28071
Augie Fackler
formatting: blacken the codebase...
r43346 yield (
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'conflict',
Augie Fackler
formatting: blacken the codebase...
r43346 z1,
z2,
a1 + startmatches,
a2 - endmatches,
b1 + startmatches,
b2 - endmatches,
)
Ryan McElroy
merge: introduce method to minimize merge regions...
r28071
if endmatches > 0:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 yield b'same', a2 - endmatches, a2
Ryan McElroy
merge: introduce method to minimize merge regions...
r28071
Matt Mackall
merge: move the bulk of simplemerge into core...
r6002 def find_sync_regions(self):
Matt Mackall
check-code: catch misspellings of descendant...
r14549 """Return a list of sync regions, where both descendants match the base.
Matt Mackall
merge: move the bulk of simplemerge into core...
r6002
Generates a list of (base1, base2, a1, a2, b1, b2). There is
always a zero-length sync region at the end of all the files.
"""
ia = ib = 0
amatches = mdiff.get_matching_blocks(self.basetext, self.atext)
bmatches = mdiff.get_matching_blocks(self.basetext, self.btext)
len_a = len(amatches)
len_b = len(bmatches)
sl = []
while ia < len_a and ib < len_b:
abase, amatch, alen = amatches[ia]
bbase, bmatch, blen = bmatches[ib]
# there is an unconflicted block at i; how long does it
# extend? until whichever one ends earlier.
Matt Mackall
many, many trivial check-code fixups
r10282 i = intersect((abase, abase + alen), (bbase, bbase + blen))
Matt Mackall
merge: move the bulk of simplemerge into core...
r6002 if i:
intbase = i[0]
intend = i[1]
intlen = intend - intbase
# found a match of base[i[0], i[1]]; this may be less than
# the region that matches in either one
assert intlen <= alen
assert intlen <= blen
assert abase <= intbase
assert bbase <= intbase
asub = amatch + (intbase - abase)
bsub = bmatch + (intbase - bbase)
aend = asub + intlen
bend = bsub + intlen
Augie Fackler
cleanup: use () to wrap long lines instead of \...
r41925 assert self.base[intbase:intend] == self.a[asub:aend], (
Augie Fackler
formatting: blacken the codebase...
r43346 self.base[intbase:intend],
self.a[asub:aend],
)
Matt Mackall
merge: move the bulk of simplemerge into core...
r6002
assert self.base[intbase:intend] == self.b[bsub:bend]
Augie Fackler
formatting: blacken the codebase...
r43346 sl.append((intbase, intend, asub, aend, bsub, bend))
Matt Mackall
merge: move the bulk of simplemerge into core...
r6002
# advance whichever one ends first in the base text
if (abase + alen) < (bbase + blen):
ia += 1
else:
ib += 1
intbase = len(self.base)
abase = len(self.a)
bbase = len(self.b)
sl.append((intbase, intbase, abase, abase, bbase, bbase))
return sl
Augie Fackler
formatting: blacken the codebase...
r43346
Phil Cohen
simplemerge: extract verifytext as a helper function...
r33824 def _verifytext(text, path, ui, opts):
"""verifies that text is non-binary (unless opts[text] is passed,
then we just warn)"""
Yuya Nishihara
stringutil: bulk-replace call sites to point to new module...
r37102 if stringutil.binary(text):
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 msg = _(b"%s looks like a binary file.") % path
Martin von Zweigbergk
simplemerge: work with opts as native strings instead of bytes...
r46714 if not opts.get('quiet'):
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ui.warn(_(b'warning: %s\n') % msg)
Martin von Zweigbergk
simplemerge: work with opts as native strings instead of bytes...
r46714 if not opts.get('text'):
Phil Cohen
simplemerge: extract verifytext as a helper function...
r33824 raise error.Abort(msg)
return text
Augie Fackler
formatting: blacken the codebase...
r43346
Phil Cohen
filemerge: extract `_picklabels` as a helper function...
r33829 def _picklabels(defaults, overrides):
if len(overrides) > 3:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 raise error.Abort(_(b"can only specify three labels."))
Phil Cohen
simplemerge: refactor _picklabels to be more compact...
r33934 result = defaults[:]
for i, override in enumerate(overrides):
result[i] = override
return result
Phil Cohen
filemerge: extract `_picklabels` as a helper function...
r33829
Augie Fackler
formatting: blacken the codebase...
r43346
Yuya Nishihara
simplemerge: fix function name that tests if ctx is not null revision
r45473 def is_not_null(ctx):
flags: actually merge flags in simplemerge...
r45398 if not util.safehasattr(ctx, "node"):
return False
Joerg Sonnenberger
node: import symbols explicitly...
r46729 return ctx.node() != nullid
flags: actually merge flags in simplemerge...
r45398
Martin von Zweigbergk
mergetools: add new conflict marker format with diffs in...
r46724 def _mergediff(m3, name_a, name_b, name_base):
lines = []
conflicts = False
for group in m3.merge_groups():
if group[0] == b'conflict':
base_lines, a_lines, b_lines = group[1:]
base_text = b''.join(base_lines)
b_blocks = list(
mdiff.allblocks(
base_text,
b''.join(b_lines),
lines1=base_lines,
lines2=b_lines,
)
)
a_blocks = list(
mdiff.allblocks(
base_text,
b''.join(a_lines),
lines1=base_lines,
lines2=b_lines,
)
)
def matching_lines(blocks):
return sum(
block[1] - block[0]
for block, kind in blocks
if kind == b'='
)
def diff_lines(blocks, lines1, lines2):
for block, kind in blocks:
if kind == b'=':
for line in lines1[block[0] : block[1]]:
yield b' ' + line
else:
for line in lines1[block[0] : block[1]]:
yield b'-' + line
for line in lines2[block[2] : block[3]]:
yield b'+' + line
lines.append(b"<<<<<<<\n")
if matching_lines(a_blocks) < matching_lines(b_blocks):
lines.append(b"======= %s\n" % name_a)
lines.extend(a_lines)
lines.append(b"------- %s\n" % name_base)
lines.append(b"+++++++ %s\n" % name_b)
lines.extend(diff_lines(b_blocks, base_lines, b_lines))
else:
lines.append(b"------- %s\n" % name_base)
lines.append(b"+++++++ %s\n" % name_a)
lines.extend(diff_lines(a_blocks, base_lines, a_lines))
lines.append(b"======= %s\n" % name_b)
lines.extend(b_lines)
lines.append(b">>>>>>>\n")
conflicts = True
else:
lines.extend(group[1])
return lines, conflicts
Phil Cohen
simplemerge: remove unused `repo` parameter...
r34051 def simplemerge(ui, localctx, basectx, otherctx, **opts):
Phil Cohen
simplemerge: use contexts to read file data from, if passed...
r33827 """Performs the simplemerge algorithm.
Phil Cohen
simplemerge: make context parameters non-optional...
r33908 The merged result is written into `localctx`.
Phil Cohen
simplemerge: stop reading from, and writing to, files...
r33906 """
Pulkit Goyal
py3: handle keyword arguments correctly in simplemerge.py...
r35369
Phil Cohen
simplemerge: use contexts to read file data from, if passed...
r33827 def readctx(ctx):
Phil Cohen
simplemerge: use `ctx.decoddeddata()` instead of `repo.wreaddata`...
r33903 # Merges were always run in the working copy before, which means
# they used decoded data, if the user defined any repository
# filters.
#
# Maintain that behavior today for BC, though perhaps in the future
# it'd be worth considering whether merging encoded data (what the
# repository usually sees) might be more useful.
return _verifytext(ctx.decodeddata(), ctx.path(), ui, opts)
Phil Cohen
simplemerge: use contexts to read file data from, if passed...
r33827
Martin von Zweigbergk
simplemerge: work with opts as native strings instead of bytes...
r46714 mode = opts.get('mode', b'merge')
Phil Cohen
filemerge: extract `_picklabels` as a helper function...
r33829 name_a, name_b, name_base = None, None, None
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if mode != b'union':
Augie Fackler
formatting: blacken the codebase...
r43346 name_a, name_b, name_base = _picklabels(
Martin von Zweigbergk
simplemerge: work with opts as native strings instead of bytes...
r46714 [localctx.path(), otherctx.path(), None], opts.get('label', [])
Augie Fackler
formatting: blacken the codebase...
r43346 )
Matt Mackall
merge: move the bulk of simplemerge into core...
r6002
Steve Borho
simplemerge: do not allow binary files to abort an entire merge...
r14328 try:
Phil Cohen
simplemerge: stop reading from, and writing to, files...
r33906 localtext = readctx(localctx)
basetext = readctx(basectx)
othertext = readctx(otherctx)
Pierre-Yves David
error: get Abort from 'error' instead of 'util'...
r26587 except error.Abort:
Steve Borho
simplemerge: do not allow binary files to abort an entire merge...
r14328 return 1
Matt Mackall
merge: move the bulk of simplemerge into core...
r6002
m3 = Merge3Text(basetext, localtext, othertext)
Ryan McElroy
merge: minimize conflicts when common base is not shown (issue4447)...
r28072 extrakwargs = {
Martin von Zweigbergk
simplemerge: work with opts as native strings instead of bytes...
r46714 b"localorother": opts.get("localorother", None),
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'minimize': True,
Augie Fackler
formatting: blacken the codebase...
r43346 }
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if mode == b'union':
extrakwargs[b'start_marker'] = None
extrakwargs[b'mid_marker'] = None
extrakwargs[b'end_marker'] = None
Erik Huelsmann
simplemerge: add 'mode' kwarg which - when 'union' - suppresses markers...
r26069 elif name_base is not None:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 extrakwargs[b'base_marker'] = b'|||||||'
extrakwargs[b'name_base'] = name_base
extrakwargs[b'minimize'] = False
Phil Cohen
simplemerge: simplify code now that we always write to a context...
r33909
Martin von Zweigbergk
mergetools: add new conflict marker format with diffs in...
r46724 if mode == b'mergediff':
lines, conflicts = _mergediff(m3, name_a, name_b, name_base)
else:
lines = list(
m3.merge_lines(
name_a=name_a, name_b=name_b, **pycompat.strkwargs(extrakwargs)
)
)
conflicts = m3.conflicts
Matt Mackall
merge: move the bulk of simplemerge into core...
r6002
flags: actually merge flags in simplemerge...
r45398 # merge flags if necessary
flags = localctx.flags()
Yuya Nishihara
simplemerge: leverage pycompat function to convert byte string to set
r45474 localflags = set(pycompat.iterbytestr(flags))
otherflags = set(pycompat.iterbytestr(otherctx.flags()))
Yuya Nishihara
simplemerge: fix function name that tests if ctx is not null revision
r45473 if is_not_null(basectx) and localflags != otherflags:
Yuya Nishihara
simplemerge: leverage pycompat function to convert byte string to set
r45474 baseflags = set(pycompat.iterbytestr(basectx.flags()))
Yuya Nishihara
simplemerge: rewrite flag merging loop as expression...
r45475 commonflags = localflags & otherflags
addedflags = (localflags ^ otherflags) - baseflags
flags = b''.join(sorted(commonflags | addedflags))
flags: actually merge flags in simplemerge...
r45398
Martin von Zweigbergk
simplemerge: write output only once it's complete...
r46716 mergedtext = b''.join(lines)
if opts.get('print'):
ui.fout.write(mergedtext)
else:
flags: actually merge flags in simplemerge...
r45398 localctx.write(mergedtext, flags)
Matt Mackall
merge: move the bulk of simplemerge into core...
r6002
Martin von Zweigbergk
mergetools: add new conflict marker format with diffs in...
r46724 if conflicts and not mode == b'union':
Matt Mackall
merge: move the bulk of simplemerge into core...
r6002 return 1