mercurial/commands.py
changeset 2503 37655f10ced6
parent 2494 73ac95671788
child 2510 cbff06469488
equal deleted inserted replaced
2502:18cf95ad3666 2503:37655f10ced6
   648                 ui.status(_('adding %s\n') % rel)
   648                 ui.status(_('adding %s\n') % rel)
   649             names.append(abs)
   649             names.append(abs)
   650         elif repo.dirstate.state(abs) == '?':
   650         elif repo.dirstate.state(abs) == '?':
   651             ui.status(_('adding %s\n') % rel)
   651             ui.status(_('adding %s\n') % rel)
   652             names.append(abs)
   652             names.append(abs)
   653     if not opts['dry_run']:
   653     if not opts.get('dry_run'):
   654         repo.add(names)
   654         repo.add(names)
   655 
   655 
   656 def addremove(ui, repo, *pats, **opts):
   656 def addremove(ui, repo, *pats, **opts):
   657     """add all new files, delete all missing files (DEPRECATED)
   657     """add all new files, delete all missing files (DEPRECATED)
   658 
   658 
  1074             opts['after'] and repo.dirstate.state(abstarget) not in '?r'):
  1074             opts['after'] and repo.dirstate.state(abstarget) not in '?r'):
  1075             if not opts['force']:
  1075             if not opts['force']:
  1076                 ui.warn(_('%s: not overwriting - file exists\n') %
  1076                 ui.warn(_('%s: not overwriting - file exists\n') %
  1077                         reltarget)
  1077                         reltarget)
  1078                 return
  1078                 return
  1079             if not opts['after'] and not opts['dry_run']:
  1079             if not opts['after'] and not opts.get('dry_run'):
  1080                 os.unlink(reltarget)
  1080                 os.unlink(reltarget)
  1081         if opts['after']:
  1081         if opts['after']:
  1082             if not os.path.exists(reltarget):
  1082             if not os.path.exists(reltarget):
  1083                 return
  1083                 return
  1084         else:
  1084         else:
  1085             targetdir = os.path.dirname(reltarget) or '.'
  1085             targetdir = os.path.dirname(reltarget) or '.'
  1086             if not os.path.isdir(targetdir) and not opts['dry_run']:
  1086             if not os.path.isdir(targetdir) and not opts.get('dry_run'):
  1087                 os.makedirs(targetdir)
  1087                 os.makedirs(targetdir)
  1088             try:
  1088             try:
  1089                 restore = repo.dirstate.state(abstarget) == 'r'
  1089                 restore = repo.dirstate.state(abstarget) == 'r'
  1090                 if restore and not opts['dry_run']:
  1090                 if restore and not opts.get('dry_run'):
  1091                     repo.undelete([abstarget], wlock)
  1091                     repo.undelete([abstarget], wlock)
  1092                 try:
  1092                 try:
  1093                     if not opts['dry_run']:
  1093                     if not opts.get('dry_run'):
  1094                         shutil.copyfile(relsrc, reltarget)
  1094                         shutil.copyfile(relsrc, reltarget)
  1095                         shutil.copymode(relsrc, reltarget)
  1095                         shutil.copymode(relsrc, reltarget)
  1096                     restore = False
  1096                     restore = False
  1097                 finally:
  1097                 finally:
  1098                     if restore:
  1098                     if restore:
  1108                     errors += 1
  1108                     errors += 1
  1109                     return
  1109                     return
  1110         if ui.verbose or not exact:
  1110         if ui.verbose or not exact:
  1111             ui.status(_('copying %s to %s\n') % (relsrc, reltarget))
  1111             ui.status(_('copying %s to %s\n') % (relsrc, reltarget))
  1112         targets[abstarget] = abssrc
  1112         targets[abstarget] = abssrc
  1113         if abstarget != origsrc and not opts['dry_run']:
  1113         if abstarget != origsrc and not opts.get('dry_run'):
  1114             repo.copy(origsrc, abstarget, wlock)
  1114             repo.copy(origsrc, abstarget, wlock)
  1115         copied.append((abssrc, relsrc, exact))
  1115         copied.append((abssrc, relsrc, exact))
  1116 
  1116 
  1117     def targetpathfn(pat, dest, srcs):
  1117     def targetpathfn(pat, dest, srcs):
  1118         if os.path.isdir(pat):
  1118         if os.path.isdir(pat):
  2332     names = []
  2332     names = []
  2333     for abs, rel, exact in copied:
  2333     for abs, rel, exact in copied:
  2334         if ui.verbose or not exact:
  2334         if ui.verbose or not exact:
  2335             ui.status(_('removing %s\n') % rel)
  2335             ui.status(_('removing %s\n') % rel)
  2336         names.append(abs)
  2336         names.append(abs)
  2337     if not opts['dry_run']:
  2337     if not opts.get('dry_run'):
  2338         repo.remove(names, True, wlock)
  2338         repo.remove(names, True, wlock)
  2339     return errs
  2339     return errs
  2340 
  2340 
  2341 def revert(ui, repo, *pats, **opts):
  2341 def revert(ui, repo, *pats, **opts):
  2342     """revert files or dirs to their states as of some revision
  2342     """revert files or dirs to their states as of some revision