comparison mercurial/filemerge.py @ 21273:20b8090d8125

merge: define conflict marker labels in filemerge() Moves the conflict marker definition up to filemerge, so it gets applied to all merge strategies, and so in a future patch we can manipulate the markers.
author Durham Goode <durham@fb.com>
date Thu, 08 May 2014 16:37:33 -0700
parents 098a274764b3
children 25d5a9ecbb85
comparison
equal deleted inserted replaced
21272:4aeb7a6029ba 21273:20b8090d8125
167 Rather than attempting to merge files that were modified on both 167 Rather than attempting to merge files that were modified on both
168 branches, it marks them as unresolved. The resolve command must be 168 branches, it marks them as unresolved. The resolve command must be
169 used to resolve these conflicts.""" 169 used to resolve these conflicts."""
170 return 1 170 return 1
171 171
172 def _premerge(repo, toolconf, files): 172 def _premerge(repo, toolconf, files, labels=None):
173 tool, toolpath, binary, symlink = toolconf 173 tool, toolpath, binary, symlink = toolconf
174 if symlink: 174 if symlink:
175 return 1 175 return 1
176 a, b, c, back = files 176 a, b, c, back = files
177 177
188 raise error.ConfigError(_("%s.premerge not valid " 188 raise error.ConfigError(_("%s.premerge not valid "
189 "('%s' is neither boolean nor %s)") % 189 "('%s' is neither boolean nor %s)") %
190 (tool, premerge, _valid)) 190 (tool, premerge, _valid))
191 191
192 if premerge: 192 if premerge:
193 r = simplemerge.simplemerge(ui, a, b, c, quiet=True) 193 r = simplemerge.simplemerge(ui, a, b, c, quiet=True, label=labels)
194 if not r: 194 if not r:
195 ui.debug(" premerge successful\n") 195 ui.debug(" premerge successful\n")
196 return 0 196 return 0
197 if premerge != 'keep': 197 if premerge != 'keep':
198 util.copyfile(back, a) # restore from backup and try again 198 util.copyfile(back, a) # restore from backup and try again
199 return 1 # continue merging 199 return 1 # continue merging
200 200
201 @internaltool('merge', True, 201 @internaltool('merge', True,
202 _("merging %s incomplete! " 202 _("merging %s incomplete! "
203 "(edit conflicts, then use 'hg resolve --mark')\n")) 203 "(edit conflicts, then use 'hg resolve --mark')\n"))
204 def _imerge(repo, mynode, orig, fcd, fco, fca, toolconf, files): 204 def _imerge(repo, mynode, orig, fcd, fco, fca, toolconf, files, labels=None):
205 """ 205 """
206 Uses the internal non-interactive simple merge algorithm for merging 206 Uses the internal non-interactive simple merge algorithm for merging
207 files. It will fail if there are any conflicts and leave markers in 207 files. It will fail if there are any conflicts and leave markers in
208 the partially merged file.""" 208 the partially merged file."""
209 tool, toolpath, binary, symlink = toolconf 209 tool, toolpath, binary, symlink = toolconf
210 if symlink: 210 if symlink:
211 repo.ui.warn(_('warning: internal:merge cannot merge symlinks ' 211 repo.ui.warn(_('warning: internal:merge cannot merge symlinks '
212 'for %s\n') % fcd.path()) 212 'for %s\n') % fcd.path())
213 return False, 1 213 return False, 1
214 214 r = _premerge(repo, toolconf, files, labels=labels)
215 r = _premerge(repo, toolconf, files)
216 if r: 215 if r:
217 a, b, c, back = files 216 a, b, c, back = files
218 217
219 ui = repo.ui 218 ui = repo.ui
220 219
221 r = simplemerge.simplemerge(ui, a, b, c, label=['local', 'other']) 220 r = simplemerge.simplemerge(ui, a, b, c, label=labels)
222 return True, r 221 return True, r
223 return False, 0 222 return False, 0
224 223
225 @internaltool('dump', True) 224 @internaltool('dump', True)
226 def _idump(repo, mynode, orig, fcd, fco, fca, toolconf, files): 225 def _idump(repo, mynode, orig, fcd, fco, fca, toolconf, files, labels=None):
227 """ 226 """
228 Creates three versions of the files to merge, containing the 227 Creates three versions of the files to merge, containing the
229 contents of local, other and base. These files can then be used to 228 contents of local, other and base. These files can then be used to
230 perform a merge manually. If the file to be merged is named 229 perform a merge manually. If the file to be merged is named
231 ``a.txt``, these files will accordingly be named ``a.txt.local``, 230 ``a.txt``, these files will accordingly be named ``a.txt.local``,
232 ``a.txt.other`` and ``a.txt.base`` and they will be placed in the 231 ``a.txt.other`` and ``a.txt.base`` and they will be placed in the
233 same directory as ``a.txt``.""" 232 same directory as ``a.txt``."""
234 r = _premerge(repo, toolconf, files) 233 r = _premerge(repo, toolconf, files, labels=labels)
235 if r: 234 if r:
236 a, b, c, back = files 235 a, b, c, back = files
237 236
238 fd = fcd.path() 237 fd = fcd.path()
239 238
240 util.copyfile(a, a + ".local") 239 util.copyfile(a, a + ".local")
241 repo.wwrite(fd + ".other", fco.data(), fco.flags()) 240 repo.wwrite(fd + ".other", fco.data(), fco.flags())
242 repo.wwrite(fd + ".base", fca.data(), fca.flags()) 241 repo.wwrite(fd + ".base", fca.data(), fca.flags())
243 return False, r 242 return False, r
244 243
245 def _xmerge(repo, mynode, orig, fcd, fco, fca, toolconf, files): 244 def _xmerge(repo, mynode, orig, fcd, fco, fca, toolconf, files, labels=None):
246 r = _premerge(repo, toolconf, files) 245 r = _premerge(repo, toolconf, files, labels=labels)
247 if r: 246 if r:
248 tool, toolpath, binary, symlink = toolconf 247 tool, toolpath, binary, symlink = toolconf
249 a, b, c, back = files 248 a, b, c, back = files
250 out = "" 249 out = ""
251 env = {'HG_FILE': fcd.path(), 250 env = {'HG_FILE': fcd.path(),
325 else: 324 else:
326 ui.status(_("merging %s\n") % fd) 325 ui.status(_("merging %s\n") % fd)
327 326
328 ui.debug("my %s other %s ancestor %s\n" % (fcd, fco, fca)) 327 ui.debug("my %s other %s ancestor %s\n" % (fcd, fco, fca))
329 328
329 labels = ['local', 'other']
330 needcheck, r = func(repo, mynode, orig, fcd, fco, fca, toolconf, 330 needcheck, r = func(repo, mynode, orig, fcd, fco, fca, toolconf,
331 (a, b, c, back)) 331 (a, b, c, back), labels=labels)
332 if not needcheck: 332 if not needcheck:
333 if r: 333 if r:
334 if onfailure: 334 if onfailure:
335 ui.warn(onfailure % fd) 335 ui.warn(onfailure % fd)
336 else: 336 else: