changeset 6757:55c71226eceb

purge: cleanup - remove casefolding check, no longer needed - fold error function into remove - simplify eol logic - remove force logic and parameters
author Matt Mackall <mpm@selenic.com>
date Thu, 26 Jun 2008 18:44:54 -0500
parents d56ceb82cddb
children 87c704ac92d4
files hgext/purge.py tests/test-purge tests/test-purge.out
diffstat 3 files changed, 19 insertions(+), 60 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/purge.py	Thu Jun 26 15:55:23 2008 -0500
+++ b/hgext/purge.py	Thu Jun 26 18:44:54 2008 -0500
@@ -56,33 +56,24 @@
     files that this program would delete use the --print option.
     '''
     act = not opts['print']
-    abort_on_err = bool(opts['abort_on_err'])
-    eol = opts['print0'] and '\0' or '\n'
-    if eol == '\0':
-        # --print0 implies --print
-        act = False
-    force = bool(opts['force'])
-
-    def error(msg):
-        if abort_on_err:
-            raise util.Abort(msg)
-        else:
-            ui.warn(_('warning: %s\n') % msg)
+    eol = '\n'
+    if opts['print0']:
+        eol = '\0'
+        act = False # --print0 implies --print
 
     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)
+                m = _('%s cannot be removed') % name
+                if opts['abort_on_err']:
+                    raise util.Abort(m)
+                ui.warn(_('warning: %s\n') % m)
         else:
             ui.write('%s%s' % (name, eol))
 
-    if not force:
-        _check_fs(ui, repo)
-
     directories = []
-    files = []
     match = cmdutil.match(repo, dirs, opts)
     match.dir = directories.append
     status = repo.status(match=match, ignored=opts['all'], unknown=True)
@@ -99,33 +90,11 @@
             ui.note(_('Removing directory %s\n') % f)
             remove(os.rmdir, f)
 
-def _check_fs(ui, repo):
-    """Abort if there is the chance of having problems with name-mangling fs
-
-    In a name mangling filesystem (e.g. a case insensitive one)
-    dirstate.walk() can yield filenames different from the ones
-    stored in the dirstate. This already confuses the status and
-    add commands, but with purge this may cause data loss.
-
-    To prevent this, this function will abort if there are uncommitted
-    changes.
-    """
-
-    # We can't use (files, match) to do a partial walk here - we wouldn't
-    # notice a modified README file if the user ran "hg purge readme"
-    modified, added, removed, deleted = repo.status()[:4]
-    if modified or added or removed or deleted:
-        if not util.checkcase(repo.path) and not ui.quiet:
-            ui.warn(_("Purging on case-insensitive filesystems is not "
-                      "fully supported.\n"))
-        raise util.Abort(_("outstanding uncommitted changes"))
-
 cmdtable = {
     'purge|clean':
         (purge,
          [('a', 'abort-on-err', None, _('abort if an error occurs')),
           ('',  'all', None, _('purge ignored files too')),
-          ('f', 'force', None, _('purge even when there are uncommitted changes')),
           ('p', 'print', None, _('print the file names instead of deleting them')),
           ('0', 'print0', None, _('end filenames with NUL, for use with xargs'
                                   ' (implies -p)')),
--- a/tests/test-purge	Thu Jun 26 15:55:23 2008 -0500
+++ b/tests/test-purge	Thu Jun 26 18:44:54 2008 -0500
@@ -83,23 +83,15 @@
 rm r1
 # hide error messages to avoid changing the output when the text changes
 hg purge -p 2> /dev/null
-if [ $? -ne 0 ]; then
-    echo "refused to run"
-fi
-if [ -f untracked_file ]; then
-    echo "untracked_file still around"
-fi
-hg purge -p --force
+hg st
+
+hg purge -p
 hg purge -v 2> /dev/null
-if [ $? -ne 0 ]; then
-    echo "refused to run"
-fi
-if [ -f untracked_file ]; then
-    echo "untracked_file still around"
-fi
-hg purge -v --force
+hg st
+
+hg purge -v
 hg revert --all --quiet
-ls
+hg st -a
 
 echo '% tracked file in ignored directory (issue621)'
 echo directory >> .hgignore
--- a/tests/test-purge.out	Thu Jun 26 15:55:23 2008 -0500
+++ b/tests/test-purge.out	Thu Jun 26 18:44:54 2008 -0500
@@ -51,14 +51,12 @@
 directory
 r1
 % abort with missing files until we support name mangling filesystems
-refused to run
-untracked_file still around
 untracked_file
-refused to run
-untracked_file still around
+! r1
+? untracked_file
+untracked_file
 Removing file untracked_file
-directory
-r1
+! r1
 % tracked file in ignored directory (issue621)
 untracked_file
 Removing file untracked_file