##// END OF EJS Templates
filemerge: add internal:tagmerge merge tool...
Angel Ezquerra -
r21922:50e20154 default
parent child Browse files
Show More
@@ -0,0 +1,265
1 # tagmerge.py - merge .hgtags files
2 #
3 # Copyright 2014 Angel Ezquerra <angel.ezquerra@gmail.com>
4 #
5 # This software may be used and distributed according to the terms of the
6 # GNU General Public License version 2 or any later version.
7
8 # This module implements an automatic merge algorithm for mercurial's tag files
9 #
10 # The tagmerge algorithm implemented in this module is able to resolve most
11 # merge conflicts that currently would trigger a .hgtags merge conflict. The
12 # only case that it does not (and cannot) handle is that in which two tags point
13 # to different revisions on each merge parent _and_ their corresponding tag
14 # histories have the same rank (i.e. the same length). In all other cases the
15 # merge algorithm will choose the revision belonging to the parent with the
16 # highest ranked tag history. The merged tag history is the combination of both
17 # tag histories (special care is taken to try to combine common tag histories
18 # where possible).
19 #
20 # In addition to actually merging the tags from two parents, taking into
21 # account the base, the algorithm also tries to minimize the difference
22 # between the merged tag file and the first parent's tag file (i.e. it tries to
23 # make the merged tag order as as similar as possible to the first parent's tag
24 # file order).
25 #
26 # The algorithm works as follows:
27 # 1. read the tags from p1, p2 and the base
28 # - when reading the p1 tags, also get the line numbers associated to each
29 # tag node (these will be used to sort the merged tags in a way that
30 # minimizes the diff to p1). Ignore the file numbers when reading p2 and
31 # the base
32 # 2. recover the "lost tags" (i.e. those that are found in the base but not on
33 # p1 or p2) and add them back to p1 and/or p2
34 # - at this point the only tags that are on p1 but not on p2 are those new
35 # tags that were introduced in p1. Same thing for the tags that are on p2
36 # but not on p2
37 # 3. take all tags that are only on p1 or only on p2 (but not on the base)
38 # - Note that these are the tags that were introduced between base and p1
39 # and between base and p2, possibly on separate clones
40 # 4. for each tag found both on p1 and p2 perform the following merge algorithm:
41 # - the tags conflict if their tag "histories" have the same "rank" (i.e.
42 # length) _AND_ the last (current) tag is _NOT_ the same
43 # - for non conflicting tags:
44 # - choose which are the high and the low ranking nodes
45 # - the high ranking list of nodes is the one that is longer.
46 # In case of draw favor p1
47 # - the merged node list is made of 3 parts:
48 # - first the nodes that are common to the beginning of both
49 # the low and the high ranking nodes
50 # - second the non common low ranking nodes
51 # - finally the non common high ranking nodes (with the last
52 # one being the merged tag node)
53 # - note that this is equivalent to putting the whole low ranking
54 # node list first, followed by the non common high ranking nodes
55 # - note that during the merge we keep the "node line numbers", which will
56 # be used when writing the merged tags to the tag file
57 # 5. write the merged tags taking into account to their positions in the first
58 # parent (i.e. try to keep the relative ordering of the nodes that come
59 # from p1). This minimizes the diff between the merged and the p1 tag files
60 # This is donw by using the following algorithm
61 # - group the nodes for a given tag that must be written next to each other
62 # - A: nodes that come from consecutive lines on p1
63 # - B: nodes that come from p2 (i.e. whose associated line number is
64 # None) and are next to one of the a nodes in A
65 # - each group is associated with a line number coming from p1
66 # - generate a "tag block" for each of the groups
67 # - a tag block is a set of consecutive "node tag" lines belonging to
68 # the same tag and which will be written next to each other on the
69 # merged tags file
70 # - sort the "tag blocks" according to their associated number line
71 # - put blocks whose nodes come all from p2 first
72 # - write the tag blocks in the sorted order
73
74 import tags
75 import util
76 from node import nullid, hex
77 from i18n import _
78 import operator
79 hexnullid = hex(nullid)
80
81 def readtagsformerge(ui, repo, lines, fn='', keeplinenums=False):
82 '''read the .hgtags file into a structure that is suitable for merging
83
84 Sepending on the keeplinenumbers flag, clear the line numbers associated
85 with each tag. Rhis is done because only the line numbers of the first
86 parent are useful for merging
87 '''
88 filetags = tags._readtaghist(ui, repo, lines, fn=fn, recode=None,
89 calcnodelines=True)[1]
90 for tagname, taginfo in filetags.items():
91 if not keeplinenums:
92 for el in taginfo:
93 el[1] = None
94 return filetags
95
96 def grouptagnodesbyline(tagnodes):
97 '''
98 Group nearby nodes (i.e. those that must be written next to each other)
99
100 The input is a list of [node, position] pairs, corresponding to a given tag
101 The position is the line number where the node was found on the first parent
102 .hgtags file, or None for those nodes that came from the base or the second
103 parent .hgtags files.
104
105 This function groups those [node, position] pairs, returning a list of
106 groups of nodes that must be written next to each other because their
107 positions are consecutive or have no position preference (because their
108 position is None).
109
110 The result is a list of [position, [consecutive node list]]
111 '''
112 firstlinenum = None
113 for hexnode, linenum in tagnodes:
114 firstlinenum = linenum
115 if firstlinenum is not None:
116 break
117 if firstlinenum is None:
118 return [[None, [el[0] for el in tagnodes]]]
119 tagnodes[0][1] = firstlinenum
120 groupednodes = [[firstlinenum, []]]
121 prevlinenum = firstlinenum
122 for hexnode, linenum in tagnodes:
123 if linenum is not None and linenum - prevlinenum > 1:
124 groupednodes.append([linenum, []])
125 groupednodes[-1][1].append(hexnode)
126 if linenum is not None:
127 prevlinenum = linenum
128 return groupednodes
129
130 def writemergedtags(repo, mergedtags):
131 '''
132 write the merged tags while trying to minimize the diff to the first parent
133
134 This function uses the ordering info stored on the merged tags dict to
135 generate an .hgtags file which is correct (in the sense that its contents
136 correspond to the result of the tag merge) while also being as close as
137 possible to the first parent's .hgtags file.
138 '''
139 # group the node-tag pairs that must be written next to each other
140 for tname, taglist in mergedtags.items():
141 mergedtags[tname] = grouptagnodesbyline(taglist)
142
143 # convert the grouped merged tags dict into a format that resembles the
144 # final .hgtags file (i.e. a list of blocks of 'node tag' pairs)
145 def taglist2string(tlist, tname):
146 return '\n'.join(['%s %s' % (hexnode, tname) for hexnode in tlist])
147
148 finaltags = []
149 for tname, tags in mergedtags.items():
150 for block in tags:
151 block[1] = taglist2string(block[1], tname)
152 finaltags += tags
153
154 # the tag groups are linked to a "position" that can be used to sort them
155 # before writing them
156 # the position is calculated to ensure that the diff of the merged .hgtags
157 # file to the first parent's .hgtags file is as small as possible
158 finaltags.sort(key=operator.itemgetter(0))
159
160 # finally we can join the sorted groups to get the final contents of the
161 # merged .hgtags file, and then write it to disk
162 mergedtagstring = '\n'.join([tags for rank, tags in finaltags if tags])
163 fp = repo.wfile('.hgtags', 'wb')
164 fp.write(mergedtagstring + '\n')
165 fp.close()
166
167 def singletagmerge(p1nodes, p2nodes):
168 '''
169 merge the nodes corresponding to a single tag
170
171 Note that the inputs are lists of node-linenum pairs (i.e. not just lists
172 of nodes)
173 '''
174 if not p2nodes:
175 return p1nodes
176 if not p1nodes:
177 return p2nodes
178
179 # there is no conflict unless both tags point to different revisions
180 # and have a non identical tag history
181 p1currentnode = p1nodes[-1][0]
182 p2currentnode = p2nodes[-1][0]
183 if p1currentnode != p2currentnode and len(p1nodes) == len(p2nodes):
184 # cannot merge two tags with same rank pointing to different nodes
185 return None
186
187 # which are the highest ranking (hr) / lowest ranking (lr) nodes?
188 if len(p1nodes) >= len(p2nodes):
189 hrnodes, lrnodes = p1nodes, p2nodes
190 else:
191 hrnodes, lrnodes = p2nodes, p1nodes
192
193 # the lowest ranking nodes will be written first, followed by the highest
194 # ranking nodes
195 # to avoid unwanted tag rank explosion we try to see if there are some
196 # common nodes that can be written only once
197 commonidx = len(lrnodes)
198 for n in range(len(lrnodes)):
199 if hrnodes[n][0] != lrnodes[n][0]:
200 commonidx = n
201 break
202 lrnodes[n][1] = p1nodes[n][1]
203
204 # the merged node list has 3 parts:
205 # - common nodes
206 # - non common lowest ranking nodes
207 # - non common highest ranking nodes
208 # note that the common nodes plus the non common lowest ranking nodes is the
209 # whole list of lr nodes
210 return lrnodes + hrnodes[commonidx:]
211
212 def merge(repo, fcd, fco, fca):
213 '''
214 Merge the tags of two revisions, taking into account the base tags
215 Try to minimize the diff between the merged tags and the first parent tags
216 '''
217 ui = repo.ui
218 # read the p1, p2 and base tags
219 # only keep the line numbers for the p1 tags
220 p1tags = readtagsformerge(
221 ui, repo, fcd.data().splitlines(), fn="p1 tags",
222 keeplinenums=True)
223 p2tags = readtagsformerge(
224 ui, repo, fco.data().splitlines(), fn="p2 tags",
225 keeplinenums=False)
226 basetags = readtagsformerge(
227 ui, repo, fca.data().splitlines(), fn="base tags",
228 keeplinenums=False)
229
230 # recover the list of "lost tags" (i.e. those that were found on the base
231 # revision but not on one of the revisions being merged)
232 basetagset = set(basetags)
233 for n, pntags in enumerate((p1tags, p2tags)):
234 pntagset = set(pntags)
235 pnlosttagset = basetagset - pntagset
236 for t in pnlosttagset:
237 pntags[t] = basetags[t]
238 if pntags[t][-1][0] != hexnullid:
239 pntags[t].append([hexnullid, None])
240
241 conflictedtags = [] # for reporting purposes
242 mergedtags = util.sortdict(p1tags)
243 # sortdict does not implement iteritems()
244 for tname, p2nodes in p2tags.items():
245 if tname not in mergedtags:
246 mergedtags[tname] = p2nodes
247 continue
248 p1nodes = mergedtags[tname]
249 mergednodes = singletagmerge(p1nodes, p2nodes)
250 if mergednodes is None:
251 conflictedtags.append(tname)
252 continue
253 mergedtags[tname] = mergednodes
254
255 if conflictedtags:
256 numconflicts = len(conflictedtags)
257 ui.warn(_('automatic .hgtags merge failed\n'
258 'the following %d tags are in conflict: %s\n')
259 % (numconflicts, ', '.join(sorted(conflictedtags))))
260 return True, 1
261
262 writemergedtags(repo, mergedtags)
263 ui.note(_('.hgtags merged successfully\n'))
264 return False, 0
265
@@ -1,436 +1,447
1 1 # filemerge.py - file-level merge handling for Mercurial
2 2 #
3 3 # Copyright 2006, 2007, 2008 Matt Mackall <mpm@selenic.com>
4 4 #
5 5 # This software may be used and distributed according to the terms of the
6 6 # GNU General Public License version 2 or any later version.
7 7
8 8 from node import short
9 9 from i18n import _
10 10 import util, simplemerge, match, error, templater, templatekw
11 11 import os, tempfile, re, filecmp
12 import tagmerge
12 13
13 14 def _toolstr(ui, tool, part, default=""):
14 15 return ui.config("merge-tools", tool + "." + part, default)
15 16
16 17 def _toolbool(ui, tool, part, default=False):
17 18 return ui.configbool("merge-tools", tool + "." + part, default)
18 19
19 20 def _toollist(ui, tool, part, default=[]):
20 21 return ui.configlist("merge-tools", tool + "." + part, default)
21 22
22 23 internals = {}
23 24
24 25 def internaltool(name, trymerge, onfailure=None):
25 26 '''return a decorator for populating internal merge tool table'''
26 27 def decorator(func):
27 28 fullname = 'internal:' + name
28 29 func.__doc__ = "``%s``\n" % fullname + func.__doc__.strip()
29 30 internals[fullname] = func
30 31 func.trymerge = trymerge
31 32 func.onfailure = onfailure
32 33 return func
33 34 return decorator
34 35
35 36 def _findtool(ui, tool):
36 37 if tool in internals:
37 38 return tool
38 39 for kn in ("regkey", "regkeyalt"):
39 40 k = _toolstr(ui, tool, kn)
40 41 if not k:
41 42 continue
42 43 p = util.lookupreg(k, _toolstr(ui, tool, "regname"))
43 44 if p:
44 45 p = util.findexe(p + _toolstr(ui, tool, "regappend"))
45 46 if p:
46 47 return p
47 48 exe = _toolstr(ui, tool, "executable", tool)
48 49 return util.findexe(util.expandpath(exe))
49 50
50 51 def _picktool(repo, ui, path, binary, symlink):
51 52 def check(tool, pat, symlink, binary):
52 53 tmsg = tool
53 54 if pat:
54 55 tmsg += " specified for " + pat
55 56 if not _findtool(ui, tool):
56 57 if pat: # explicitly requested tool deserves a warning
57 58 ui.warn(_("couldn't find merge tool %s\n") % tmsg)
58 59 else: # configured but non-existing tools are more silent
59 60 ui.note(_("couldn't find merge tool %s\n") % tmsg)
60 61 elif symlink and not _toolbool(ui, tool, "symlink"):
61 62 ui.warn(_("tool %s can't handle symlinks\n") % tmsg)
62 63 elif binary and not _toolbool(ui, tool, "binary"):
63 64 ui.warn(_("tool %s can't handle binary\n") % tmsg)
64 65 elif not util.gui() and _toolbool(ui, tool, "gui"):
65 66 ui.warn(_("tool %s requires a GUI\n") % tmsg)
66 67 else:
67 68 return True
68 69 return False
69 70
70 71 # forcemerge comes from command line arguments, highest priority
71 72 force = ui.config('ui', 'forcemerge')
72 73 if force:
73 74 toolpath = _findtool(ui, force)
74 75 if toolpath:
75 76 return (force, util.shellquote(toolpath))
76 77 else:
77 78 # mimic HGMERGE if given tool not found
78 79 return (force, force)
79 80
80 81 # HGMERGE takes next precedence
81 82 hgmerge = os.environ.get("HGMERGE")
82 83 if hgmerge:
83 84 return (hgmerge, hgmerge)
84 85
85 86 # then patterns
86 87 for pat, tool in ui.configitems("merge-patterns"):
87 88 mf = match.match(repo.root, '', [pat])
88 89 if mf(path) and check(tool, pat, symlink, False):
89 90 toolpath = _findtool(ui, tool)
90 91 return (tool, util.shellquote(toolpath))
91 92
92 93 # then merge tools
93 94 tools = {}
94 95 for k, v in ui.configitems("merge-tools"):
95 96 t = k.split('.')[0]
96 97 if t not in tools:
97 98 tools[t] = int(_toolstr(ui, t, "priority", "0"))
98 99 names = tools.keys()
99 100 tools = sorted([(-p, t) for t, p in tools.items()])
100 101 uimerge = ui.config("ui", "merge")
101 102 if uimerge:
102 103 if uimerge not in names:
103 104 return (uimerge, uimerge)
104 105 tools.insert(0, (None, uimerge)) # highest priority
105 106 tools.append((None, "hgmerge")) # the old default, if found
106 107 for p, t in tools:
107 108 if check(t, None, symlink, binary):
108 109 toolpath = _findtool(ui, t)
109 110 return (t, util.shellquote(toolpath))
110 111
111 112 # internal merge or prompt as last resort
112 113 if symlink or binary:
113 114 return "internal:prompt", None
114 115 return "internal:merge", None
115 116
116 117 def _eoltype(data):
117 118 "Guess the EOL type of a file"
118 119 if '\0' in data: # binary
119 120 return None
120 121 if '\r\n' in data: # Windows
121 122 return '\r\n'
122 123 if '\r' in data: # Old Mac
123 124 return '\r'
124 125 if '\n' in data: # UNIX
125 126 return '\n'
126 127 return None # unknown
127 128
128 129 def _matcheol(file, origfile):
129 130 "Convert EOL markers in a file to match origfile"
130 131 tostyle = _eoltype(util.readfile(origfile))
131 132 if tostyle:
132 133 data = util.readfile(file)
133 134 style = _eoltype(data)
134 135 if style:
135 136 newdata = data.replace(style, tostyle)
136 137 if newdata != data:
137 138 util.writefile(file, newdata)
138 139
139 140 @internaltool('prompt', False)
140 141 def _iprompt(repo, mynode, orig, fcd, fco, fca, toolconf):
141 142 """Asks the user which of the local or the other version to keep as
142 143 the merged version."""
143 144 ui = repo.ui
144 145 fd = fcd.path()
145 146
146 147 if ui.promptchoice(_(" no tool found to merge %s\n"
147 148 "keep (l)ocal or take (o)ther?"
148 149 "$$ &Local $$ &Other") % fd, 0):
149 150 return _iother(repo, mynode, orig, fcd, fco, fca, toolconf)
150 151 else:
151 152 return _ilocal(repo, mynode, orig, fcd, fco, fca, toolconf)
152 153
153 154 @internaltool('local', False)
154 155 def _ilocal(repo, mynode, orig, fcd, fco, fca, toolconf):
155 156 """Uses the local version of files as the merged version."""
156 157 return 0
157 158
158 159 @internaltool('other', False)
159 160 def _iother(repo, mynode, orig, fcd, fco, fca, toolconf):
160 161 """Uses the other version of files as the merged version."""
161 162 repo.wwrite(fcd.path(), fco.data(), fco.flags())
162 163 return 0
163 164
164 165 @internaltool('fail', False)
165 166 def _ifail(repo, mynode, orig, fcd, fco, fca, toolconf):
166 167 """
167 168 Rather than attempting to merge files that were modified on both
168 169 branches, it marks them as unresolved. The resolve command must be
169 170 used to resolve these conflicts."""
170 171 return 1
171 172
172 173 def _premerge(repo, toolconf, files, labels=None):
173 174 tool, toolpath, binary, symlink = toolconf
174 175 if symlink:
175 176 return 1
176 177 a, b, c, back = files
177 178
178 179 ui = repo.ui
179 180
180 181 # do we attempt to simplemerge first?
181 182 try:
182 183 premerge = _toolbool(ui, tool, "premerge", not binary)
183 184 except error.ConfigError:
184 185 premerge = _toolstr(ui, tool, "premerge").lower()
185 186 valid = 'keep'.split()
186 187 if premerge not in valid:
187 188 _valid = ', '.join(["'" + v + "'" for v in valid])
188 189 raise error.ConfigError(_("%s.premerge not valid "
189 190 "('%s' is neither boolean nor %s)") %
190 191 (tool, premerge, _valid))
191 192
192 193 if premerge:
193 194 r = simplemerge.simplemerge(ui, a, b, c, quiet=True, label=labels)
194 195 if not r:
195 196 ui.debug(" premerge successful\n")
196 197 return 0
197 198 if premerge != 'keep':
198 199 util.copyfile(back, a) # restore from backup and try again
199 200 return 1 # continue merging
200 201
201 202 @internaltool('merge', True,
202 203 _("merging %s incomplete! "
203 204 "(edit conflicts, then use 'hg resolve --mark')\n"))
204 205 def _imerge(repo, mynode, orig, fcd, fco, fca, toolconf, files, labels=None):
205 206 """
206 207 Uses the internal non-interactive simple merge algorithm for merging
207 208 files. It will fail if there are any conflicts and leave markers in
208 209 the partially merged file."""
209 210 tool, toolpath, binary, symlink = toolconf
210 211 if symlink:
211 212 repo.ui.warn(_('warning: internal:merge cannot merge symlinks '
212 213 'for %s\n') % fcd.path())
213 214 return False, 1
214 215 r = _premerge(repo, toolconf, files, labels=labels)
215 216 if r:
216 217 a, b, c, back = files
217 218
218 219 ui = repo.ui
219 220
220 221 r = simplemerge.simplemerge(ui, a, b, c, label=labels, no_minimal=True)
221 222 return True, r
222 223 return False, 0
223 224
225 @internaltool('tagmerge', True,
226 _("automatic tag merging of %s failed! "
227 "(use 'hg resolve --tool internal:merge' or another merge "
228 "tool of your choice)\n"))
229 def _itagmerge(repo, mynode, orig, fcd, fco, fca, toolconf, files, labels=None):
230 """
231 Uses the internal tag merge algorithm (experimental).
232 """
233 return tagmerge.merge(repo, fcd, fco, fca)
234
224 235 @internaltool('dump', True)
225 236 def _idump(repo, mynode, orig, fcd, fco, fca, toolconf, files, labels=None):
226 237 """
227 238 Creates three versions of the files to merge, containing the
228 239 contents of local, other and base. These files can then be used to
229 240 perform a merge manually. If the file to be merged is named
230 241 ``a.txt``, these files will accordingly be named ``a.txt.local``,
231 242 ``a.txt.other`` and ``a.txt.base`` and they will be placed in the
232 243 same directory as ``a.txt``."""
233 244 r = _premerge(repo, toolconf, files, labels=labels)
234 245 if r:
235 246 a, b, c, back = files
236 247
237 248 fd = fcd.path()
238 249
239 250 util.copyfile(a, a + ".local")
240 251 repo.wwrite(fd + ".other", fco.data(), fco.flags())
241 252 repo.wwrite(fd + ".base", fca.data(), fca.flags())
242 253 return False, r
243 254
244 255 def _xmerge(repo, mynode, orig, fcd, fco, fca, toolconf, files, labels=None):
245 256 r = _premerge(repo, toolconf, files, labels=labels)
246 257 if r:
247 258 tool, toolpath, binary, symlink = toolconf
248 259 a, b, c, back = files
249 260 out = ""
250 261 env = {'HG_FILE': fcd.path(),
251 262 'HG_MY_NODE': short(mynode),
252 263 'HG_OTHER_NODE': str(fco.changectx()),
253 264 'HG_BASE_NODE': str(fca.changectx()),
254 265 'HG_MY_ISLINK': 'l' in fcd.flags(),
255 266 'HG_OTHER_ISLINK': 'l' in fco.flags(),
256 267 'HG_BASE_ISLINK': 'l' in fca.flags(),
257 268 }
258 269
259 270 ui = repo.ui
260 271
261 272 args = _toolstr(ui, tool, "args", '$local $base $other')
262 273 if "$output" in args:
263 274 out, a = a, back # read input from backup, write to original
264 275 replace = {'local': a, 'base': b, 'other': c, 'output': out}
265 276 args = util.interpolate(r'\$', replace, args,
266 277 lambda s: util.shellquote(util.localpath(s)))
267 278 r = util.system(toolpath + ' ' + args, cwd=repo.root, environ=env,
268 279 out=ui.fout)
269 280 return True, r
270 281 return False, 0
271 282
272 283 def _formatconflictmarker(repo, ctx, template, label, pad):
273 284 """Applies the given template to the ctx, prefixed by the label.
274 285
275 286 Pad is the minimum width of the label prefix, so that multiple markers
276 287 can have aligned templated parts.
277 288 """
278 289 if ctx.node() is None:
279 290 ctx = ctx.p1()
280 291
281 292 props = templatekw.keywords.copy()
282 293 props['templ'] = template
283 294 props['ctx'] = ctx
284 295 props['repo'] = repo
285 296 templateresult = template('conflictmarker', **props)
286 297
287 298 label = ('%s:' % label).ljust(pad + 1)
288 299 mark = '%s %s' % (label, templater.stringify(templateresult))
289 300
290 301 if mark:
291 302 mark = mark.splitlines()[0] # split for safety
292 303
293 304 # 8 for the prefix of conflict marker lines (e.g. '<<<<<<< ')
294 305 return util.ellipsis(mark, 80 - 8)
295 306
296 307 _defaultconflictmarker = ('{node|short} ' +
297 308 '{ifeq(tags, "tip", "", "{tags} ")}' +
298 309 '{if(bookmarks, "{bookmarks} ")}' +
299 310 '{ifeq(branch, "default", "", "{branch} ")}' +
300 311 '- {author|user}: {desc|firstline}')
301 312
302 313 _defaultconflictlabels = ['local', 'other']
303 314
304 315 def _formatlabels(repo, fcd, fco, labels):
305 316 """Formats the given labels using the conflict marker template.
306 317
307 318 Returns a list of formatted labels.
308 319 """
309 320 cd = fcd.changectx()
310 321 co = fco.changectx()
311 322
312 323 ui = repo.ui
313 324 template = ui.config('ui', 'mergemarkertemplate', _defaultconflictmarker)
314 325 template = templater.parsestring(template, quoted=False)
315 326 tmpl = templater.templater(None, cache={ 'conflictmarker' : template })
316 327
317 328 pad = max(len(labels[0]), len(labels[1]))
318 329
319 330 return [_formatconflictmarker(repo, cd, tmpl, labels[0], pad),
320 331 _formatconflictmarker(repo, co, tmpl, labels[1], pad)]
321 332
322 333 def filemerge(repo, mynode, orig, fcd, fco, fca, labels=None):
323 334 """perform a 3-way merge in the working directory
324 335
325 336 mynode = parent node before merge
326 337 orig = original local filename before merge
327 338 fco = other file context
328 339 fca = ancestor file context
329 340 fcd = local file context for current/destination file
330 341 """
331 342
332 343 def temp(prefix, ctx):
333 344 pre = "%s~%s." % (os.path.basename(ctx.path()), prefix)
334 345 (fd, name) = tempfile.mkstemp(prefix=pre)
335 346 data = repo.wwritedata(ctx.path(), ctx.data())
336 347 f = os.fdopen(fd, "wb")
337 348 f.write(data)
338 349 f.close()
339 350 return name
340 351
341 352 if not fco.cmp(fcd): # files identical?
342 353 return None
343 354
344 355 ui = repo.ui
345 356 fd = fcd.path()
346 357 binary = fcd.isbinary() or fco.isbinary() or fca.isbinary()
347 358 symlink = 'l' in fcd.flags() + fco.flags()
348 359 tool, toolpath = _picktool(repo, ui, fd, binary, symlink)
349 360 ui.debug("picked tool '%s' for %s (binary %s symlink %s)\n" %
350 361 (tool, fd, binary, symlink))
351 362
352 363 if tool in internals:
353 364 func = internals[tool]
354 365 trymerge = func.trymerge
355 366 onfailure = func.onfailure
356 367 else:
357 368 func = _xmerge
358 369 trymerge = True
359 370 onfailure = _("merging %s failed!\n")
360 371
361 372 toolconf = tool, toolpath, binary, symlink
362 373
363 374 if not trymerge:
364 375 return func(repo, mynode, orig, fcd, fco, fca, toolconf)
365 376
366 377 a = repo.wjoin(fd)
367 378 b = temp("base", fca)
368 379 c = temp("other", fco)
369 380 back = a + ".orig"
370 381 util.copyfile(a, back)
371 382
372 383 if orig != fco.path():
373 384 ui.status(_("merging %s and %s to %s\n") % (orig, fco.path(), fd))
374 385 else:
375 386 ui.status(_("merging %s\n") % fd)
376 387
377 388 ui.debug("my %s other %s ancestor %s\n" % (fcd, fco, fca))
378 389
379 390 markerstyle = ui.config('ui', 'mergemarkers', 'basic')
380 391 if markerstyle == 'basic':
381 392 formattedlabels = _defaultconflictlabels
382 393 else:
383 394 if not labels:
384 395 labels = _defaultconflictlabels
385 396
386 397 formattedlabels = _formatlabels(repo, fcd, fco, labels)
387 398
388 399 needcheck, r = func(repo, mynode, orig, fcd, fco, fca, toolconf,
389 400 (a, b, c, back), labels=formattedlabels)
390 401 if not needcheck:
391 402 if r:
392 403 if onfailure:
393 404 ui.warn(onfailure % fd)
394 405 else:
395 406 util.unlink(back)
396 407
397 408 util.unlink(b)
398 409 util.unlink(c)
399 410 return r
400 411
401 412 if not r and (_toolbool(ui, tool, "checkconflicts") or
402 413 'conflicts' in _toollist(ui, tool, "check")):
403 414 if re.search("^(<<<<<<< .*|=======|>>>>>>> .*)$", fcd.data(),
404 415 re.MULTILINE):
405 416 r = 1
406 417
407 418 checked = False
408 419 if 'prompt' in _toollist(ui, tool, "check"):
409 420 checked = True
410 421 if ui.promptchoice(_("was merge of '%s' successful (yn)?"
411 422 "$$ &Yes $$ &No") % fd, 1):
412 423 r = 1
413 424
414 425 if not r and not checked and (_toolbool(ui, tool, "checkchanged") or
415 426 'changed' in _toollist(ui, tool, "check")):
416 427 if filecmp.cmp(a, back):
417 428 if ui.promptchoice(_(" output file %s appears unchanged\n"
418 429 "was merge successful (yn)?"
419 430 "$$ &Yes $$ &No") % fd, 1):
420 431 r = 1
421 432
422 433 if _toolbool(ui, tool, "fixeol"):
423 434 _matcheol(a, back)
424 435
425 436 if r:
426 437 if onfailure:
427 438 ui.warn(onfailure % fd)
428 439 else:
429 440 util.unlink(back)
430 441
431 442 util.unlink(b)
432 443 util.unlink(c)
433 444 return r
434 445
435 446 # tell hggettext to extract docstrings from these functions:
436 447 i18nfunctions = internals.values()
@@ -1,405 +1,606
1 1 $ hg init test
2 2 $ cd test
3 3
4 4 $ echo a > a
5 5 $ hg add a
6 6 $ hg commit -m "test"
7 7 $ hg history
8 8 changeset: 0:acb14030fe0a
9 9 tag: tip
10 10 user: test
11 11 date: Thu Jan 01 00:00:00 1970 +0000
12 12 summary: test
13 13
14 14
15 15 $ hg tag ' '
16 16 abort: tag names cannot consist entirely of whitespace
17 17 [255]
18 18
19 19 (this tests also that editor is not invoked, if '--edit' is not
20 20 specified)
21 21
22 22 $ HGEDITOR=cat hg tag "bleah"
23 23 $ hg history
24 24 changeset: 1:d4f0d2909abc
25 25 tag: tip
26 26 user: test
27 27 date: Thu Jan 01 00:00:00 1970 +0000
28 28 summary: Added tag bleah for changeset acb14030fe0a
29 29
30 30 changeset: 0:acb14030fe0a
31 31 tag: bleah
32 32 user: test
33 33 date: Thu Jan 01 00:00:00 1970 +0000
34 34 summary: test
35 35
36 36
37 37 $ echo foo >> .hgtags
38 38 $ hg tag "bleah2"
39 39 abort: working copy of .hgtags is changed (please commit .hgtags manually)
40 40 [255]
41 41
42 42 $ hg revert .hgtags
43 43 $ hg tag -r 0 x y z y y z
44 44 abort: tag names must be unique
45 45 [255]
46 46 $ hg tag tap nada dot tip
47 47 abort: the name 'tip' is reserved
48 48 [255]
49 49 $ hg tag .
50 50 abort: the name '.' is reserved
51 51 [255]
52 52 $ hg tag null
53 53 abort: the name 'null' is reserved
54 54 [255]
55 55 $ hg tag "bleah"
56 56 abort: tag 'bleah' already exists (use -f to force)
57 57 [255]
58 58 $ hg tag "blecch" "bleah"
59 59 abort: tag 'bleah' already exists (use -f to force)
60 60 [255]
61 61
62 62 $ hg tag --remove "blecch"
63 63 abort: tag 'blecch' does not exist
64 64 [255]
65 65 $ hg tag --remove "bleah" "blecch" "blough"
66 66 abort: tag 'blecch' does not exist
67 67 [255]
68 68
69 69 $ hg tag -r 0 "bleah0"
70 70 $ hg tag -l -r 1 "bleah1"
71 71 $ hg tag gack gawk gorp
72 72 $ hg tag -f gack
73 73 $ hg tag --remove gack gorp
74 74
75 75 $ hg tag "bleah "
76 76 abort: tag 'bleah' already exists (use -f to force)
77 77 [255]
78 78 $ hg tag " bleah"
79 79 abort: tag 'bleah' already exists (use -f to force)
80 80 [255]
81 81 $ hg tag " bleah"
82 82 abort: tag 'bleah' already exists (use -f to force)
83 83 [255]
84 84 $ hg tag -r 0 " bleahbleah "
85 85 $ hg tag -r 0 " bleah bleah "
86 86
87 87 $ cat .hgtags
88 88 acb14030fe0a21b60322c440ad2d20cf7685a376 bleah
89 89 acb14030fe0a21b60322c440ad2d20cf7685a376 bleah0
90 90 336fccc858a4eb69609a291105009e484a6b6b8d gack
91 91 336fccc858a4eb69609a291105009e484a6b6b8d gawk
92 92 336fccc858a4eb69609a291105009e484a6b6b8d gorp
93 93 336fccc858a4eb69609a291105009e484a6b6b8d gack
94 94 799667b6f2d9b957f73fa644a918c2df22bab58f gack
95 95 799667b6f2d9b957f73fa644a918c2df22bab58f gack
96 96 0000000000000000000000000000000000000000 gack
97 97 336fccc858a4eb69609a291105009e484a6b6b8d gorp
98 98 0000000000000000000000000000000000000000 gorp
99 99 acb14030fe0a21b60322c440ad2d20cf7685a376 bleahbleah
100 100 acb14030fe0a21b60322c440ad2d20cf7685a376 bleah bleah
101 101
102 102 $ cat .hg/localtags
103 103 d4f0d2909abc9290e2773c08837d70c1794e3f5a bleah1
104 104
105 105 tagging on a non-head revision
106 106
107 107 $ hg update 0
108 108 0 files updated, 0 files merged, 1 files removed, 0 files unresolved
109 109 $ hg tag -l localblah
110 110 $ hg tag "foobar"
111 111 abort: not at a branch head (use -f to force)
112 112 [255]
113 113 $ hg tag -f "foobar"
114 114 $ cat .hgtags
115 115 acb14030fe0a21b60322c440ad2d20cf7685a376 foobar
116 116 $ cat .hg/localtags
117 117 d4f0d2909abc9290e2773c08837d70c1794e3f5a bleah1
118 118 acb14030fe0a21b60322c440ad2d20cf7685a376 localblah
119 119
120 120 $ hg tag -l 'xx
121 121 > newline'
122 122 abort: '\n' cannot be used in a name
123 123 [255]
124 124 $ hg tag -l 'xx:xx'
125 125 abort: ':' cannot be used in a name
126 126 [255]
127 127
128 128 cloning local tags
129 129
130 130 $ cd ..
131 131 $ hg -R test log -r0:5
132 132 changeset: 0:acb14030fe0a
133 133 tag: bleah
134 134 tag: bleah bleah
135 135 tag: bleah0
136 136 tag: bleahbleah
137 137 tag: foobar
138 138 tag: localblah
139 139 user: test
140 140 date: Thu Jan 01 00:00:00 1970 +0000
141 141 summary: test
142 142
143 143 changeset: 1:d4f0d2909abc
144 144 tag: bleah1
145 145 user: test
146 146 date: Thu Jan 01 00:00:00 1970 +0000
147 147 summary: Added tag bleah for changeset acb14030fe0a
148 148
149 149 changeset: 2:336fccc858a4
150 150 tag: gawk
151 151 user: test
152 152 date: Thu Jan 01 00:00:00 1970 +0000
153 153 summary: Added tag bleah0 for changeset acb14030fe0a
154 154
155 155 changeset: 3:799667b6f2d9
156 156 user: test
157 157 date: Thu Jan 01 00:00:00 1970 +0000
158 158 summary: Added tag gack, gawk, gorp for changeset 336fccc858a4
159 159
160 160 changeset: 4:154eeb7c0138
161 161 user: test
162 162 date: Thu Jan 01 00:00:00 1970 +0000
163 163 summary: Added tag gack for changeset 799667b6f2d9
164 164
165 165 changeset: 5:b4bb47aaff09
166 166 user: test
167 167 date: Thu Jan 01 00:00:00 1970 +0000
168 168 summary: Removed tag gack, gorp
169 169
170 170 $ hg clone -q -rbleah1 test test1
171 171 $ hg -R test1 parents --style=compact
172 172 1[tip] d4f0d2909abc 1970-01-01 00:00 +0000 test
173 173 Added tag bleah for changeset acb14030fe0a
174 174
175 175 $ hg clone -q -r5 test#bleah1 test2
176 176 $ hg -R test2 parents --style=compact
177 177 5[tip] b4bb47aaff09 1970-01-01 00:00 +0000 test
178 178 Removed tag gack, gorp
179 179
180 180 $ hg clone -q -U test#bleah1 test3
181 181 $ hg -R test3 parents --style=compact
182 182
183 183 $ cd test
184 184
185 185 Issue601: hg tag doesn't do the right thing if .hgtags or localtags
186 186 doesn't end with EOL
187 187
188 188 $ python << EOF
189 189 > f = file('.hg/localtags'); last = f.readlines()[-1][:-1]; f.close()
190 190 > f = file('.hg/localtags', 'w'); f.write(last); f.close()
191 191 > EOF
192 192 $ cat .hg/localtags; echo
193 193 acb14030fe0a21b60322c440ad2d20cf7685a376 localblah
194 194 $ hg tag -l localnewline
195 195 $ cat .hg/localtags; echo
196 196 acb14030fe0a21b60322c440ad2d20cf7685a376 localblah
197 197 c2899151f4e76890c602a2597a650a72666681bf localnewline
198 198
199 199
200 200 $ python << EOF
201 201 > f = file('.hgtags'); last = f.readlines()[-1][:-1]; f.close()
202 202 > f = file('.hgtags', 'w'); f.write(last); f.close()
203 203 > EOF
204 204 $ hg ci -m'broken manual edit of .hgtags'
205 205 $ cat .hgtags; echo
206 206 acb14030fe0a21b60322c440ad2d20cf7685a376 foobar
207 207 $ hg tag newline
208 208 $ cat .hgtags; echo
209 209 acb14030fe0a21b60322c440ad2d20cf7685a376 foobar
210 210 a0eea09de1eeec777b46f2085260a373b2fbc293 newline
211 211
212 212
213 213 tag and branch using same name
214 214
215 215 $ hg branch tag-and-branch-same-name
216 216 marked working directory as branch tag-and-branch-same-name
217 217 (branches are permanent and global, did you want a bookmark?)
218 218 $ hg ci -m"discouraged"
219 219 $ hg tag tag-and-branch-same-name
220 220 warning: tag tag-and-branch-same-name conflicts with existing branch name
221 221
222 222 test custom commit messages
223 223
224 224 $ cat > editor.sh << '__EOF__'
225 225 > echo "==== before editing"
226 226 > cat "$1"
227 227 > echo "===="
228 228 > echo "custom tag message" > "$1"
229 229 > echo "second line" >> "$1"
230 230 > __EOF__
231 231
232 232 at first, test saving last-message.txt
233 233
234 234 (test that editor is not invoked before transaction starting)
235 235
236 236 $ cat > .hg/hgrc << '__EOF__'
237 237 > [hooks]
238 238 > # this failure occurs before editor invocation
239 239 > pretag.test-saving-lastmessage = false
240 240 > __EOF__
241 241 $ rm -f .hg/last-message.txt
242 242 $ HGEDITOR="\"sh\" \"`pwd`/editor.sh\"" hg tag custom-tag -e
243 243 abort: pretag.test-saving-lastmessage hook exited with status 1
244 244 [255]
245 245 $ cat .hg/last-message.txt
246 246 cat: .hg/last-message.txt: No such file or directory
247 247 [1]
248 248
249 249 (test that editor is invoked and commit message is saved into
250 250 "last-message.txt")
251 251
252 252 $ cat >> .hg/hgrc << '__EOF__'
253 253 > [hooks]
254 254 > pretag.test-saving-lastmessage =
255 255 > # this failure occurs after editor invocation
256 256 > pretxncommit.unexpectedabort = false
257 257 > __EOF__
258 258
259 259 (this tests also that editor is invoked, if '--edit' is specified,
260 260 regardless of '--message')
261 261
262 262 $ rm -f .hg/last-message.txt
263 263 $ HGEDITOR="\"sh\" \"`pwd`/editor.sh\"" hg tag custom-tag -e -m "foo bar"
264 264 ==== before editing
265 265 foo bar
266 266
267 267
268 268 HG: Enter commit message. Lines beginning with 'HG:' are removed.
269 269 HG: Leave message empty to abort commit.
270 270 HG: --
271 271 HG: user: test
272 272 HG: branch 'tag-and-branch-same-name'
273 273 HG: changed .hgtags
274 274 ====
275 275 transaction abort!
276 276 rollback completed
277 277 note: commit message saved in .hg/last-message.txt
278 278 abort: pretxncommit.unexpectedabort hook exited with status 1
279 279 [255]
280 280 $ cat .hg/last-message.txt
281 281 custom tag message
282 282 second line
283 283
284 284 $ cat >> .hg/hgrc << '__EOF__'
285 285 > [hooks]
286 286 > pretxncommit.unexpectedabort =
287 287 > __EOF__
288 288 $ hg status .hgtags
289 289 M .hgtags
290 290 $ hg revert --no-backup -q .hgtags
291 291
292 292 then, test custom commit message itself
293 293
294 294 $ HGEDITOR="\"sh\" \"`pwd`/editor.sh\"" hg tag custom-tag -e
295 295 ==== before editing
296 296 Added tag custom-tag for changeset 75a534207be6
297 297
298 298
299 299 HG: Enter commit message. Lines beginning with 'HG:' are removed.
300 300 HG: Leave message empty to abort commit.
301 301 HG: --
302 302 HG: user: test
303 303 HG: branch 'tag-and-branch-same-name'
304 304 HG: changed .hgtags
305 305 ====
306 306 $ hg log -l1 --template "{desc}\n"
307 307 custom tag message
308 308 second line
309 309
310 310
311 311 local tag with .hgtags modified
312 312
313 313 $ hg tag hgtags-modified
314 314 $ hg rollback
315 315 repository tip rolled back to revision 13 (undo commit)
316 316 working directory now based on revision 13
317 317 $ hg st
318 318 M .hgtags
319 319 ? .hgtags.orig
320 320 ? editor.sh
321 321 $ hg tag --local baz
322 322 $ hg revert --no-backup .hgtags
323 323
324 324
325 325 tagging when at named-branch-head that's not a topo-head
326 326
327 327 $ hg up default
328 328 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
329 329 $ hg merge -t internal:local
330 330 0 files updated, 1 files merged, 0 files removed, 0 files unresolved
331 331 (branch merge, don't forget to commit)
332 332 $ hg ci -m 'merge named branch'
333 333 $ hg up 13
334 334 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
335 335 $ hg tag new-topo-head
336 336
337 337 tagging on null rev
338 338
339 339 $ hg up null
340 340 0 files updated, 0 files merged, 2 files removed, 0 files unresolved
341 341 $ hg tag nullrev
342 342 abort: not at a branch head (use -f to force)
343 343 [255]
344 344
345 345 $ hg init empty
346 346 $ hg tag -R empty nullrev
347 347 abort: cannot tag null revision
348 348 [255]
349 349
350 350 $ hg tag -R empty -r 00000000000 -f nulltag
351 351 abort: cannot tag null revision
352 352 [255]
353 353
354 354 $ cd ..
355 355
356 356 tagging on an uncommitted merge (issue2542)
357 357
358 358 $ hg init repo-tag-uncommitted-merge
359 359 $ cd repo-tag-uncommitted-merge
360 360 $ echo c1 > f1
361 361 $ hg ci -Am0
362 362 adding f1
363 363 $ echo c2 > f2
364 364 $ hg ci -Am1
365 365 adding f2
366 366 $ hg co -q 0
367 367 $ hg branch b1
368 368 marked working directory as branch b1
369 369 (branches are permanent and global, did you want a bookmark?)
370 370 $ hg ci -m2
371 371 $ hg up default
372 372 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
373 373 $ hg merge b1
374 374 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
375 375 (branch merge, don't forget to commit)
376 376
377 377 $ hg tag t1
378 378 abort: uncommitted merge
379 379 [255]
380 380 $ hg status
381 381 $ hg tag --rev 1 t2
382 382 abort: uncommitted merge
383 383 [255]
384 384 $ hg tag --rev 1 --local t3
385 385 $ hg tags -v
386 386 tip 2:2a156e8887cc
387 387 t3 1:c3adabd1a5f4 local
388 388
389 389 $ cd ..
390 390
391 391 commit hook on tag used to be run without write lock - issue3344
392 392
393 393 $ hg init repo-tag
394 394 $ touch repo-tag/test
395 395 $ hg -R repo-tag commit -A -m "test"
396 396 adding test
397 397 $ hg init repo-tag-target
398 398 $ hg -R repo-tag --config hooks.commit="\"hg\" push \"`pwd`/repo-tag-target\"" tag tag
399 399 pushing to $TESTTMP/repo-tag-target (glob)
400 400 searching for changes
401 401 adding changesets
402 402 adding manifests
403 403 adding file changes
404 404 added 2 changesets with 2 changes to 2 files
405 405
406 automatically merge resolvable tag conflicts (i.e. tags that differ in rank)
407 create two clones with some different tags as well as some common tags
408 check that we can merge tags that differ in rank
409
410 $ hg init repo-automatic-tag-merge
411 $ cd repo-automatic-tag-merge
412 $ echo c0 > f0
413 $ hg ci -A -m0
414 adding f0
415 $ hg tag tbase
416 $ cd ..
417 $ hg clone repo-automatic-tag-merge repo-automatic-tag-merge-clone
418 updating to branch default
419 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
420 $ cd repo-automatic-tag-merge-clone
421 $ echo c1 > f1
422 $ hg ci -A -m1
423 adding f1
424 $ hg tag t1 t2 t3
425 $ hg tag --remove t2
426 $ hg tag t5
427 $ echo c2 > f2
428 $ hg ci -A -m2
429 adding f2
430 $ hg tag -f t3
431
432 $ cd ../repo-automatic-tag-merge
433 $ echo c3 > f3
434 $ hg ci -A -m3
435 adding f3
436 $ hg tag -f t4 t5 t6
437 $ hg tag --remove t5
438 $ echo c4 > f4
439 $ hg ci -A -m4
440 adding f4
441 $ hg tag t2
442 $ hg tag -f t6
443
444 $ cd ../repo-automatic-tag-merge-clone
445 $ hg pull
446 pulling from $TESTTMP/repo-automatic-tag-merge (glob)
447 searching for changes
448 adding changesets
449 adding manifests
450 adding file changes
451 added 6 changesets with 6 changes to 3 files (+1 heads)
452 (run 'hg heads' to see heads, 'hg merge' to merge)
453 $ hg merge --tool internal:tagmerge
454 merging .hgtags
455 2 files updated, 1 files merged, 0 files removed, 0 files unresolved
456 (branch merge, don't forget to commit)
457 $ hg status
458 M .hgtags
459 M f3
460 M f4
461 $ hg resolve -l
462 R .hgtags
463 $ cat .hgtags
464 9aa4e1292a27a248f8d07339bed9931d54907be7 t4
465 9aa4e1292a27a248f8d07339bed9931d54907be7 t6
466 9aa4e1292a27a248f8d07339bed9931d54907be7 t6
467 09af2ce14077a94effef208b49a718f4836d4338 t6
468 6cee5c8f3e5b4ae1a3996d2f6489c3e08eb5aea7 tbase
469 4f3e9b90005b68b4d8a3f4355cedc302a8364f5c t1
470 929bca7b18d067cbf3844c3896319a940059d748 t2
471 4f3e9b90005b68b4d8a3f4355cedc302a8364f5c t2
472 4f3e9b90005b68b4d8a3f4355cedc302a8364f5c t3
473 4f3e9b90005b68b4d8a3f4355cedc302a8364f5c t2
474 0000000000000000000000000000000000000000 t2
475 875517b4806a848f942811a315a5bce30804ae85 t5
476 9aa4e1292a27a248f8d07339bed9931d54907be7 t5
477 9aa4e1292a27a248f8d07339bed9931d54907be7 t5
478 0000000000000000000000000000000000000000 t5
479 4f3e9b90005b68b4d8a3f4355cedc302a8364f5c t3
480 79505d5360b07e3e79d1052e347e73c02b8afa5b t3
481
482 check that the merge tried to minimize the diff witht he first merge parent
483
484 $ hg diff --git -r 'p1()' .hgtags
485 diff --git a/.hgtags b/.hgtags
486 --- a/.hgtags
487 +++ b/.hgtags
488 @@ -1,9 +1,17 @@
489 +9aa4e1292a27a248f8d07339bed9931d54907be7 t4
490 +9aa4e1292a27a248f8d07339bed9931d54907be7 t6
491 +9aa4e1292a27a248f8d07339bed9931d54907be7 t6
492 +09af2ce14077a94effef208b49a718f4836d4338 t6
493 6cee5c8f3e5b4ae1a3996d2f6489c3e08eb5aea7 tbase
494 4f3e9b90005b68b4d8a3f4355cedc302a8364f5c t1
495 +929bca7b18d067cbf3844c3896319a940059d748 t2
496 4f3e9b90005b68b4d8a3f4355cedc302a8364f5c t2
497 4f3e9b90005b68b4d8a3f4355cedc302a8364f5c t3
498 4f3e9b90005b68b4d8a3f4355cedc302a8364f5c t2
499 0000000000000000000000000000000000000000 t2
500 875517b4806a848f942811a315a5bce30804ae85 t5
501 +9aa4e1292a27a248f8d07339bed9931d54907be7 t5
502 +9aa4e1292a27a248f8d07339bed9931d54907be7 t5
503 +0000000000000000000000000000000000000000 t5
504 4f3e9b90005b68b4d8a3f4355cedc302a8364f5c t3
505 79505d5360b07e3e79d1052e347e73c02b8afa5b t3
506
507 detect merge tag conflicts
508
509 $ hg update -C -r tip
510 3 files updated, 0 files merged, 2 files removed, 0 files unresolved
511 $ hg tag t7
512 $ hg update -C -r 'first(sort(head()))'
513 3 files updated, 0 files merged, 2 files removed, 0 files unresolved
514 $ printf "%s %s\n" `hg log -r . --template "{node} t7"` >> .hgtags
515 $ hg commit -m "manually add conflicting t7 tag"
516 $ hg merge --tool internal:tagmerge
517 merging .hgtags
518 automatic .hgtags merge failed
519 the following 1 tags are in conflict: t7
520 automatic tag merging of .hgtags failed! (use 'hg resolve --tool internal:merge' or another merge tool of your choice)
521 2 files updated, 0 files merged, 0 files removed, 1 files unresolved
522 use 'hg resolve' to retry unresolved file merges or 'hg update -C .' to abandon
523 [1]
524 $ hg resolve -l
525 U .hgtags
526 $ cat .hgtags
527 6cee5c8f3e5b4ae1a3996d2f6489c3e08eb5aea7 tbase
528 4f3e9b90005b68b4d8a3f4355cedc302a8364f5c t1
529 4f3e9b90005b68b4d8a3f4355cedc302a8364f5c t2
530 4f3e9b90005b68b4d8a3f4355cedc302a8364f5c t3
531 4f3e9b90005b68b4d8a3f4355cedc302a8364f5c t2
532 0000000000000000000000000000000000000000 t2
533 875517b4806a848f942811a315a5bce30804ae85 t5
534 4f3e9b90005b68b4d8a3f4355cedc302a8364f5c t3
535 79505d5360b07e3e79d1052e347e73c02b8afa5b t3
536 ea918d56be86a4afc5a95312e8b6750e1428d9d2 t7
537
538 $ cd ..
539
540 handle the loss of tags
541
542 $ hg clone repo-automatic-tag-merge-clone repo-merge-lost-tags
543 updating to branch default
544 4 files updated, 0 files merged, 0 files removed, 0 files unresolved
545 $ cd repo-merge-lost-tags
546 $ echo c5 > f5
547 $ hg ci -A -m5
548 adding f5
549 $ hg tag -f t7
550 $ hg update -r 'p1(t7)'
551 1 files updated, 0 files merged, 1 files removed, 0 files unresolved
552 $ printf '' > .hgtags
553 $ hg commit -m 'delete all tags'
554 created new head
555 $ hg update -r 'max(t7::)'
556 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
557 $ hg merge -r tip --tool internal:tagmerge
558 merging .hgtags
559 0 files updated, 1 files merged, 0 files removed, 0 files unresolved
560 (branch merge, don't forget to commit)
561 $ hg resolve -l
562 R .hgtags
563 $ cat .hgtags
564 6cee5c8f3e5b4ae1a3996d2f6489c3e08eb5aea7 tbase
565 0000000000000000000000000000000000000000 tbase
566 4f3e9b90005b68b4d8a3f4355cedc302a8364f5c t1
567 0000000000000000000000000000000000000000 t1
568 4f3e9b90005b68b4d8a3f4355cedc302a8364f5c t2
569 4f3e9b90005b68b4d8a3f4355cedc302a8364f5c t3
570 4f3e9b90005b68b4d8a3f4355cedc302a8364f5c t2
571 0000000000000000000000000000000000000000 t2
572 875517b4806a848f942811a315a5bce30804ae85 t5
573 0000000000000000000000000000000000000000 t5
574 4f3e9b90005b68b4d8a3f4355cedc302a8364f5c t3
575 79505d5360b07e3e79d1052e347e73c02b8afa5b t3
576 0000000000000000000000000000000000000000 t3
577 ea918d56be86a4afc5a95312e8b6750e1428d9d2 t7
578 0000000000000000000000000000000000000000 t7
579 ea918d56be86a4afc5a95312e8b6750e1428d9d2 t7
580 fd3a9e394ce3afb354a496323bf68ac1755a30de t7
581
582 also check that we minimize the diff with the 1st merge parent
583
584 $ hg diff --git -r 'p1()' .hgtags
585 diff --git a/.hgtags b/.hgtags
586 --- a/.hgtags
587 +++ b/.hgtags
588 @@ -1,12 +1,17 @@
589 6cee5c8f3e5b4ae1a3996d2f6489c3e08eb5aea7 tbase
590 +0000000000000000000000000000000000000000 tbase
591 4f3e9b90005b68b4d8a3f4355cedc302a8364f5c t1
592 +0000000000000000000000000000000000000000 t1
593 4f3e9b90005b68b4d8a3f4355cedc302a8364f5c t2
594 4f3e9b90005b68b4d8a3f4355cedc302a8364f5c t3
595 4f3e9b90005b68b4d8a3f4355cedc302a8364f5c t2
596 0000000000000000000000000000000000000000 t2
597 875517b4806a848f942811a315a5bce30804ae85 t5
598 +0000000000000000000000000000000000000000 t5
599 4f3e9b90005b68b4d8a3f4355cedc302a8364f5c t3
600 79505d5360b07e3e79d1052e347e73c02b8afa5b t3
601 +0000000000000000000000000000000000000000 t3
602 ea918d56be86a4afc5a95312e8b6750e1428d9d2 t7
603 +0000000000000000000000000000000000000000 t7
604 ea918d56be86a4afc5a95312e8b6750e1428d9d2 t7
605 fd3a9e394ce3afb354a496323bf68ac1755a30de t7
606
General Comments 0
You need to be logged in to leave comments. Login now