[PATCH 10 of 13] Do not use 'self' in the purge() method
Emanuele Aina
faina.mail at tiscali.it
Tue Feb 27 07:06:10 UTC 2007
# HG changeset patch
# User Emanuele Aina <em at nerd.ocracy.org>
# Date 1172563536 -3600
# Node ID b51b8152e1d9f784660b44be57b46fea796da162
# Parent 0f9e732424724ad3ea74dc730b8440494bcc19b2
Do not use 'self' in the purge() method
Avoid any reference to 'self' in Purge.purge() to allow its refactoring
in a simple function.
diff --git a/contrib/purge/purge.py b/contrib/purge/purge.py
--- a/contrib/purge/purge.py
+++ b/contrib/purge/purge.py
@@ -22,31 +22,24 @@ import os
import os
class Purge(object):
- def __init__(self, act=True, abort_on_err=False, eol='\n'):
- self._repo = None
- self._ui = None
- self._act = act
- self._abort_on_err = abort_on_err
- self._eol = eol
+ def __init__(self):
+ pass
- def purge(self, ui, repo, dirs=None):
- self._repo = repo
- self._ui = ui
-
- def error(self, msg):
- if self._abort_on_err:
+ 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:
- self._ui.warn(_('warning: %s\n') % msg)
+ ui.warn(_('warning: %s\n') % msg)
def remove(remove_func, name):
- if self._act:
+ if act:
try:
- remove_func(os.path.join(self._repo.root, name))
+ remove_func(os.path.join(repo.root, name))
except OSError, e:
error(_('%s cannot be removed') % name)
else:
- self._ui.write('%s%s' % (name, self._eol))
+ ui.write('%s%s' % (name, eol))
if not dirs:
dirs = [repo.root]
@@ -64,18 +57,14 @@ class Purge(object):
directories.sort()
for f in files:
- if f not in self._repo.dirstate:
- self._ui.note(_('Removing file %s\n') % f)
+ 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)):
- self._ui.note(_('Removing directory %s\n') % f)
+ ui.note(_('Removing directory %s\n') % f)
remove(os.rmdir, f)
-
- self._repo = None
- self._ui = None
-
def purge(ui, repo, *dirs, **opts):
@@ -108,8 +97,8 @@ def purge(ui, repo, *dirs, **opts):
if eol == '\0':
# --print0 implies --print
act = False
- p = Purge(act, abort_on_err, eol)
- p.purge(ui, repo, dirs)
+ p = Purge()
+ p.purge(ui, repo, dirs, act, abort_on_err, eol)
cmdtable = {
More information about the Mercurial-devel
mailing list