[PATCH 11 of 13] Delete the Purge class, refactoring Purge.purge() in dopurge()
Emanuele Aina
faina.mail at tiscali.it
Tue Feb 27 07:06:11 UTC 2007
# HG changeset patch
# User Emanuele Aina <em at nerd.ocracy.org>
# Date 1172563536 -3600
# Node ID 8bea9bf75cb80394032f141636cd297b99ac58f4
# Parent b51b8152e1d9f784660b44be57b46fea796da162
Delete the Purge class, refactoring Purge.purge() in dopurge()
diff --git a/contrib/purge/purge.py b/contrib/purge/purge.py
--- a/contrib/purge/purge.py
+++ b/contrib/purge/purge.py
@@ -21,50 +21,46 @@ from mercurial.i18n import _
from mercurial.i18n import _
import os
-class Purge(object):
- def __init__(self):
- pass
+def dopurge(ui, repo, dirs=None, act=True, abort_on_err=False, eol='\n'):
+ def error(msg):
+ if abort_on_err:
+ raise util.Abort(msg)
+ else:
+ ui.warn(_('warning: %s\n') % msg)
- def purge(self, ui, repo, dirs=None, act=True, abort_on_err=False, eol='\n'):
- def error(msg):
- if abort_on_err:
- raise util.Abort(msg)
- else:
- ui.warn(_('warning: %s\n') % msg)
+ def remove(remove_func, name):
+ if act:
+ try:
+ remove_func(os.path.join(repo.root, name))
+ except OSError, e:
+ error(_('%s cannot be removed') % name)
+ else:
+ ui.write('%s%s' % (name, eol))
- def remove(remove_func, name):
- if act:
- try:
- remove_func(os.path.join(repo.root, name))
- except OSError, e:
- error(_('%s cannot be removed') % name)
- else:
- ui.write('%s%s' % (name, eol))
+ if not dirs:
+ dirs = [repo.root]
+
+ directories = []
+ files = []
+ for path in dirs:
+ path = os.path.abspath(path)
+ for src, f, st in repo.dirstate.statwalk():
+ if src == 'd':
+ directories.append(f)
+ elif src == 'f' and src not in repo.dirstate:
+ files.append(f)
- if not dirs:
- dirs = [repo.root]
-
- directories = []
- files = []
- for path in dirs:
- path = os.path.abspath(path)
- for src, f, st in repo.dirstate.statwalk():
- if src == 'd':
- directories.append(f)
- elif src == 'f' and src not in repo.dirstate:
- files.append(f)
+ directories.sort()
- directories.sort()
+ for f in files:
+ if f not in repo.dirstate:
+ ui.note(_('Removing file %s\n') % f)
+ remove(os.remove, f)
- for f in files:
- if f not in repo.dirstate:
- ui.note(_('Removing file %s\n') % f)
- remove(os.remove, f)
-
- for f in directories[::-1]:
- if not os.listdir(os.path.join(repo.root, f)):
- ui.note(_('Removing directory %s\n') % f)
- remove(os.rmdir, f)
+ for f in directories[::-1]:
+ if not os.listdir(os.path.join(repo.root, f)):
+ ui.note(_('Removing directory %s\n') % f)
+ remove(os.rmdir, f)
def purge(ui, repo, *dirs, **opts):
@@ -97,8 +93,7 @@ def purge(ui, repo, *dirs, **opts):
if eol == '\0':
# --print0 implies --print
act = False
- p = Purge()
- p.purge(ui, repo, dirs, act, abort_on_err, eol)
+ dopurge(ui, repo, dirs, act, abort_on_err, eol)
cmdtable = {
More information about the Mercurial-devel
mailing list