Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/cmdutil.py @ 23289:ae5d0a22ee7e
remove: move most of the implementation into cmdutils.remove()
This will allow access to the reusable parts from subrepos, similar to add(),
forget(), etc.
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Sun, 09 Nov 2014 12:31:34 -0500 |
parents | 10697f29af2b |
children | 4165cfd67519 |
comparison
equal
deleted
inserted
replaced
23288:2b9bc7963504 | 23289:ae5d0a22ee7e |
---|---|
2050 rejected = wctx.forget(forget, prefix) | 2050 rejected = wctx.forget(forget, prefix) |
2051 bad.extend(f for f in rejected if f in match.files()) | 2051 bad.extend(f for f in rejected if f in match.files()) |
2052 forgot.extend(forget) | 2052 forgot.extend(forget) |
2053 return bad, forgot | 2053 return bad, forgot |
2054 | 2054 |
2055 def remove(ui, repo, m, after, force): | |
2056 ret = 0 | |
2057 s = repo.status(match=m, clean=True) | |
2058 modified, added, deleted, clean = s[0], s[1], s[3], s[6] | |
2059 | |
2060 # warn about failure to delete explicit files/dirs | |
2061 wctx = repo[None] | |
2062 for f in m.files(): | |
2063 if f in repo.dirstate or f in wctx.dirs(): | |
2064 continue | |
2065 if os.path.exists(m.rel(f)): | |
2066 if os.path.isdir(m.rel(f)): | |
2067 ui.warn(_('not removing %s: no tracked files\n') % m.rel(f)) | |
2068 else: | |
2069 ui.warn(_('not removing %s: file is untracked\n') % m.rel(f)) | |
2070 # missing files will generate a warning elsewhere | |
2071 ret = 1 | |
2072 | |
2073 if force: | |
2074 list = modified + deleted + clean + added | |
2075 elif after: | |
2076 list = deleted | |
2077 for f in modified + added + clean: | |
2078 ui.warn(_('not removing %s: file still exists\n') % m.rel(f)) | |
2079 ret = 1 | |
2080 else: | |
2081 list = deleted + clean | |
2082 for f in modified: | |
2083 ui.warn(_('not removing %s: file is modified (use -f' | |
2084 ' to force removal)\n') % m.rel(f)) | |
2085 ret = 1 | |
2086 for f in added: | |
2087 ui.warn(_('not removing %s: file has been marked for add' | |
2088 ' (use forget to undo)\n') % m.rel(f)) | |
2089 ret = 1 | |
2090 | |
2091 for f in sorted(list): | |
2092 if ui.verbose or not m.exact(f): | |
2093 ui.status(_('removing %s\n') % m.rel(f)) | |
2094 | |
2095 wlock = repo.wlock() | |
2096 try: | |
2097 if not after: | |
2098 for f in list: | |
2099 if f in added: | |
2100 continue # we never unlink added files on remove | |
2101 util.unlinkpath(repo.wjoin(f), ignoremissing=True) | |
2102 repo[None].forget(list) | |
2103 finally: | |
2104 wlock.release() | |
2105 | |
2106 return ret | |
2107 | |
2055 def cat(ui, repo, ctx, matcher, prefix, **opts): | 2108 def cat(ui, repo, ctx, matcher, prefix, **opts): |
2056 err = 1 | 2109 err = 1 |
2057 | 2110 |
2058 def write(path): | 2111 def write(path): |
2059 fp = makefileobj(repo, opts.get('output'), ctx.node(), | 2112 fp = makefileobj(repo, opts.get('output'), ctx.node(), |