Mercurial > hg > mercurial-crew-with-dirclash
comparison mercurial/commands.py @ 2414:86e07466bcfc
remove: add -n/--dry-run option
author | Vadim Gelfer <vadim.gelfer@gmail.com> |
---|---|
date | Fri, 09 Jun 2006 09:00:08 -0700 |
parents | c1ec81319870 |
children | dec79ed61ee1 |
comparison
equal
deleted
inserted
replaced
2413:c1ec81319870 | 2414:86e07466bcfc |
---|---|
1053 opts['after'] and repo.dirstate.state(abstarget) not in '?r'): | 1053 opts['after'] and repo.dirstate.state(abstarget) not in '?r'): |
1054 if not opts['force']: | 1054 if not opts['force']: |
1055 ui.warn(_('%s: not overwriting - file exists\n') % | 1055 ui.warn(_('%s: not overwriting - file exists\n') % |
1056 reltarget) | 1056 reltarget) |
1057 return | 1057 return |
1058 if not opts['after']: | 1058 if not opts['after'] and not opts['dry_run']: |
1059 os.unlink(reltarget) | 1059 os.unlink(reltarget) |
1060 if opts['after']: | 1060 if opts['after']: |
1061 if not os.path.exists(reltarget): | 1061 if not os.path.exists(reltarget): |
1062 return | 1062 return |
1063 else: | 1063 else: |
1064 targetdir = os.path.dirname(reltarget) or '.' | 1064 targetdir = os.path.dirname(reltarget) or '.' |
1065 if not os.path.isdir(targetdir): | 1065 if not os.path.isdir(targetdir) and not opts['dry_run']: |
1066 os.makedirs(targetdir) | 1066 os.makedirs(targetdir) |
1067 try: | 1067 try: |
1068 restore = repo.dirstate.state(abstarget) == 'r' | 1068 restore = repo.dirstate.state(abstarget) == 'r' |
1069 if restore: | 1069 if restore and not dry_run: |
1070 repo.undelete([abstarget], wlock) | 1070 repo.undelete([abstarget], wlock) |
1071 try: | 1071 try: |
1072 shutil.copyfile(relsrc, reltarget) | 1072 if not opts['dry_run']: |
1073 shutil.copymode(relsrc, reltarget) | 1073 shutil.copyfile(relsrc, reltarget) |
1074 shutil.copymode(relsrc, reltarget) | |
1074 restore = False | 1075 restore = False |
1075 finally: | 1076 finally: |
1076 if restore: | 1077 if restore: |
1077 repo.remove([abstarget], wlock) | 1078 repo.remove([abstarget], wlock) |
1078 except shutil.Error, inst: | 1079 except shutil.Error, inst: |
1086 errors += 1 | 1087 errors += 1 |
1087 return | 1088 return |
1088 if ui.verbose or not exact: | 1089 if ui.verbose or not exact: |
1089 ui.status(_('copying %s to %s\n') % (relsrc, reltarget)) | 1090 ui.status(_('copying %s to %s\n') % (relsrc, reltarget)) |
1090 targets[abstarget] = abssrc | 1091 targets[abstarget] = abssrc |
1091 if abstarget != origsrc: | 1092 if abstarget != origsrc and not opts['dry_run']: |
1092 repo.copy(origsrc, abstarget, wlock) | 1093 repo.copy(origsrc, abstarget, wlock) |
1093 copied.append((abssrc, relsrc, exact)) | 1094 copied.append((abssrc, relsrc, exact)) |
1094 | 1095 |
1095 def targetpathfn(pat, dest, srcs): | 1096 def targetpathfn(pat, dest, srcs): |
1096 if os.path.isdir(pat): | 1097 if os.path.isdir(pat): |
1170 continue | 1171 continue |
1171 copylist.append((tfn(pat, dest, srcs), srcs)) | 1172 copylist.append((tfn(pat, dest, srcs), srcs)) |
1172 if not copylist: | 1173 if not copylist: |
1173 raise util.Abort(_('no files to copy')) | 1174 raise util.Abort(_('no files to copy')) |
1174 | 1175 |
1175 if not opts.get('dry_run'): | 1176 for targetpath, srcs in copylist: |
1176 for targetpath, srcs in copylist: | 1177 for origsrc, abssrc, relsrc, exact in srcs: |
1177 for origsrc, abssrc, relsrc, exact in srcs: | 1178 copy(origsrc, abssrc, relsrc, targetpath(abssrc), exact) |
1178 copy(origsrc, abssrc, relsrc, targetpath(abssrc), exact) | |
1179 | 1179 |
1180 if errors: | 1180 if errors: |
1181 ui.warn(_('(consider using --after)\n')) | 1181 ui.warn(_('(consider using --after)\n')) |
1182 return errors, copied | 1182 return errors, copied |
1183 | 1183 |
2307 names = [] | 2307 names = [] |
2308 for abs, rel, exact in copied: | 2308 for abs, rel, exact in copied: |
2309 if ui.verbose or not exact: | 2309 if ui.verbose or not exact: |
2310 ui.status(_('removing %s\n') % rel) | 2310 ui.status(_('removing %s\n') % rel) |
2311 names.append(abs) | 2311 names.append(abs) |
2312 repo.remove(names, True, wlock) | 2312 if not opts['dry_run']: |
2313 repo.remove(names, True, wlock) | |
2313 return errs | 2314 return errs |
2314 | 2315 |
2315 def revert(ui, repo, *pats, **opts): | 2316 def revert(ui, repo, *pats, **opts): |
2316 """revert files or dirs to their states as of some revision | 2317 """revert files or dirs to their states as of some revision |
2317 | 2318 |
3064 (rename, | 3065 (rename, |
3065 [('A', 'after', None, _('record a rename that has already occurred')), | 3066 [('A', 'after', None, _('record a rename that has already occurred')), |
3066 ('f', 'force', None, | 3067 ('f', 'force', None, |
3067 _('forcibly copy over an existing managed file')), | 3068 _('forcibly copy over an existing managed file')), |
3068 ('I', 'include', [], _('include names matching the given patterns')), | 3069 ('I', 'include', [], _('include names matching the given patterns')), |
3069 ('X', 'exclude', [], _('exclude names matching the given patterns'))], | 3070 ('X', 'exclude', [], _('exclude names matching the given patterns')), |
3071 ('n', 'dry-run', None, _('print what would be done'))], | |
3070 _('hg rename [OPTION]... SOURCE... DEST')), | 3072 _('hg rename [OPTION]... SOURCE... DEST')), |
3071 "^revert": | 3073 "^revert": |
3072 (revert, | 3074 (revert, |
3073 [('r', 'rev', '', _('revision to revert to')), | 3075 [('r', 'rev', '', _('revision to revert to')), |
3074 ('', 'no-backup', None, _('do not save backup copies of files')), | 3076 ('', 'no-backup', None, _('do not save backup copies of files')), |