# HG changeset patch # User Thomas Arendsen Hein # Date 2006-04-01 09:58:50 # Node ID c9226bcc288d470a5f2944318e7eed04adb5f1f3 # Parent 8d9ec30d58bc79bfa3a4a11a006abb11deb65473 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) diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -2287,9 +2287,8 @@ def revert(ui, repo, *pats, **opts): 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 @@ def revert(ui, repo, *pats, **opts): 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 @@ def revert(ui, repo, *pats, **opts): 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 @@ table = { "^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'))], diff --git a/tests/test-confused-revert.out b/tests/test-confused-revert.out --- a/tests/test-confused-revert.out +++ b/tests/test-confused-revert.out @@ -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 diff --git a/tests/test-merge-revert.out b/tests/test-merge-revert.out --- a/tests/test-merge-revert.out +++ b/tests/test-merge-revert.out @@ -3,7 +3,6 @@ 0:eb43f19ff115 016807e6fdaf tip eb43f19ff115 eb43f19ff115+ -saving current version of file1 as file1.orig reverting file1 ? file1.orig eb43f19ff115 diff --git a/tests/test-revert b/tests/test-revert --- a/tests/test-revert +++ b/tests/test-revert @@ -22,16 +22,16 @@ hg revert a 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 diff --git a/tests/test-revert.out b/tests/test-revert.out --- a/tests/test-revert.out +++ b/tests/test-revert.out @@ -13,23 +13,25 @@ R a %% 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 diff --git a/tests/test-tag.out b/tests/test-tag.out --- a/tests/test-tag.out +++ b/tests/test-tag.out @@ -21,7 +21,6 @@ failed 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