Skip to content
Snippets Groups Projects
Commit 55c71226 authored by Matt Mackall's avatar Matt Mackall
Browse files

purge: cleanup

- remove casefolding check, no longer needed
- fold error function into remove
- simplify eol logic
- remove force logic and parameters
parent d56ceb82
No related branches found
No related tags found
No related merge requests found
......@@ -56,21 +56,13 @@
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:
......@@ -71,10 +63,13 @@
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))
......@@ -78,7 +73,4 @@
else:
ui.write('%s%s' % (name, eol))
if not force:
_check_fs(ui, repo)
directories = []
......@@ -84,5 +76,4 @@
directories = []
files = []
match = cmdutil.match(repo, dirs, opts)
match.dir = directories.append
status = repo.status(match=match, ignored=opts['all'], unknown=True)
......@@ -99,29 +90,8 @@
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')),
......@@ -123,9 +93,8 @@
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)')),
......
......@@ -83,11 +83,7 @@
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
......@@ -93,9 +89,5 @@
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
......@@ -101,5 +93,5 @@
hg revert --all --quiet
ls
hg st -a
echo '% tracked file in ignored directory (issue621)'
echo directory >> .hgignore
......
......@@ -51,6 +51,4 @@
directory
r1
% abort with missing files until we support name mangling filesystems
refused to run
untracked_file still around
untracked_file
......@@ -56,4 +54,5 @@
untracked_file
refused to run
untracked_file still around
! r1
? untracked_file
untracked_file
Removing file untracked_file
......@@ -59,6 +58,5 @@
Removing file untracked_file
directory
r1
! r1
% tracked file in ignored directory (issue621)
untracked_file
Removing file untracked_file
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment