Mercurial > public > mercurial-scm > hg
comparison mercurial/filemerge.py @ 33151:851825214aa3
filemerge: convert a couple of wvfs calls in internal mergetools to contexts
One hitch is that sometimes fcd is actually an absentfilectx which does not
expose any mutator functions. In order to still use the context functions,
we look up the underlying workingfilectx to perform the write there.
One alternate way would be to put the write functions on the absentfilectx and
have them pass-through. While this makes the callsites cleaner, we would need
to decide what its getter functions would return after this point, since
returning None for `data` (and True for `isabsent()`) might no longer be
correct after a write. I discussed with Sidd about just having the getters
raise RuntimeErrors after a mutator has been called, but we actually call
isabsent() in merge.py after running the internal merge tools.
author | Phil Cohen <phillco@fb.com> |
---|---|
date | Mon, 26 Jun 2017 22:52:15 -0700 |
parents | 2ecce24dfcd3 |
children | 0407a51b9d8c |
comparison
equal
deleted
inserted
replaced
33150:77e666f943a6 | 33151:851825214aa3 |
---|---|
296 @internaltool('other', nomerge) | 296 @internaltool('other', nomerge) |
297 def _iother(repo, mynode, orig, fcd, fco, fca, toolconf, labels=None): | 297 def _iother(repo, mynode, orig, fcd, fco, fca, toolconf, labels=None): |
298 """Uses the other `p2()` version of files as the merged version.""" | 298 """Uses the other `p2()` version of files as the merged version.""" |
299 if fco.isabsent(): | 299 if fco.isabsent(): |
300 # local changed, remote deleted -- 'deleted' picked | 300 # local changed, remote deleted -- 'deleted' picked |
301 repo.wvfs.unlinkpath(fcd.path()) | 301 _underlyingfctxifabsent(fcd).remove() |
302 deleted = True | 302 deleted = True |
303 else: | 303 else: |
304 repo.wwrite(fcd.path(), fco.data(), fco.flags()) | 304 _underlyingfctxifabsent(fcd).write(fco.data(), fco.flags()) |
305 deleted = False | 305 deleted = False |
306 return 0, deleted | 306 return 0, deleted |
307 | 307 |
308 @internaltool('fail', nomerge) | 308 @internaltool('fail', nomerge) |
309 def _ifail(repo, mynode, orig, fcd, fco, fca, toolconf, labels=None): | 309 def _ifail(repo, mynode, orig, fcd, fco, fca, toolconf, labels=None): |
311 Rather than attempting to merge files that were modified on both | 311 Rather than attempting to merge files that were modified on both |
312 branches, it marks them as unresolved. The resolve command must be | 312 branches, it marks them as unresolved. The resolve command must be |
313 used to resolve these conflicts.""" | 313 used to resolve these conflicts.""" |
314 # for change/delete conflicts write out the changed version, then fail | 314 # for change/delete conflicts write out the changed version, then fail |
315 if fcd.isabsent(): | 315 if fcd.isabsent(): |
316 repo.wwrite(fcd.path(), fco.data(), fco.flags()) | 316 _underlyingfctxifabsent(fcd).write(fco.data(), fco.flags()) |
317 return 1, False | 317 return 1, False |
318 | |
319 def _underlyingfctxifabsent(filectx): | |
320 """Sometimes when resolving, our fcd is actually an absentfilectx, but | |
321 we want to write to it (to do the resolve). This helper returns the | |
322 underyling workingfilectx in that case. | |
323 """ | |
324 if filectx.isabsent(): | |
325 return filectx.changectx()[filectx.path()] | |
326 else: | |
327 return filectx | |
318 | 328 |
319 def _premerge(repo, fcd, fco, fca, toolconf, files, labels=None): | 329 def _premerge(repo, fcd, fco, fca, toolconf, files, labels=None): |
320 tool, toolpath, binary, symlink = toolconf | 330 tool, toolpath, binary, symlink = toolconf |
321 if symlink or fcd.isabsent() or fco.isabsent(): | 331 if symlink or fcd.isabsent() or fco.isabsent(): |
322 return 1 | 332 return 1 |