comparison mercurial/commands.py @ 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 d436b21b20dc
children f90513a3dbcd
comparison
equal deleted inserted replaced
2030:8d9ec30d58bc 2036:c9226bcc288d
2285 2285
2286 In its default mode, it reverts any uncommitted modifications made 2286 In its default mode, it reverts any uncommitted modifications made
2287 to the named files or directories. This restores the contents of 2287 to the named files or directories. This restores the contents of
2288 the affected files to an unmodified state. 2288 the affected files to an unmodified state.
2289 2289
2290 Modified files have backup copies saved before revert. To disable 2290 Modified files are saved with a .orig suffix before reverting.
2291 backups, use --no-backup. To change the name of backup files, use 2291 To disable these backups, use --no-backup.
2292 --backup to give a format string.
2293 2292
2294 Using the -r option, it reverts the given files or directories to 2293 Using the -r option, it reverts the given files or directories to
2295 their state as of an earlier revision. This can be helpful to "roll 2294 their state as of an earlier revision. This can be helpful to "roll
2296 back" some or all of a change that should not have been committed. 2295 back" some or all of a change that should not have been committed.
2297 2296
2306 If no arguments are given, all files in the repository are reverted. 2305 If no arguments are given, all files in the repository are reverted.
2307 """ 2306 """
2308 parent = repo.dirstate.parents()[0] 2307 parent = repo.dirstate.parents()[0]
2309 node = opts['rev'] and repo.lookup(opts['rev']) or parent 2308 node = opts['rev'] and repo.lookup(opts['rev']) or parent
2310 mf = repo.manifest.read(repo.changelog.read(node)[0]) 2309 mf = repo.manifest.read(repo.changelog.read(node)[0])
2311
2312 def backup(name, exact):
2313 bakname = make_filename(repo, repo.changelog,
2314 opts['backup_name'] or '%p.orig',
2315 node=parent, pathname=name)
2316 if os.path.exists(name):
2317 # if backup already exists and is same as backup we want
2318 # to make, do nothing
2319 if os.path.exists(bakname):
2320 if repo.wread(name) == repo.wread(bakname):
2321 return
2322 raise util.Abort(_('cannot save current version of %s - '
2323 '%s exists and differs') %
2324 (name, bakname))
2325 ui.status(('saving current version of %s as %s\n') %
2326 (name, bakname))
2327 shutil.copyfile(name, bakname)
2328 shutil.copymode(name, bakname)
2329 2310
2330 wlock = repo.wlock() 2311 wlock = repo.wlock()
2331 2312
2332 entries = [] 2313 entries = []
2333 names = {} 2314 names = {}
2360 ) 2341 )
2361 2342
2362 for abs, rel, exact in entries: 2343 for abs, rel, exact in entries:
2363 def handle(xlist, dobackup): 2344 def handle(xlist, dobackup):
2364 xlist[0].append(abs) 2345 xlist[0].append(abs)
2365 if dobackup and not opts['no_backup']: 2346 if dobackup and not opts['no_backup'] and os.path.exists(rel):
2366 backup(rel, exact) 2347 bakname = "%s.orig" % rel
2348 ui.note(_('saving current version of %s as %s\n') %
2349 (rel, bakname))
2350 shutil.copyfile(rel, bakname)
2351 shutil.copymode(rel, bakname)
2367 if ui.verbose or not exact: 2352 if ui.verbose or not exact:
2368 ui.status(xlist[1] % rel) 2353 ui.status(xlist[1] % rel)
2369 for table, hitlist, misslist, backuphit, backupmiss in disptable: 2354 for table, hitlist, misslist, backuphit, backupmiss in disptable:
2370 if abs not in table: continue 2355 if abs not in table: continue
2371 # file has changed in dirstate 2356 # file has changed in dirstate
3009 ('X', 'exclude', [], _('exclude names matching the given patterns'))], 2994 ('X', 'exclude', [], _('exclude names matching the given patterns'))],
3010 _('hg rename [OPTION]... SOURCE... DEST')), 2995 _('hg rename [OPTION]... SOURCE... DEST')),
3011 "^revert": 2996 "^revert":
3012 (revert, 2997 (revert,
3013 [('r', 'rev', '', _('revision to revert to')), 2998 [('r', 'rev', '', _('revision to revert to')),
3014 ('', 'backup-name', '', _('save backup with formatted name')),
3015 ('', 'no-backup', None, _('do not save backup copies of files')), 2999 ('', 'no-backup', None, _('do not save backup copies of files')),
3016 ('I', 'include', [], _('include names matching given patterns')), 3000 ('I', 'include', [], _('include names matching given patterns')),
3017 ('X', 'exclude', [], _('exclude names matching given patterns'))], 3001 ('X', 'exclude', [], _('exclude names matching given patterns'))],
3018 _('hg revert [-r REV] [NAME]...')), 3002 _('hg revert [-r REV] [NAME]...')),
3019 "root": (root, [], _('hg root')), 3003 "root": (root, [], _('hg root')),