Removed --nothing, added --print and --print0
authorMarco Barisione <marco@barisione.org>
Fri, 26 May 2006 13:13:39 +0200
changeset 2378 6e5d40ec862d
parent 2377 626779aba9bb
child 2379 e90cff87f871
Removed --nothing, added --print and --print0
purge.py
--- a/purge.py	Tue May 16 22:36:31 2006 +0200
+++ b/purge.py	Fri May 26 13:13:39 2006 +0200
@@ -26,12 +26,13 @@
     return s
 
 class Purge(object):
-    def __init__(self, act=True, abort_on_err=False):
+    def __init__(self, act=True, abort_on_err=False, eol='\n'):
         self._repo = None
         self._ui = None
         self._hg_root = None
         self._act = act
         self._abort_on_err = abort_on_err
+        self._eol = eol
 
     def purge(self, ui, repo, dirs=None):
         self._repo = repo
@@ -71,20 +72,24 @@
         # directory.
         if self._repo.dirstate.state(relative_name) != '?':
             return
-        self._ui.note(name + '\n')
+        self._ui.note(_('Removing file %s\n') % name)
         if self._act:
             try:
                 os.remove(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(name + '\n')
+        self._ui.note(_('Removing directory %s\n') % name)
         if self._act:
             try:
                 os.rmdir(name)
             except OSError, e:
                 self._error(_('%s cannot be removed') % name)
+        else:
+            self._ui.write('%s%s' % (name, self._eol))
 
     def _relative_name(self, path):
         '''
@@ -153,16 +158,21 @@
     forgot to add to the repository. If you only want to print the list of
     files that this program would delete use the -vn options.
     '''
-    act = not opts['nothing']
+    act = not opts['print']
     abort_on_err = bool(opts['abort_on_err'])
-    p = Purge(act, abort_on_err)
+    eol = opts['print0'] and '\0' or '\n'
+    if eol == '\0':
+        # --print0 implies --print
+        act = False
+    p = Purge(act, abort_on_err, eol)
     p.purge(ui, repo, dirs)
 
 
 cmdtable = {
     'purge':    (purge,
                  [('a', 'abort-on-err', None, _('abort if an error occurs')),
-                  ('n', 'nothing',      None, _('do nothing on files, useful with --verbose')),
+                  ('p', 'print',        None, _('print the file names instead of deleting them')),
+                  ('0', 'print0',       None, _('end filenames with NUL, for use with xargs (implies -p)')),
                  ],
                  _('hg purge [OPTIONS] [DIR]'))
 }