[PATCH 08 of 13] Merge _remove_file() and _remove_dir() in a single function

Emanuele Aina faina.mail at tiscali.it
Tue Feb 27 07:06:08 UTC 2007


# HG changeset patch
# User Emanuele Aina <em at nerd.ocracy.org>
# Date 1172563536 -3600
# Node ID e19d0f6da2049c8e319e9648764d0e11c85ac5b3
# Parent  b9949d8f4dbdd6296bcf85cb5924da10d1a63558
Merge _remove_file() and _remove_dir() in a single function

diff --git a/contrib/purge/purge.py b/contrib/purge/purge.py
--- a/contrib/purge/purge.py
+++ b/contrib/purge/purge.py
@@ -49,11 +49,14 @@ class Purge(object):
         directories.sort()
 
         for f in files:
-            self._remove_file(f)
+            if f not in self._repo.dirstate:
+                self._ui.note(_('Removing file %s\n') % f)
+                self._remove(os.remove, f)
 
         for f in directories[::-1]:
             if not os.listdir(os.path.join(repo.root, f)):
-                self._remove_dir(f)
+                self._ui.note(_('Removing directory %s\n') % f)
+                self._remove(os.rmdir, f)
 
         self._repo = None
         self._ui = None
@@ -64,23 +67,10 @@ class Purge(object):
         else:
             self._ui.warn(_('warning: %s\n') % msg)
 
-    def _remove_file(self, name):
-        if name in self._repo.dirstate:
-            return
-        self._ui.note(_('Removing file %s\n') % name)
+    def _remove(self, remove_func, name):
         if self._act:
             try:
-                os.remove(os.path.join(self._repo.root, name))
-            except OSError, e:
-                self._error(_('%s cannot be removed') % name)
-        else:
-            self._ui.write('%s%s' % (name, self._eol))
-
-    def _remove_dir(self, name):
-        self._ui.note(_('Removing directory %s\n') % name)
-        if self._act:
-            try:
-                os.rmdir(os.path.join(self._repo.root, name))
+                remove_func(os.path.join(self._repo.root, name))
             except OSError, e:
                 self._error(_('%s cannot be removed') % name)
         else:



More information about the Mercurial-devel mailing list