From patchwork Mon Nov 10 01:24:47 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [1, of, 2] remove: move most of the implementation into cmdutils.remove() From: Matt Harbison X-Patchwork-Id: 6656 Message-Id: To: mercurial-devel@selenic.com Date: Sun, 09 Nov 2014 20:24:47 -0500 # HG changeset patch # User Matt Harbison # Date 1415554294 18000 # Sun Nov 09 12:31:34 2014 -0500 # Node ID cbb4fe231f72f2e677ca3e90eb018b2134bac39b # Parent 2d54aa5397cdb1c697673ba10b7618d5ac25c69e remove: move most of the implementation into cmdutils.remove() This will allow access to the reusable parts from subrepos, similar to add(), forget(), etc. diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py --- a/mercurial/cmdutil.py +++ b/mercurial/cmdutil.py @@ -2052,6 +2052,59 @@ forgot.extend(forget) return bad, forgot +def remove(ui, repo, m, after, force): + ret = 0 + s = repo.status(match=m, clean=True) + modified, added, deleted, clean = s[0], s[1], s[3], s[6] + + # warn about failure to delete explicit files/dirs + wctx = repo[None] + for f in m.files(): + if f in repo.dirstate or f in wctx.dirs(): + continue + if os.path.exists(m.rel(f)): + if os.path.isdir(m.rel(f)): + ui.warn(_('not removing %s: no tracked files\n') % m.rel(f)) + else: + ui.warn(_('not removing %s: file is untracked\n') % m.rel(f)) + # missing files will generate a warning elsewhere + ret = 1 + + if force: + list = modified + deleted + clean + added + elif after: + list = deleted + for f in modified + added + clean: + ui.warn(_('not removing %s: file still exists\n') % m.rel(f)) + ret = 1 + else: + list = deleted + clean + for f in modified: + ui.warn(_('not removing %s: file is modified (use -f' + ' to force removal)\n') % m.rel(f)) + ret = 1 + for f in added: + ui.warn(_('not removing %s: file has been marked for add' + ' (use forget to undo)\n') % m.rel(f)) + ret = 1 + + for f in sorted(list): + if ui.verbose or not m.exact(f): + ui.status(_('removing %s\n') % m.rel(f)) + + wlock = repo.wlock() + try: + if not after: + for f in list: + if f in added: + continue # we never unlink added files on remove + util.unlinkpath(repo.wjoin(f), ignoremissing=True) + repo[None].forget(list) + finally: + wlock.release() + + return ret + def cat(ui, repo, ctx, matcher, prefix, **opts): err = 1 diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -5137,62 +5137,12 @@ Returns 0 on success, 1 if any warnings encountered. """ - ret = 0 after, force = opts.get('after'), opts.get('force') if not pats and not after: raise util.Abort(_('no files specified')) m = scmutil.match(repo[None], pats, opts) - s = repo.status(match=m, clean=True) - modified, added, deleted, clean = s[0], s[1], s[3], s[6] - - # warn about failure to delete explicit files/dirs - wctx = repo[None] - for f in m.files(): - if f in repo.dirstate or f in wctx.dirs(): - continue - if os.path.exists(m.rel(f)): - if os.path.isdir(m.rel(f)): - ui.warn(_('not removing %s: no tracked files\n') % m.rel(f)) - else: - ui.warn(_('not removing %s: file is untracked\n') % m.rel(f)) - # missing files will generate a warning elsewhere - ret = 1 - - if force: - list = modified + deleted + clean + added - elif after: - list = deleted - for f in modified + added + clean: - ui.warn(_('not removing %s: file still exists\n') % m.rel(f)) - ret = 1 - else: - list = deleted + clean - for f in modified: - ui.warn(_('not removing %s: file is modified (use -f' - ' to force removal)\n') % m.rel(f)) - ret = 1 - for f in added: - ui.warn(_('not removing %s: file has been marked for add' - ' (use forget to undo)\n') % m.rel(f)) - ret = 1 - - for f in sorted(list): - if ui.verbose or not m.exact(f): - ui.status(_('removing %s\n') % m.rel(f)) - - wlock = repo.wlock() - try: - if not after: - for f in list: - if f in added: - continue # we never unlink added files on remove - util.unlinkpath(repo.wjoin(f), ignoremissing=True) - repo[None].forget(list) - finally: - wlock.release() - - return ret + return cmdutil.remove(ui, repo, m, after, force) @command('rename|move|mv', [('A', 'after', None, _('record a rename that has already occurred')),