annotate mercurial/simplemerge.py @ 48514:fb691fa90807

simplemerge: add a specialized function for "union", "local", "other" Differential Revision: https://phab.mercurial-scm.org/D11901
author Martin von Zweigbergk <martinvonz@google.com>
date Tue, 07 Dec 2021 22:33:18 -0800
parents 5151b0f6519e
children bd27dad294b7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4362
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
1 # Copyright (C) 2004, 2005 Canonical Ltd
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
2 #
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
3 # This program is free software; you can redistribute it and/or modify
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
4 # it under the terms of the GNU General Public License as published by
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
5 # the Free Software Foundation; either version 2 of the License, or
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
6 # (at your option) any later version.
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
7 #
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
8 # This program is distributed in the hope that it will be useful,
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
11 # GNU General Public License for more details.
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
12 #
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
13 # You should have received a copy of the GNU General Public License
15782
7de7630053cb Remove FSF mailing address from GPL headers
Martin Geisler <mg@aragost.com>
parents: 15381
diff changeset
14 # along with this program; if not, see <http://www.gnu.org/licenses/>.
4362
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
15
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
16 # mbp: "you know that thing where cvs gives you conflict markers?"
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
17 # s: "i hate that."
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
18
25974
241a1324a180 simplemerge: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 22056
diff changeset
19 from __future__ import absolute_import
241a1324a180 simplemerge: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 22056
diff changeset
20
241a1324a180 simplemerge: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 22056
diff changeset
21 from .i18n import _
241a1324a180 simplemerge: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 22056
diff changeset
22 from . import (
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26223
diff changeset
23 error,
25974
241a1324a180 simplemerge: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 22056
diff changeset
24 mdiff,
33017
c31d45623304 py3: convert kwargs' keys' to str using pycompat.strkwargs()
Pulkit Goyal <7895pulkit@gmail.com>
parents: 31238
diff changeset
25 pycompat,
37084
f0b6fbea00cf stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents: 35368
diff changeset
26 )
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
27 from .utils import stringutil
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
28
4363
2e3c54fb79a3 actually port simplemerge to hg
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4362
diff changeset
29
2e3c54fb79a3 actually port simplemerge to hg
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4362
diff changeset
30 class CantReprocessAndShowBase(Exception):
2e3c54fb79a3 actually port simplemerge to hg
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4362
diff changeset
31 pass
5081
ea7b982b6c08 Remove trailing spaces
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4408
diff changeset
32
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
33
4362
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
34 def intersect(ra, rb):
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
35 """Given two ranges return the range where they intersect or None.
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
36
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
37 >>> intersect((0, 10), (0, 6))
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
38 (0, 6)
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
39 >>> intersect((0, 10), (5, 15))
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
40 (5, 10)
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
41 >>> intersect((0, 10), (10, 15))
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
42 >>> intersect((0, 9), (10, 15))
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
43 >>> intersect((0, 9), (7, 15))
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
44 (7, 9)
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
45 """
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
46 assert ra[0] <= ra[1]
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
47 assert rb[0] <= rb[1]
5081
ea7b982b6c08 Remove trailing spaces
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4408
diff changeset
48
4362
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
49 sa = max(ra[0], rb[0])
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
50 sb = min(ra[1], rb[1])
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
51 if sa < sb:
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
52 return sa, sb
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
53 else:
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
54 return None
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
55
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
56
4362
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
57 def compare_range(a, astart, aend, b, bstart, bend):
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 44949
diff changeset
58 """Compare a[astart:aend] == b[bstart:bend], without slicing."""
10282
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 8312
diff changeset
59 if (aend - astart) != (bend - bstart):
4362
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
60 return False
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
61 for ia, ib in zip(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
62 pycompat.xrange(astart, aend), pycompat.xrange(bstart, bend)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
63 ):
4362
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
64 if a[ia] != b[ib]:
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
65 return False
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
66 else:
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
67 return True
5081
ea7b982b6c08 Remove trailing spaces
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4408
diff changeset
68
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
69
4363
2e3c54fb79a3 actually port simplemerge to hg
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4362
diff changeset
70 class Merge3Text(object):
4362
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
71 """3-way merge of texts.
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
72
4363
2e3c54fb79a3 actually port simplemerge to hg
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4362
diff changeset
73 Given strings BASE, OTHER, THIS, tries to produce a combined text
2e3c54fb79a3 actually port simplemerge to hg
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4362
diff changeset
74 incorporating the changes from both BASE->OTHER and BASE->THIS."""
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
75
4363
2e3c54fb79a3 actually port simplemerge to hg
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4362
diff changeset
76 def __init__(self, basetext, atext, btext, base=None, a=None, b=None):
2e3c54fb79a3 actually port simplemerge to hg
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4362
diff changeset
77 self.basetext = basetext
2e3c54fb79a3 actually port simplemerge to hg
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4362
diff changeset
78 self.atext = atext
2e3c54fb79a3 actually port simplemerge to hg
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4362
diff changeset
79 self.btext = btext
2e3c54fb79a3 actually port simplemerge to hg
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4362
diff changeset
80 if base is None:
2e3c54fb79a3 actually port simplemerge to hg
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4362
diff changeset
81 base = mdiff.splitnewlines(basetext)
2e3c54fb79a3 actually port simplemerge to hg
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4362
diff changeset
82 if a is None:
2e3c54fb79a3 actually port simplemerge to hg
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4362
diff changeset
83 a = mdiff.splitnewlines(atext)
2e3c54fb79a3 actually port simplemerge to hg
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4362
diff changeset
84 if b is None:
2e3c54fb79a3 actually port simplemerge to hg
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4362
diff changeset
85 b = mdiff.splitnewlines(btext)
4362
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
86 self.base = base
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
87 self.a = a
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
88 self.b = b
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
89
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
90 def merge_lines(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
91 self,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
92 name_a=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
93 name_b=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
94 name_base=None,
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
95 start_marker=b'<<<<<<<',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
96 mid_marker=b'=======',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
97 end_marker=b'>>>>>>>',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
98 base_marker=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
99 localorother=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
100 minimize=False,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
101 ):
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 44949
diff changeset
102 """Return merge in cvs-like form."""
4364
d5c3a70f8422 polish the simplemerge command; add a test
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4363
diff changeset
103 self.conflicts = False
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
104 newline = b'\n'
4362
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
105 if len(self.a) > 0:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
106 if self.a[0].endswith(b'\r\n'):
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
107 newline = b'\r\n'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
108 elif self.a[0].endswith(b'\r'):
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
109 newline = b'\r'
26069
09d6725cbc60 simplemerge: add 'mode' kwarg which - when 'union' - suppresses markers
Erik Huelsmann <ehuels@gmail.com>
parents: 25974
diff changeset
110 if name_a and start_marker:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
111 start_marker = start_marker + b' ' + name_a
26069
09d6725cbc60 simplemerge: add 'mode' kwarg which - when 'union' - suppresses markers
Erik Huelsmann <ehuels@gmail.com>
parents: 25974
diff changeset
112 if name_b and end_marker:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
113 end_marker = end_marker + b' ' + name_b
4362
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
114 if name_base and base_marker:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
115 base_marker = base_marker + b' ' + name_base
4362
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
116 merge_regions = self.merge_regions()
28072
c3e9269d9602 merge: minimize conflicts when common base is not shown (issue4447)
Ryan McElroy <rmcelroy@fb.com>
parents: 28071
diff changeset
117 if minimize:
c3e9269d9602 merge: minimize conflicts when common base is not shown (issue4447)
Ryan McElroy <rmcelroy@fb.com>
parents: 28071
diff changeset
118 merge_regions = self.minimize(merge_regions)
4362
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
119 for t in merge_regions:
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
120 what = t[0]
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
121 if what == b'unchanged':
4362
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
122 for i in range(t[1], t[2]):
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
123 yield self.base[i]
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
124 elif what == b'a' or what == b'same':
4362
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
125 for i in range(t[1], t[2]):
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
126 yield self.a[i]
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
127 elif what == b'b':
4362
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
128 for i in range(t[1], t[2]):
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
129 yield self.b[i]
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
130 elif what == b'conflict':
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
131 if localorother == b'local':
26223
ed12abab068e simplemerge: enable option to resolve conflicts one way
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 26069
diff changeset
132 for i in range(t[3], t[4]):
ed12abab068e simplemerge: enable option to resolve conflicts one way
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 26069
diff changeset
133 yield self.a[i]
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
134 elif localorother == b'other':
26223
ed12abab068e simplemerge: enable option to resolve conflicts one way
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 26069
diff changeset
135 for i in range(t[5], t[6]):
ed12abab068e simplemerge: enable option to resolve conflicts one way
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 26069
diff changeset
136 yield self.b[i]
ed12abab068e simplemerge: enable option to resolve conflicts one way
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 26069
diff changeset
137 else:
ed12abab068e simplemerge: enable option to resolve conflicts one way
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 26069
diff changeset
138 self.conflicts = True
ed12abab068e simplemerge: enable option to resolve conflicts one way
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 26069
diff changeset
139 if start_marker is not None:
ed12abab068e simplemerge: enable option to resolve conflicts one way
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 26069
diff changeset
140 yield start_marker + newline
ed12abab068e simplemerge: enable option to resolve conflicts one way
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 26069
diff changeset
141 for i in range(t[3], t[4]):
ed12abab068e simplemerge: enable option to resolve conflicts one way
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 26069
diff changeset
142 yield self.a[i]
ed12abab068e simplemerge: enable option to resolve conflicts one way
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 26069
diff changeset
143 if base_marker is not None:
ed12abab068e simplemerge: enable option to resolve conflicts one way
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 26069
diff changeset
144 yield base_marker + newline
ed12abab068e simplemerge: enable option to resolve conflicts one way
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 26069
diff changeset
145 for i in range(t[1], t[2]):
ed12abab068e simplemerge: enable option to resolve conflicts one way
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 26069
diff changeset
146 yield self.base[i]
ed12abab068e simplemerge: enable option to resolve conflicts one way
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 26069
diff changeset
147 if mid_marker is not None:
ed12abab068e simplemerge: enable option to resolve conflicts one way
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 26069
diff changeset
148 yield mid_marker + newline
ed12abab068e simplemerge: enable option to resolve conflicts one way
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 26069
diff changeset
149 for i in range(t[5], t[6]):
ed12abab068e simplemerge: enable option to resolve conflicts one way
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 26069
diff changeset
150 yield self.b[i]
ed12abab068e simplemerge: enable option to resolve conflicts one way
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 26069
diff changeset
151 if end_marker is not None:
ed12abab068e simplemerge: enable option to resolve conflicts one way
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 26069
diff changeset
152 yield end_marker + newline
4362
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
153 else:
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
154 raise ValueError(what)
5081
ea7b982b6c08 Remove trailing spaces
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4408
diff changeset
155
4362
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
156 def merge_groups(self):
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
157 """Yield sequence of line groups. Each one is a tuple:
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
158
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
159 'unchanged', lines
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
160 Lines unchanged from base
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
161
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
162 'a', lines
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
163 Lines taken from a
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
164
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
165 'same', lines
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
166 Lines taken from a (and equal to b)
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
167
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
168 'b', lines
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
169 Lines taken from b
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
170
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
171 'conflict', base_lines, a_lines, b_lines
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
172 Lines from base were changed to either a or b and conflict.
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
173 """
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
174 for t in self.merge_regions():
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
175 what = t[0]
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
176 if what == b'unchanged':
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
177 yield what, self.base[t[1] : t[2]]
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
178 elif what == b'a' or what == b'same':
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
179 yield what, self.a[t[1] : t[2]]
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
180 elif what == b'b':
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
181 yield what, self.b[t[1] : t[2]]
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
182 elif what == b'conflict':
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
183 yield (
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
184 what,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
185 self.base[t[1] : t[2]],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
186 self.a[t[3] : t[4]],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
187 self.b[t[5] : t[6]],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
188 )
4362
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
189 else:
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
190 raise ValueError(what)
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
191
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
192 def merge_regions(self):
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
193 """Return sequences of matching and conflicting regions.
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
194
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
195 This returns tuples, where the first value says what kind we
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
196 have:
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
197
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
198 'unchanged', start, end
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
199 Take a region of base[start:end]
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
200
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
201 'same', astart, aend
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
202 b and a are different from base but give the same result
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
203
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
204 'a', start, end
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
205 Non-clashing insertion from a[start:end]
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
206
28070
a504794cee29 merge: add some useful documentation
Ryan McElroy <rmcelroy@fb.com>
parents: 26614
diff changeset
207 'conflict', zstart, zend, astart, aend, bstart, bend
a504794cee29 merge: add some useful documentation
Ryan McElroy <rmcelroy@fb.com>
parents: 26614
diff changeset
208 Conflict between a and b, with z as common ancestor
a504794cee29 merge: add some useful documentation
Ryan McElroy <rmcelroy@fb.com>
parents: 26614
diff changeset
209
4362
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
210 Method is as follows:
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
211
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
212 The two sequences align only on regions which match the base
14549
48ec0763afbb check-code: catch misspellings of descendant
Matt Mackall <mpm@selenic.com>
parents: 14329
diff changeset
213 and both descendants. These are found by doing a two-way diff
4362
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
214 of each one against the base, and then finding the
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
215 intersections between those regions. These "sync regions"
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
216 are by definition unchanged in both and easily dealt with.
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
217
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
218 The regions in between can be in any of three cases:
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
219 conflicted, or changed on only one side.
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
220 """
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
221
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
222 # section a[0:ia] has been disposed of, etc
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
223 iz = ia = ib = 0
5081
ea7b982b6c08 Remove trailing spaces
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4408
diff changeset
224
16683
525fdb738975 cleanup: eradicate long lines
Brodie Rao <brodie@sf.io>
parents: 15782
diff changeset
225 for region in self.find_sync_regions():
525fdb738975 cleanup: eradicate long lines
Brodie Rao <brodie@sf.io>
parents: 15782
diff changeset
226 zmatch, zend, amatch, aend, bmatch, bend = region
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
227 # print 'match base [%d:%d]' % (zmatch, zend)
5081
ea7b982b6c08 Remove trailing spaces
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4408
diff changeset
228
4362
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
229 matchlen = zend - zmatch
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
230 assert matchlen >= 0
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
231 assert matchlen == (aend - amatch)
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
232 assert matchlen == (bend - bmatch)
5081
ea7b982b6c08 Remove trailing spaces
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4408
diff changeset
233
4362
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
234 len_a = amatch - ia
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
235 len_b = bmatch - ib
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
236 len_base = zmatch - iz
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
237 assert len_a >= 0
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
238 assert len_b >= 0
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
239 assert len_base >= 0
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
240
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
241 # print 'unmatched a=%d, b=%d' % (len_a, len_b)
4362
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
242
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
243 if len_a or len_b:
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
244 # try to avoid actually slicing the lists
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
245 equal_a = compare_range(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
246 self.a, ia, amatch, self.base, iz, zmatch
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
247 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
248 equal_b = compare_range(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
249 self.b, ib, bmatch, self.base, iz, zmatch
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
250 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
251 same = compare_range(self.a, ia, amatch, self.b, ib, bmatch)
4362
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
252
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
253 if same:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
254 yield b'same', ia, amatch
4362
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
255 elif equal_a and not equal_b:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
256 yield b'b', ib, bmatch
4362
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
257 elif equal_b and not equal_a:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
258 yield b'a', ia, amatch
4362
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
259 elif not equal_a and not equal_b:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
260 yield b'conflict', iz, zmatch, ia, amatch, ib, bmatch
4362
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
261 else:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
262 raise AssertionError(b"can't handle a=b=base but unmatched")
4362
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
263
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
264 ia = amatch
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
265 ib = bmatch
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
266 iz = zmatch
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
267
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
268 # if the same part of the base was deleted on both sides
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
269 # that's OK, we can just skip it.
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
270
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
271 if matchlen > 0:
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
272 assert ia == amatch
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
273 assert ib == bmatch
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
274 assert iz == zmatch
5081
ea7b982b6c08 Remove trailing spaces
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4408
diff changeset
275
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
276 yield b'unchanged', zmatch, zend
4362
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
277 iz = zend
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
278 ia = aend
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
279 ib = bend
5081
ea7b982b6c08 Remove trailing spaces
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4408
diff changeset
280
28071
261324dd5f5b merge: introduce method to minimize merge regions
Ryan McElroy <rmcelroy@fb.com>
parents: 28070
diff changeset
281 def minimize(self, merge_regions):
261324dd5f5b merge: introduce method to minimize merge regions
Ryan McElroy <rmcelroy@fb.com>
parents: 28070
diff changeset
282 """Trim conflict regions of lines where A and B sides match.
261324dd5f5b merge: introduce method to minimize merge regions
Ryan McElroy <rmcelroy@fb.com>
parents: 28070
diff changeset
283
30332
318a24b52eeb spelling: fixes of non-dictionary words
Mads Kiilerich <madski@unity3d.com>
parents: 30323
diff changeset
284 Lines where both A and B have made the same changes at the beginning
28071
261324dd5f5b merge: introduce method to minimize merge regions
Ryan McElroy <rmcelroy@fb.com>
parents: 28070
diff changeset
285 or the end of each merge region are eliminated from the conflict
261324dd5f5b merge: introduce method to minimize merge regions
Ryan McElroy <rmcelroy@fb.com>
parents: 28070
diff changeset
286 region and are instead considered the same.
261324dd5f5b merge: introduce method to minimize merge regions
Ryan McElroy <rmcelroy@fb.com>
parents: 28070
diff changeset
287 """
261324dd5f5b merge: introduce method to minimize merge regions
Ryan McElroy <rmcelroy@fb.com>
parents: 28070
diff changeset
288 for region in merge_regions:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
289 if region[0] != b"conflict":
28071
261324dd5f5b merge: introduce method to minimize merge regions
Ryan McElroy <rmcelroy@fb.com>
parents: 28070
diff changeset
290 yield region
261324dd5f5b merge: introduce method to minimize merge regions
Ryan McElroy <rmcelroy@fb.com>
parents: 28070
diff changeset
291 continue
43486
3b581ad59459 simplemerge: disable a pytype error where it's just confused
Augie Fackler <augie@google.com>
parents: 43077
diff changeset
292 # pytype thinks this tuple contains only 3 things, but
3b581ad59459 simplemerge: disable a pytype error where it's just confused
Augie Fackler <augie@google.com>
parents: 43077
diff changeset
293 # that's clearly not true because this code successfully
3b581ad59459 simplemerge: disable a pytype error where it's just confused
Augie Fackler <augie@google.com>
parents: 43077
diff changeset
294 # executes. It might be wise to rework merge_regions to be
3b581ad59459 simplemerge: disable a pytype error where it's just confused
Augie Fackler <augie@google.com>
parents: 43077
diff changeset
295 # some kind of attrs type.
3b581ad59459 simplemerge: disable a pytype error where it's just confused
Augie Fackler <augie@google.com>
parents: 43077
diff changeset
296 (
3b581ad59459 simplemerge: disable a pytype error where it's just confused
Augie Fackler <augie@google.com>
parents: 43077
diff changeset
297 issue,
3b581ad59459 simplemerge: disable a pytype error where it's just confused
Augie Fackler <augie@google.com>
parents: 43077
diff changeset
298 z1,
3b581ad59459 simplemerge: disable a pytype error where it's just confused
Augie Fackler <augie@google.com>
parents: 43077
diff changeset
299 z2,
3b581ad59459 simplemerge: disable a pytype error where it's just confused
Augie Fackler <augie@google.com>
parents: 43077
diff changeset
300 a1,
3b581ad59459 simplemerge: disable a pytype error where it's just confused
Augie Fackler <augie@google.com>
parents: 43077
diff changeset
301 a2,
3b581ad59459 simplemerge: disable a pytype error where it's just confused
Augie Fackler <augie@google.com>
parents: 43077
diff changeset
302 b1,
3b581ad59459 simplemerge: disable a pytype error where it's just confused
Augie Fackler <augie@google.com>
parents: 43077
diff changeset
303 b2,
3b581ad59459 simplemerge: disable a pytype error where it's just confused
Augie Fackler <augie@google.com>
parents: 43077
diff changeset
304 ) = region # pytype: disable=bad-unpacking
28071
261324dd5f5b merge: introduce method to minimize merge regions
Ryan McElroy <rmcelroy@fb.com>
parents: 28070
diff changeset
305 alen = a2 - a1
261324dd5f5b merge: introduce method to minimize merge regions
Ryan McElroy <rmcelroy@fb.com>
parents: 28070
diff changeset
306 blen = b2 - b1
261324dd5f5b merge: introduce method to minimize merge regions
Ryan McElroy <rmcelroy@fb.com>
parents: 28070
diff changeset
307
261324dd5f5b merge: introduce method to minimize merge regions
Ryan McElroy <rmcelroy@fb.com>
parents: 28070
diff changeset
308 # find matches at the front
261324dd5f5b merge: introduce method to minimize merge regions
Ryan McElroy <rmcelroy@fb.com>
parents: 28070
diff changeset
309 ii = 0
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
310 while (
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
311 ii < alen and ii < blen and self.a[a1 + ii] == self.b[b1 + ii]
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
312 ):
28071
261324dd5f5b merge: introduce method to minimize merge regions
Ryan McElroy <rmcelroy@fb.com>
parents: 28070
diff changeset
313 ii += 1
261324dd5f5b merge: introduce method to minimize merge regions
Ryan McElroy <rmcelroy@fb.com>
parents: 28070
diff changeset
314 startmatches = ii
261324dd5f5b merge: introduce method to minimize merge regions
Ryan McElroy <rmcelroy@fb.com>
parents: 28070
diff changeset
315
261324dd5f5b merge: introduce method to minimize merge regions
Ryan McElroy <rmcelroy@fb.com>
parents: 28070
diff changeset
316 # find matches at the end
261324dd5f5b merge: introduce method to minimize merge regions
Ryan McElroy <rmcelroy@fb.com>
parents: 28070
diff changeset
317 ii = 0
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
318 while (
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
319 ii < alen
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
320 and ii < blen
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
321 and self.a[a2 - ii - 1] == self.b[b2 - ii - 1]
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
322 ):
28071
261324dd5f5b merge: introduce method to minimize merge regions
Ryan McElroy <rmcelroy@fb.com>
parents: 28070
diff changeset
323 ii += 1
261324dd5f5b merge: introduce method to minimize merge regions
Ryan McElroy <rmcelroy@fb.com>
parents: 28070
diff changeset
324 endmatches = ii
261324dd5f5b merge: introduce method to minimize merge regions
Ryan McElroy <rmcelroy@fb.com>
parents: 28070
diff changeset
325
261324dd5f5b merge: introduce method to minimize merge regions
Ryan McElroy <rmcelroy@fb.com>
parents: 28070
diff changeset
326 if startmatches > 0:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
327 yield b'same', a1, a1 + startmatches
28071
261324dd5f5b merge: introduce method to minimize merge regions
Ryan McElroy <rmcelroy@fb.com>
parents: 28070
diff changeset
328
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
329 yield (
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
330 b'conflict',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
331 z1,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
332 z2,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
333 a1 + startmatches,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
334 a2 - endmatches,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
335 b1 + startmatches,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
336 b2 - endmatches,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
337 )
28071
261324dd5f5b merge: introduce method to minimize merge regions
Ryan McElroy <rmcelroy@fb.com>
parents: 28070
diff changeset
338
261324dd5f5b merge: introduce method to minimize merge regions
Ryan McElroy <rmcelroy@fb.com>
parents: 28070
diff changeset
339 if endmatches > 0:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
340 yield b'same', a2 - endmatches, a2
28071
261324dd5f5b merge: introduce method to minimize merge regions
Ryan McElroy <rmcelroy@fb.com>
parents: 28070
diff changeset
341
4362
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
342 def find_sync_regions(self):
14549
48ec0763afbb check-code: catch misspellings of descendant
Matt Mackall <mpm@selenic.com>
parents: 14329
diff changeset
343 """Return a list of sync regions, where both descendants match the base.
4362
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
344
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
345 Generates a list of (base1, base2, a1, a2, b1, b2). There is
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
346 always a zero-length sync region at the end of all the files.
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
347 """
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
348
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
349 ia = ib = 0
4363
2e3c54fb79a3 actually port simplemerge to hg
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4362
diff changeset
350 amatches = mdiff.get_matching_blocks(self.basetext, self.atext)
2e3c54fb79a3 actually port simplemerge to hg
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4362
diff changeset
351 bmatches = mdiff.get_matching_blocks(self.basetext, self.btext)
4362
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
352 len_a = len(amatches)
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
353 len_b = len(bmatches)
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
354
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
355 sl = []
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
356
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
357 while ia < len_a and ib < len_b:
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
358 abase, amatch, alen = amatches[ia]
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
359 bbase, bmatch, blen = bmatches[ib]
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
360
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
361 # there is an unconflicted block at i; how long does it
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
362 # extend? until whichever one ends earlier.
10282
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 8312
diff changeset
363 i = intersect((abase, abase + alen), (bbase, bbase + blen))
4362
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
364 if i:
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
365 intbase = i[0]
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
366 intend = i[1]
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
367 intlen = intend - intbase
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
368
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
369 # found a match of base[i[0], i[1]]; this may be less than
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
370 # the region that matches in either one
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
371 assert intlen <= alen
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
372 assert intlen <= blen
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
373 assert abase <= intbase
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
374 assert bbase <= intbase
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
375
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
376 asub = amatch + (intbase - abase)
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
377 bsub = bmatch + (intbase - bbase)
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
378 aend = asub + intlen
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
379 bend = bsub + intlen
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
380
41759
aaad36b88298 cleanup: use () to wrap long lines instead of \
Augie Fackler <augie@google.com>
parents: 38783
diff changeset
381 assert self.base[intbase:intend] == self.a[asub:aend], (
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
382 self.base[intbase:intend],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
383 self.a[asub:aend],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
384 )
4362
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
385
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
386 assert self.base[intbase:intend] == self.b[bsub:bend]
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
387
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
388 sl.append((intbase, intend, asub, aend, bsub, bend))
4362
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
389
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
390 # advance whichever one ends first in the base text
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
391 if (abase + alen) < (bbase + blen):
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
392 ia += 1
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
393 else:
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
394 ib += 1
5081
ea7b982b6c08 Remove trailing spaces
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4408
diff changeset
395
4362
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
396 intbase = len(self.base)
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
397 abase = len(self.a)
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
398 bbase = len(self.b)
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
399 sl.append((intbase, intbase, abase, abase, bbase, bbase))
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
400
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
401 return sl
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
402
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
403
33825
de573184686e simplemerge: extract verifytext as a helper function
Phil Cohen <phillco@fb.com>
parents: 33017
diff changeset
404 def _verifytext(text, path, ui, opts):
de573184686e simplemerge: extract verifytext as a helper function
Phil Cohen <phillco@fb.com>
parents: 33017
diff changeset
405 """verifies that text is non-binary (unless opts[text] is passed,
de573184686e simplemerge: extract verifytext as a helper function
Phil Cohen <phillco@fb.com>
parents: 33017
diff changeset
406 then we just warn)"""
37084
f0b6fbea00cf stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents: 35368
diff changeset
407 if stringutil.binary(text):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
408 msg = _(b"%s looks like a binary file.") % path
46098
5510e2ac213f simplemerge: work with opts as native strings instead of bytes
Martin von Zweigbergk <martinvonz@google.com>
parents: 45942
diff changeset
409 if not opts.get('quiet'):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
410 ui.warn(_(b'warning: %s\n') % msg)
46098
5510e2ac213f simplemerge: work with opts as native strings instead of bytes
Martin von Zweigbergk <martinvonz@google.com>
parents: 45942
diff changeset
411 if not opts.get('text'):
33825
de573184686e simplemerge: extract verifytext as a helper function
Phil Cohen <phillco@fb.com>
parents: 33017
diff changeset
412 raise error.Abort(msg)
de573184686e simplemerge: extract verifytext as a helper function
Phil Cohen <phillco@fb.com>
parents: 33017
diff changeset
413 return text
de573184686e simplemerge: extract verifytext as a helper function
Phil Cohen <phillco@fb.com>
parents: 33017
diff changeset
414
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
415
33830
aa6c290a77fa filemerge: extract `_picklabels` as a helper function
Phil Cohen <phillco@fb.com>
parents: 33829
diff changeset
416 def _picklabels(defaults, overrides):
aa6c290a77fa filemerge: extract `_picklabels` as a helper function
Phil Cohen <phillco@fb.com>
parents: 33829
diff changeset
417 if len(overrides) > 3:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
418 raise error.Abort(_(b"can only specify three labels."))
33933
39d253d088a9 simplemerge: refactor _picklabels to be more compact
Phil Cohen <phillco@fb.com>
parents: 33932
diff changeset
419 result = defaults[:]
39d253d088a9 simplemerge: refactor _picklabels to be more compact
Phil Cohen <phillco@fb.com>
parents: 33932
diff changeset
420 for i, override in enumerate(overrides):
39d253d088a9 simplemerge: refactor _picklabels to be more compact
Phil Cohen <phillco@fb.com>
parents: 33932
diff changeset
421 result[i] = override
39d253d088a9 simplemerge: refactor _picklabels to be more compact
Phil Cohen <phillco@fb.com>
parents: 33932
diff changeset
422 return result
33830
aa6c290a77fa filemerge: extract `_picklabels` as a helper function
Phil Cohen <phillco@fb.com>
parents: 33829
diff changeset
423
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
424
46108
bdc2bf68f19e mergetools: add new conflict marker format with diffs in
Martin von Zweigbergk <martinvonz@google.com>
parents: 46100
diff changeset
425 def _mergediff(m3, name_a, name_b, name_base):
bdc2bf68f19e mergetools: add new conflict marker format with diffs in
Martin von Zweigbergk <martinvonz@google.com>
parents: 46100
diff changeset
426 lines = []
bdc2bf68f19e mergetools: add new conflict marker format with diffs in
Martin von Zweigbergk <martinvonz@google.com>
parents: 46100
diff changeset
427 conflicts = False
bdc2bf68f19e mergetools: add new conflict marker format with diffs in
Martin von Zweigbergk <martinvonz@google.com>
parents: 46100
diff changeset
428 for group in m3.merge_groups():
bdc2bf68f19e mergetools: add new conflict marker format with diffs in
Martin von Zweigbergk <martinvonz@google.com>
parents: 46100
diff changeset
429 if group[0] == b'conflict':
bdc2bf68f19e mergetools: add new conflict marker format with diffs in
Martin von Zweigbergk <martinvonz@google.com>
parents: 46100
diff changeset
430 base_lines, a_lines, b_lines = group[1:]
bdc2bf68f19e mergetools: add new conflict marker format with diffs in
Martin von Zweigbergk <martinvonz@google.com>
parents: 46100
diff changeset
431 base_text = b''.join(base_lines)
bdc2bf68f19e mergetools: add new conflict marker format with diffs in
Martin von Zweigbergk <martinvonz@google.com>
parents: 46100
diff changeset
432 b_blocks = list(
bdc2bf68f19e mergetools: add new conflict marker format with diffs in
Martin von Zweigbergk <martinvonz@google.com>
parents: 46100
diff changeset
433 mdiff.allblocks(
bdc2bf68f19e mergetools: add new conflict marker format with diffs in
Martin von Zweigbergk <martinvonz@google.com>
parents: 46100
diff changeset
434 base_text,
bdc2bf68f19e mergetools: add new conflict marker format with diffs in
Martin von Zweigbergk <martinvonz@google.com>
parents: 46100
diff changeset
435 b''.join(b_lines),
bdc2bf68f19e mergetools: add new conflict marker format with diffs in
Martin von Zweigbergk <martinvonz@google.com>
parents: 46100
diff changeset
436 lines1=base_lines,
bdc2bf68f19e mergetools: add new conflict marker format with diffs in
Martin von Zweigbergk <martinvonz@google.com>
parents: 46100
diff changeset
437 lines2=b_lines,
bdc2bf68f19e mergetools: add new conflict marker format with diffs in
Martin von Zweigbergk <martinvonz@google.com>
parents: 46100
diff changeset
438 )
bdc2bf68f19e mergetools: add new conflict marker format with diffs in
Martin von Zweigbergk <martinvonz@google.com>
parents: 46100
diff changeset
439 )
bdc2bf68f19e mergetools: add new conflict marker format with diffs in
Martin von Zweigbergk <martinvonz@google.com>
parents: 46100
diff changeset
440 a_blocks = list(
bdc2bf68f19e mergetools: add new conflict marker format with diffs in
Martin von Zweigbergk <martinvonz@google.com>
parents: 46100
diff changeset
441 mdiff.allblocks(
bdc2bf68f19e mergetools: add new conflict marker format with diffs in
Martin von Zweigbergk <martinvonz@google.com>
parents: 46100
diff changeset
442 base_text,
bdc2bf68f19e mergetools: add new conflict marker format with diffs in
Martin von Zweigbergk <martinvonz@google.com>
parents: 46100
diff changeset
443 b''.join(a_lines),
bdc2bf68f19e mergetools: add new conflict marker format with diffs in
Martin von Zweigbergk <martinvonz@google.com>
parents: 46100
diff changeset
444 lines1=base_lines,
bdc2bf68f19e mergetools: add new conflict marker format with diffs in
Martin von Zweigbergk <martinvonz@google.com>
parents: 46100
diff changeset
445 lines2=b_lines,
bdc2bf68f19e mergetools: add new conflict marker format with diffs in
Martin von Zweigbergk <martinvonz@google.com>
parents: 46100
diff changeset
446 )
bdc2bf68f19e mergetools: add new conflict marker format with diffs in
Martin von Zweigbergk <martinvonz@google.com>
parents: 46100
diff changeset
447 )
bdc2bf68f19e mergetools: add new conflict marker format with diffs in
Martin von Zweigbergk <martinvonz@google.com>
parents: 46100
diff changeset
448
bdc2bf68f19e mergetools: add new conflict marker format with diffs in
Martin von Zweigbergk <martinvonz@google.com>
parents: 46100
diff changeset
449 def matching_lines(blocks):
bdc2bf68f19e mergetools: add new conflict marker format with diffs in
Martin von Zweigbergk <martinvonz@google.com>
parents: 46100
diff changeset
450 return sum(
bdc2bf68f19e mergetools: add new conflict marker format with diffs in
Martin von Zweigbergk <martinvonz@google.com>
parents: 46100
diff changeset
451 block[1] - block[0]
bdc2bf68f19e mergetools: add new conflict marker format with diffs in
Martin von Zweigbergk <martinvonz@google.com>
parents: 46100
diff changeset
452 for block, kind in blocks
bdc2bf68f19e mergetools: add new conflict marker format with diffs in
Martin von Zweigbergk <martinvonz@google.com>
parents: 46100
diff changeset
453 if kind == b'='
bdc2bf68f19e mergetools: add new conflict marker format with diffs in
Martin von Zweigbergk <martinvonz@google.com>
parents: 46100
diff changeset
454 )
bdc2bf68f19e mergetools: add new conflict marker format with diffs in
Martin von Zweigbergk <martinvonz@google.com>
parents: 46100
diff changeset
455
bdc2bf68f19e mergetools: add new conflict marker format with diffs in
Martin von Zweigbergk <martinvonz@google.com>
parents: 46100
diff changeset
456 def diff_lines(blocks, lines1, lines2):
bdc2bf68f19e mergetools: add new conflict marker format with diffs in
Martin von Zweigbergk <martinvonz@google.com>
parents: 46100
diff changeset
457 for block, kind in blocks:
bdc2bf68f19e mergetools: add new conflict marker format with diffs in
Martin von Zweigbergk <martinvonz@google.com>
parents: 46100
diff changeset
458 if kind == b'=':
bdc2bf68f19e mergetools: add new conflict marker format with diffs in
Martin von Zweigbergk <martinvonz@google.com>
parents: 46100
diff changeset
459 for line in lines1[block[0] : block[1]]:
bdc2bf68f19e mergetools: add new conflict marker format with diffs in
Martin von Zweigbergk <martinvonz@google.com>
parents: 46100
diff changeset
460 yield b' ' + line
bdc2bf68f19e mergetools: add new conflict marker format with diffs in
Martin von Zweigbergk <martinvonz@google.com>
parents: 46100
diff changeset
461 else:
bdc2bf68f19e mergetools: add new conflict marker format with diffs in
Martin von Zweigbergk <martinvonz@google.com>
parents: 46100
diff changeset
462 for line in lines1[block[0] : block[1]]:
bdc2bf68f19e mergetools: add new conflict marker format with diffs in
Martin von Zweigbergk <martinvonz@google.com>
parents: 46100
diff changeset
463 yield b'-' + line
bdc2bf68f19e mergetools: add new conflict marker format with diffs in
Martin von Zweigbergk <martinvonz@google.com>
parents: 46100
diff changeset
464 for line in lines2[block[2] : block[3]]:
bdc2bf68f19e mergetools: add new conflict marker format with diffs in
Martin von Zweigbergk <martinvonz@google.com>
parents: 46100
diff changeset
465 yield b'+' + line
bdc2bf68f19e mergetools: add new conflict marker format with diffs in
Martin von Zweigbergk <martinvonz@google.com>
parents: 46100
diff changeset
466
bdc2bf68f19e mergetools: add new conflict marker format with diffs in
Martin von Zweigbergk <martinvonz@google.com>
parents: 46100
diff changeset
467 lines.append(b"<<<<<<<\n")
bdc2bf68f19e mergetools: add new conflict marker format with diffs in
Martin von Zweigbergk <martinvonz@google.com>
parents: 46100
diff changeset
468 if matching_lines(a_blocks) < matching_lines(b_blocks):
bdc2bf68f19e mergetools: add new conflict marker format with diffs in
Martin von Zweigbergk <martinvonz@google.com>
parents: 46100
diff changeset
469 lines.append(b"======= %s\n" % name_a)
bdc2bf68f19e mergetools: add new conflict marker format with diffs in
Martin von Zweigbergk <martinvonz@google.com>
parents: 46100
diff changeset
470 lines.extend(a_lines)
bdc2bf68f19e mergetools: add new conflict marker format with diffs in
Martin von Zweigbergk <martinvonz@google.com>
parents: 46100
diff changeset
471 lines.append(b"------- %s\n" % name_base)
bdc2bf68f19e mergetools: add new conflict marker format with diffs in
Martin von Zweigbergk <martinvonz@google.com>
parents: 46100
diff changeset
472 lines.append(b"+++++++ %s\n" % name_b)
bdc2bf68f19e mergetools: add new conflict marker format with diffs in
Martin von Zweigbergk <martinvonz@google.com>
parents: 46100
diff changeset
473 lines.extend(diff_lines(b_blocks, base_lines, b_lines))
bdc2bf68f19e mergetools: add new conflict marker format with diffs in
Martin von Zweigbergk <martinvonz@google.com>
parents: 46100
diff changeset
474 else:
bdc2bf68f19e mergetools: add new conflict marker format with diffs in
Martin von Zweigbergk <martinvonz@google.com>
parents: 46100
diff changeset
475 lines.append(b"------- %s\n" % name_base)
bdc2bf68f19e mergetools: add new conflict marker format with diffs in
Martin von Zweigbergk <martinvonz@google.com>
parents: 46100
diff changeset
476 lines.append(b"+++++++ %s\n" % name_a)
bdc2bf68f19e mergetools: add new conflict marker format with diffs in
Martin von Zweigbergk <martinvonz@google.com>
parents: 46100
diff changeset
477 lines.extend(diff_lines(a_blocks, base_lines, a_lines))
bdc2bf68f19e mergetools: add new conflict marker format with diffs in
Martin von Zweigbergk <martinvonz@google.com>
parents: 46100
diff changeset
478 lines.append(b"======= %s\n" % name_b)
bdc2bf68f19e mergetools: add new conflict marker format with diffs in
Martin von Zweigbergk <martinvonz@google.com>
parents: 46100
diff changeset
479 lines.extend(b_lines)
bdc2bf68f19e mergetools: add new conflict marker format with diffs in
Martin von Zweigbergk <martinvonz@google.com>
parents: 46100
diff changeset
480 lines.append(b">>>>>>>\n")
bdc2bf68f19e mergetools: add new conflict marker format with diffs in
Martin von Zweigbergk <martinvonz@google.com>
parents: 46100
diff changeset
481 conflicts = True
bdc2bf68f19e mergetools: add new conflict marker format with diffs in
Martin von Zweigbergk <martinvonz@google.com>
parents: 46100
diff changeset
482 else:
bdc2bf68f19e mergetools: add new conflict marker format with diffs in
Martin von Zweigbergk <martinvonz@google.com>
parents: 46100
diff changeset
483 lines.extend(group[1])
bdc2bf68f19e mergetools: add new conflict marker format with diffs in
Martin von Zweigbergk <martinvonz@google.com>
parents: 46100
diff changeset
484 return lines, conflicts
bdc2bf68f19e mergetools: add new conflict marker format with diffs in
Martin von Zweigbergk <martinvonz@google.com>
parents: 46100
diff changeset
485
bdc2bf68f19e mergetools: add new conflict marker format with diffs in
Martin von Zweigbergk <martinvonz@google.com>
parents: 46100
diff changeset
486
48514
fb691fa90807 simplemerge: add a specialized function for "union", "local", "other"
Martin von Zweigbergk <martinvonz@google.com>
parents: 48509
diff changeset
487 def _resolve(m3, sides):
fb691fa90807 simplemerge: add a specialized function for "union", "local", "other"
Martin von Zweigbergk <martinvonz@google.com>
parents: 48509
diff changeset
488 lines = []
fb691fa90807 simplemerge: add a specialized function for "union", "local", "other"
Martin von Zweigbergk <martinvonz@google.com>
parents: 48509
diff changeset
489 for group in m3.merge_groups():
fb691fa90807 simplemerge: add a specialized function for "union", "local", "other"
Martin von Zweigbergk <martinvonz@google.com>
parents: 48509
diff changeset
490 if group[0] == b'conflict':
fb691fa90807 simplemerge: add a specialized function for "union", "local", "other"
Martin von Zweigbergk <martinvonz@google.com>
parents: 48509
diff changeset
491 for side in sides:
fb691fa90807 simplemerge: add a specialized function for "union", "local", "other"
Martin von Zweigbergk <martinvonz@google.com>
parents: 48509
diff changeset
492 lines.extend(group[side + 1])
fb691fa90807 simplemerge: add a specialized function for "union", "local", "other"
Martin von Zweigbergk <martinvonz@google.com>
parents: 48509
diff changeset
493 else:
fb691fa90807 simplemerge: add a specialized function for "union", "local", "other"
Martin von Zweigbergk <martinvonz@google.com>
parents: 48509
diff changeset
494 lines.extend(group[1])
fb691fa90807 simplemerge: add a specialized function for "union", "local", "other"
Martin von Zweigbergk <martinvonz@google.com>
parents: 48509
diff changeset
495 return lines
fb691fa90807 simplemerge: add a specialized function for "union", "local", "other"
Martin von Zweigbergk <martinvonz@google.com>
parents: 48509
diff changeset
496
fb691fa90807 simplemerge: add a specialized function for "union", "local", "other"
Martin von Zweigbergk <martinvonz@google.com>
parents: 48509
diff changeset
497
34049
6330df9d6393 simplemerge: remove unused `repo` parameter
Phil Cohen <phillco@fb.com>
parents: 33933
diff changeset
498 def simplemerge(ui, localctx, basectx, otherctx, **opts):
33828
8b91a4ff23ad simplemerge: use contexts to read file data from, if passed
Phil Cohen <phillco@fb.com>
parents: 33826
diff changeset
499 """Performs the simplemerge algorithm.
8b91a4ff23ad simplemerge: use contexts to read file data from, if passed
Phil Cohen <phillco@fb.com>
parents: 33826
diff changeset
500
33907
1ad3085239ad simplemerge: make context parameters non-optional
Phil Cohen <phillco@fb.com>
parents: 33906
diff changeset
501 The merged result is written into `localctx`.
33905
61b267a99fea simplemerge: stop reading from, and writing to, files
Phil Cohen <phillco@fb.com>
parents: 33904
diff changeset
502 """
35368
93c4958d987c py3: handle keyword arguments correctly in simplemerge.py
Pulkit Goyal <7895pulkit@gmail.com>
parents: 34049
diff changeset
503
33828
8b91a4ff23ad simplemerge: use contexts to read file data from, if passed
Phil Cohen <phillco@fb.com>
parents: 33826
diff changeset
504 def readctx(ctx):
33902
f39ba8237ed6 simplemerge: use `ctx.decoddeddata()` instead of `repo.wreaddata`
Phil Cohen <phillco@fb.com>
parents: 33830
diff changeset
505 # Merges were always run in the working copy before, which means
f39ba8237ed6 simplemerge: use `ctx.decoddeddata()` instead of `repo.wreaddata`
Phil Cohen <phillco@fb.com>
parents: 33830
diff changeset
506 # they used decoded data, if the user defined any repository
f39ba8237ed6 simplemerge: use `ctx.decoddeddata()` instead of `repo.wreaddata`
Phil Cohen <phillco@fb.com>
parents: 33830
diff changeset
507 # filters.
f39ba8237ed6 simplemerge: use `ctx.decoddeddata()` instead of `repo.wreaddata`
Phil Cohen <phillco@fb.com>
parents: 33830
diff changeset
508 #
f39ba8237ed6 simplemerge: use `ctx.decoddeddata()` instead of `repo.wreaddata`
Phil Cohen <phillco@fb.com>
parents: 33830
diff changeset
509 # Maintain that behavior today for BC, though perhaps in the future
f39ba8237ed6 simplemerge: use `ctx.decoddeddata()` instead of `repo.wreaddata`
Phil Cohen <phillco@fb.com>
parents: 33830
diff changeset
510 # it'd be worth considering whether merging encoded data (what the
f39ba8237ed6 simplemerge: use `ctx.decoddeddata()` instead of `repo.wreaddata`
Phil Cohen <phillco@fb.com>
parents: 33830
diff changeset
511 # repository usually sees) might be more useful.
f39ba8237ed6 simplemerge: use `ctx.decoddeddata()` instead of `repo.wreaddata`
Phil Cohen <phillco@fb.com>
parents: 33830
diff changeset
512 return _verifytext(ctx.decodeddata(), ctx.path(), ui, opts)
33828
8b91a4ff23ad simplemerge: use contexts to read file data from, if passed
Phil Cohen <phillco@fb.com>
parents: 33826
diff changeset
513
46098
5510e2ac213f simplemerge: work with opts as native strings instead of bytes
Martin von Zweigbergk <martinvonz@google.com>
parents: 45942
diff changeset
514 mode = opts.get('mode', b'merge')
33830
aa6c290a77fa filemerge: extract `_picklabels` as a helper function
Phil Cohen <phillco@fb.com>
parents: 33829
diff changeset
515 name_a, name_b, name_base = None, None, None
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
516 if mode != b'union':
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
517 name_a, name_b, name_base = _picklabels(
46098
5510e2ac213f simplemerge: work with opts as native strings instead of bytes
Martin von Zweigbergk <martinvonz@google.com>
parents: 45942
diff changeset
518 [localctx.path(), otherctx.path(), None], opts.get('label', [])
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
519 )
4364
d5c3a70f8422 polish the simplemerge command; add a test
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4363
diff changeset
520
14328
3c65cdcf3ba6 simplemerge: do not allow binary files to abort an entire merge
Steve Borho <steve@borho.org>
parents: 12401
diff changeset
521 try:
33905
61b267a99fea simplemerge: stop reading from, and writing to, files
Phil Cohen <phillco@fb.com>
parents: 33904
diff changeset
522 localtext = readctx(localctx)
61b267a99fea simplemerge: stop reading from, and writing to, files
Phil Cohen <phillco@fb.com>
parents: 33904
diff changeset
523 basetext = readctx(basectx)
61b267a99fea simplemerge: stop reading from, and writing to, files
Phil Cohen <phillco@fb.com>
parents: 33904
diff changeset
524 othertext = readctx(otherctx)
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26223
diff changeset
525 except error.Abort:
14328
3c65cdcf3ba6 simplemerge: do not allow binary files to abort an entire merge
Steve Borho <steve@borho.org>
parents: 12401
diff changeset
526 return 1
4364
d5c3a70f8422 polish the simplemerge command; add a test
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4363
diff changeset
527
d5c3a70f8422 polish the simplemerge command; add a test
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4363
diff changeset
528 m3 = Merge3Text(basetext, localtext, othertext)
48514
fb691fa90807 simplemerge: add a specialized function for "union", "local", "other"
Martin von Zweigbergk <martinvonz@google.com>
parents: 48509
diff changeset
529 conflicts = False
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
530 if mode == b'union':
48514
fb691fa90807 simplemerge: add a specialized function for "union", "local", "other"
Martin von Zweigbergk <martinvonz@google.com>
parents: 48509
diff changeset
531 lines = _resolve(m3, (1, 2))
48509
5151b0f6519e simplemerge: make `localorother` a "mode" instead of a separate thing
Martin von Zweigbergk <martinvonz@google.com>
parents: 48508
diff changeset
532 elif mode == b'local':
48514
fb691fa90807 simplemerge: add a specialized function for "union", "local", "other"
Martin von Zweigbergk <martinvonz@google.com>
parents: 48509
diff changeset
533 lines = _resolve(m3, (1,))
48509
5151b0f6519e simplemerge: make `localorother` a "mode" instead of a separate thing
Martin von Zweigbergk <martinvonz@google.com>
parents: 48508
diff changeset
534 elif mode == b'other':
48514
fb691fa90807 simplemerge: add a specialized function for "union", "local", "other"
Martin von Zweigbergk <martinvonz@google.com>
parents: 48509
diff changeset
535 lines = _resolve(m3, (2,))
fb691fa90807 simplemerge: add a specialized function for "union", "local", "other"
Martin von Zweigbergk <martinvonz@google.com>
parents: 48509
diff changeset
536 elif mode == b'mergediff':
46108
bdc2bf68f19e mergetools: add new conflict marker format with diffs in
Martin von Zweigbergk <martinvonz@google.com>
parents: 46100
diff changeset
537 lines, conflicts = _mergediff(m3, name_a, name_b, name_base)
bdc2bf68f19e mergetools: add new conflict marker format with diffs in
Martin von Zweigbergk <martinvonz@google.com>
parents: 46100
diff changeset
538 else:
48514
fb691fa90807 simplemerge: add a specialized function for "union", "local", "other"
Martin von Zweigbergk <martinvonz@google.com>
parents: 48509
diff changeset
539 extrakwargs = {
fb691fa90807 simplemerge: add a specialized function for "union", "local", "other"
Martin von Zweigbergk <martinvonz@google.com>
parents: 48509
diff changeset
540 'minimize': True,
fb691fa90807 simplemerge: add a specialized function for "union", "local", "other"
Martin von Zweigbergk <martinvonz@google.com>
parents: 48509
diff changeset
541 }
fb691fa90807 simplemerge: add a specialized function for "union", "local", "other"
Martin von Zweigbergk <martinvonz@google.com>
parents: 48509
diff changeset
542 if name_base is not None:
fb691fa90807 simplemerge: add a specialized function for "union", "local", "other"
Martin von Zweigbergk <martinvonz@google.com>
parents: 48509
diff changeset
543 extrakwargs['base_marker'] = b'|||||||'
fb691fa90807 simplemerge: add a specialized function for "union", "local", "other"
Martin von Zweigbergk <martinvonz@google.com>
parents: 48509
diff changeset
544 extrakwargs['name_base'] = name_base
fb691fa90807 simplemerge: add a specialized function for "union", "local", "other"
Martin von Zweigbergk <martinvonz@google.com>
parents: 48509
diff changeset
545 extrakwargs['minimize'] = False
46108
bdc2bf68f19e mergetools: add new conflict marker format with diffs in
Martin von Zweigbergk <martinvonz@google.com>
parents: 46100
diff changeset
546 lines = list(
48508
fa159bb463e6 simplemerge: avoid a call to `pycompat.strkwargs()`
Martin von Zweigbergk <martinvonz@google.com>
parents: 48507
diff changeset
547 m3.merge_lines(name_a=name_a, name_b=name_b, **extrakwargs)
46108
bdc2bf68f19e mergetools: add new conflict marker format with diffs in
Martin von Zweigbergk <martinvonz@google.com>
parents: 46100
diff changeset
548 )
48514
fb691fa90807 simplemerge: add a specialized function for "union", "local", "other"
Martin von Zweigbergk <martinvonz@google.com>
parents: 48509
diff changeset
549 conflicts = m3.conflicts
4364
d5c3a70f8422 polish the simplemerge command; add a test
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4363
diff changeset
550
46100
a771ffc378a8 simplemerge: write output only once it's complete
Martin von Zweigbergk <martinvonz@google.com>
parents: 46099
diff changeset
551 mergedtext = b''.join(lines)
a771ffc378a8 simplemerge: write output only once it's complete
Martin von Zweigbergk <martinvonz@google.com>
parents: 46099
diff changeset
552 if opts.get('print'):
a771ffc378a8 simplemerge: write output only once it's complete
Martin von Zweigbergk <martinvonz@google.com>
parents: 46099
diff changeset
553 ui.fout.write(mergedtext)
a771ffc378a8 simplemerge: write output only once it's complete
Martin von Zweigbergk <martinvonz@google.com>
parents: 46099
diff changeset
554 else:
48507
58a3be48ddd2 simplemerge: stop merging file flags
Martin von Zweigbergk <martinvonz@google.com>
parents: 48425
diff changeset
555 # localctx.flags() already has the merged flags (done in
58a3be48ddd2 simplemerge: stop merging file flags
Martin von Zweigbergk <martinvonz@google.com>
parents: 48425
diff changeset
556 # mergestate.resolve())
58a3be48ddd2 simplemerge: stop merging file flags
Martin von Zweigbergk <martinvonz@google.com>
parents: 48425
diff changeset
557 localctx.write(mergedtext, localctx.flags())
4364
d5c3a70f8422 polish the simplemerge command; add a test
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4363
diff changeset
558
48425
9e1f174d305b simplemerge: set `conflicts` earlier for :union tool
Martin von Zweigbergk <martinvonz@google.com>
parents: 46843
diff changeset
559 if conflicts:
4364
d5c3a70f8422 polish the simplemerge command; add a test
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4363
diff changeset
560 return 1