Mercurial > hg
changeset 2036:c9226bcc288d
Don't abort when backup files already exist. Don't allow alternative names.
Rationale:
- When the user wants to revert, he shouldn't be stopped from doing
this just because some old backups will be overwritten.
- To not clobber important files by accident, alternative names for backup
files were disabled. As the backup target now has a fixed name, the user
doesn't have to be informed about the backup copy (unless --verbose)
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Sat, 01 Apr 2006 11:58:50 +0200 |
parents | 8d9ec30d58bc |
children | f90513a3dbcd |
files | mercurial/commands.py tests/test-confused-revert.out tests/test-merge-revert.out tests/test-revert tests/test-revert.out tests/test-tag.out |
diffstat | 6 files changed, 21 insertions(+), 38 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/commands.py Fri Mar 31 10:52:56 2006 -0800 +++ b/mercurial/commands.py Sat Apr 01 11:58:50 2006 +0200 @@ -2287,9 +2287,8 @@ to the named files or directories. This restores the contents of the affected files to an unmodified state. - Modified files have backup copies saved before revert. To disable - backups, use --no-backup. To change the name of backup files, use - --backup to give a format string. + Modified files are saved with a .orig suffix before reverting. + To disable these backups, use --no-backup. Using the -r option, it reverts the given files or directories to their state as of an earlier revision. This can be helpful to "roll @@ -2309,24 +2308,6 @@ node = opts['rev'] and repo.lookup(opts['rev']) or parent mf = repo.manifest.read(repo.changelog.read(node)[0]) - def backup(name, exact): - bakname = make_filename(repo, repo.changelog, - opts['backup_name'] or '%p.orig', - node=parent, pathname=name) - if os.path.exists(name): - # if backup already exists and is same as backup we want - # to make, do nothing - if os.path.exists(bakname): - if repo.wread(name) == repo.wread(bakname): - return - raise util.Abort(_('cannot save current version of %s - ' - '%s exists and differs') % - (name, bakname)) - ui.status(('saving current version of %s as %s\n') % - (name, bakname)) - shutil.copyfile(name, bakname) - shutil.copymode(name, bakname) - wlock = repo.wlock() entries = [] @@ -2362,8 +2343,12 @@ for abs, rel, exact in entries: def handle(xlist, dobackup): xlist[0].append(abs) - if dobackup and not opts['no_backup']: - backup(rel, exact) + if dobackup and not opts['no_backup'] and os.path.exists(rel): + bakname = "%s.orig" % rel + ui.note(_('saving current version of %s as %s\n') % + (rel, bakname)) + shutil.copyfile(rel, bakname) + shutil.copymode(rel, bakname) if ui.verbose or not exact: ui.status(xlist[1] % rel) for table, hitlist, misslist, backuphit, backupmiss in disptable: @@ -3011,7 +2996,6 @@ "^revert": (revert, [('r', 'rev', '', _('revision to revert to')), - ('', 'backup-name', '', _('save backup with formatted name')), ('', 'no-backup', None, _('do not save backup copies of files')), ('I', 'include', [], _('include names matching given patterns')), ('X', 'exclude', [], _('exclude names matching given patterns'))],
--- a/tests/test-confused-revert.out Fri Mar 31 10:52:56 2006 -0800 +++ b/tests/test-confused-revert.out Sat Apr 01 11:58:50 2006 +0200 @@ -2,7 +2,6 @@ A b R a reverting... -saving current version of b as b.orig forgetting b undeleting a %%% should show b unknown and a back to normal
--- a/tests/test-merge-revert.out Fri Mar 31 10:52:56 2006 -0800 +++ b/tests/test-merge-revert.out Sat Apr 01 11:58:50 2006 +0200 @@ -3,7 +3,6 @@ 016807e6fdaf tip eb43f19ff115 eb43f19ff115+ -saving current version of file1 as file1.orig reverting file1 ? file1.orig eb43f19ff115
--- a/tests/test-revert Fri Mar 31 10:52:56 2006 -0800 +++ b/tests/test-revert Sat Apr 01 11:58:50 2006 +0200 @@ -22,16 +22,16 @@ echo %% should show b added, copy saved, and c modified hg status hg revert b -echo %% should show b unknown, b.bak unknown, and c modified +echo %% should show b unknown, b.orig unknown, and c modified hg status hg revert --no-backup c -echo %% should show unknown: b b.bak +echo %% should show unknown: b b.orig hg status -echo %% should show a b b.bak c e +echo %% should show a b b.orig c e ls -echo %% should save backup to e.0 +echo %% should verbosely save backup to e.orig echo z > e -hg revert --backup='%p.%R' +hg revert -v echo %% should say no changes needed hg revert a echo %% should say file not managed
--- a/tests/test-revert.out Fri Mar 31 10:52:56 2006 -0800 +++ b/tests/test-revert.out Sat Apr 01 11:58:50 2006 +0200 @@ -13,23 +13,25 @@ %% should show b added, copy saved, and c modified M c A b -saving current version of b as b.orig -%% should show b unknown, b.bak unknown, and c modified +%% should show b unknown, b.orig unknown, and c modified M c ? b ? b.orig -%% should show unknown: b b.bak +%% should show unknown: b b.orig ? b ? b.orig -%% should show a b b.bak c e +%% should show a b b.orig c e a b b.orig c e -%% should save backup to e.0 -saving current version of e as e.0 +%% should verbosely save backup to e.orig +saving current version of e as e.orig reverting e +resolving manifests +getting e +1 files updated, 0 files merged, 0 files removed, 0 files unresolved %% should say no changes needed no changes needed to a %% should say file not managed
--- a/tests/test-tag.out Fri Mar 31 10:52:56 2006 -0800 +++ b/tests/test-tag.out Sat Apr 01 11:58:50 2006 +0200 @@ -21,7 +21,6 @@ use of 'hg tag NAME [REV]' is deprecated, please use 'hg tag [-r REV] NAME' instead abort: use only one form to specify the revision failed -saving current version of .hgtags as .hgtags.orig use of 'hg tag NAME [REV]' is deprecated, please use 'hg tag [-r REV] NAME' instead 0acdaf8983679e0aac16e811534eb49d7ee1f2b4 bleah 0acdaf8983679e0aac16e811534eb49d7ee1f2b4 bleah0