604 # TODO: Break this import cycle somehow. (filectx -> ctx -> fileset -> |
604 # TODO: Break this import cycle somehow. (filectx -> ctx -> fileset -> |
605 # merge -> filemerge). (I suspect the fileset import is the weakest link) |
605 # merge -> filemerge). (I suspect the fileset import is the weakest link) |
606 from . import context |
606 from . import context |
607 a = _workingpath(repo, fcd) |
607 a = _workingpath(repo, fcd) |
608 back = scmutil.origpath(ui, repo, a) |
608 back = scmutil.origpath(ui, repo, a) |
609 if premerge: |
609 inworkingdir = (back.startswith(repo.wvfs.base) and not |
610 util.copyfile(a, back) |
610 back.startswith(repo.vfs.base)) |
611 return context.arbitraryfilectx(back, repo=repo) |
611 |
|
612 if isinstance(fcd, context.overlayworkingfilectx) and inworkingdir: |
|
613 # If the backup file is to be in the working directory, and we're |
|
614 # merging in-memory, we must redirect the backup to the memory context |
|
615 # so we don't disturb the working directory. |
|
616 relpath = back[len(repo.wvfs.base) + 1:] |
|
617 wctx[relpath].write(fcd.data(), fcd.flags()) |
|
618 return wctx[relpath] |
|
619 else: |
|
620 # Otherwise, write to wherever the user specified the backups should go. |
|
621 # |
|
622 # A arbitraryfilectx is returned, so we can run the same functions on |
|
623 # the backup context regardless of where it lives. |
|
624 if premerge: |
|
625 util.copyfile(a, back) |
|
626 return context.arbitraryfilectx(back, repo=repo) |
612 |
627 |
613 def _maketempfiles(repo, fco, fca): |
628 def _maketempfiles(repo, fco, fca): |
614 """Writes out `fco` and `fca` as temporary files, so an external merge |
629 """Writes out `fco` and `fca` as temporary files, so an external merge |
615 tool may use them. |
630 tool may use them. |
616 """ |
631 """ |