571 |
572 |
572 Fetch user defined path from config file: [ui] origbackuppath = <path> |
573 Fetch user defined path from config file: [ui] origbackuppath = <path> |
573 Fall back to default (filepath with .orig suffix) if not specified |
574 Fall back to default (filepath with .orig suffix) if not specified |
574 ''' |
575 ''' |
575 origbackuppath = ui.config('ui', 'origbackuppath') |
576 origbackuppath = ui.config('ui', 'origbackuppath') |
576 if origbackuppath is None: |
577 if not origbackuppath: |
577 return filepath + ".orig" |
578 return filepath + ".orig" |
578 |
579 |
579 filepathfromroot = os.path.relpath(filepath, start=repo.root) |
580 # Convert filepath from an absolute path into a path inside the repo. |
580 fullorigpath = repo.wjoin(origbackuppath, filepathfromroot) |
581 filepathfromroot = util.normpath(os.path.relpath(filepath, |
581 |
582 start=repo.root)) |
582 origbackupdir = repo.vfs.dirname(fullorigpath) |
583 |
583 if not repo.vfs.exists(origbackupdir): |
584 origvfs = vfs.vfs(repo.wjoin(origbackuppath)) |
584 ui.note(_('creating directory: %s\n') % origbackupdir) |
585 origbackupdir = origvfs.dirname(filepathfromroot) |
585 util.makedirs(origbackupdir) |
586 if not origvfs.isdir(origbackupdir) or origvfs.islink(origbackupdir): |
586 |
587 ui.note(_('creating directory: %s\n') % origvfs.join(origbackupdir)) |
587 return fullorigpath |
588 |
|
589 # Remove any files that conflict with the backup file's path |
|
590 for f in reversed(list(util.finddirs(filepathfromroot))): |
|
591 if origvfs.isfileorlink(f): |
|
592 ui.note(_('removing conflicting file: %s\n') |
|
593 % origvfs.join(f)) |
|
594 origvfs.unlink(f) |
|
595 break |
|
596 |
|
597 origvfs.makedirs(origbackupdir) |
|
598 |
|
599 if origvfs.isdir(filepathfromroot): |
|
600 ui.note(_('removing conflicting directory: %s\n') |
|
601 % origvfs.join(filepathfromroot)) |
|
602 origvfs.rmtree(filepathfromroot, forcibly=True) |
|
603 |
|
604 return origvfs.join(filepathfromroot) |
588 |
605 |
589 class _containsnode(object): |
606 class _containsnode(object): |
590 """proxy __contains__(node) to container.__contains__ which accepts revs""" |
607 """proxy __contains__(node) to container.__contains__ which accepts revs""" |
591 |
608 |
592 def __init__(self, repo, revcontainer): |
609 def __init__(self, repo, revcontainer): |