# HG changeset patch # User Emanuele Aina # Date 1173213946 10800 # Node ID 1c0488b58ece7bb9f8edf5c4def82792f6359b4c # Parent 337010e50dcd34a2c1d248ae3250e604c095ad3a 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 @@ from mercurial.i18n import _ 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)) directories = [] files = [] @@ -100,8 +93,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 = {