From: Pavel Roskin <proski@gnu.org>
To: git <git@vger.kernel.org>, Petr Baudis <pasky@ucw.cz>
Subject: New script: cg-clean
Date: Fri, 08 Jul 2005 18:34:44 -0400 [thread overview]
Message-ID: <1120862084.17812.6.camel@dv> (raw)
Hello, Petr!
Please consider this script for Cogito.
Signed-off-by: Pavel Roskin <proski@gnu.org>
#!/usr/bin/env bash
#
# Clean unknown files from the working tree.
# Copyright (c) Pavel Roskin, 2005
#
# Cleans file and directories that are not under version control.
# Only regular files that are not ignored by cg-status are cleaned
# by default.
#
# OPTIONS
# -------
# -i::
# Clean files ignored by cg-status, such as object files.
#
# -s::
# Clean symlinks, fifos, sockets and other special files.
#
# -r::
# Clean directories.
#
# -R::
# Clean directories, try harder. Make directories writeable
# recursively before removing.
#
# -a::
# Clean all the above.
#
# If any other arguments are specified, they will be the only files
# considered for removal. It will also imply the `-a' option.
USAGE="cg-clean [-i] [-s] [-r] [-R] [-a] [FILE]..."
. ${COGITO_LIB}cg-Xlib
cleanexclude=
cleanspecial=
cleandir=
cleandirhard=
while optparse; do
if optparse -i; then
cleanexclude=1
elif optparse -s; then
cleanspecial=1
elif optparse -r; then
cleandir=1
elif optparse -R; then
cleandirhard=1
elif optparse -a; then
cleanexclude=1
cleandirhard=1
else
optfail
fi
done
if [ "$ARGS" ]; then
cleanexclude=1
cleandirhard=1
fi
# Good candidate for cg-Xlib
# Put exclude options for git-ls-files to EXCLUDE
set_exclude() {
stdignores=('*.[ao]' '.*' tags '*~' '#*' ',,merge*')
for ign in "${stdignores[@]}"; do
EXCLUDE="$EXCLUDE --exclude=$ign"
done
EXCLUDEFILE=$_git/exclude
if [ -f "$EXCLUDEFILE" ]; then
EXCLUDE="$EXCLUDE --exclude-from=$EXCLUDEFILE"
fi
}
EXCLUDE=
if [ -z "$cleanexclude" ]; then
set_exclude
fi
git-update-cache --refresh > /dev/null
do_clean() {
# FIXME - very suboptimal
if [ "$ARGS" ]; then
local found=
for arg in "${ARGS[@]}"; do
if [ "$arg" = "$file" ]; then
found=1
break
fi
done
[ "$found" ] || return
fi
if [ "$cleandirhard" ]; then
chmod -R 700 "$file"
rm -rf "$file"
return
fi
if [ "$cleandir" ]; then
rm -rf "$file"
return
fi
if [ "$cleanspecial" ]; then
[ -d "$file" ] && return
rm -f "$file"
return
fi
[ -f "$file" ] && rm -f "$file"
}
# Need to use temporary file so that changing IFS doesn't affect $EXCLUDE
# expansion.
filelist=$(mktemp -t gitlsfiles.XXXXXX)
git-ls-files --others $EXCLUDE >"$filelist"
IFS=$'\n'
for file in $(cat "$filelist"); do
do_clean "$file"
done
rm -f "$filelist"
--
Regards,
Pavel Roskin
next reply other threads:[~2005-07-08 22:42 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-07-08 22:34 Pavel Roskin [this message]
2005-07-08 22:59 ` New script: cg-clean Wolfgang Denk
2005-07-10 15:46 ` Petr Baudis
2005-08-06 7:14 ` Pavel Roskin
2005-08-11 23:29 ` Petr Baudis
2005-08-12 0:54 ` Pavel Roskin
2005-08-12 1:08 ` Petr Baudis
2005-08-12 3:59 ` Pavel Roskin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1120862084.17812.6.camel@dv \
--to=proski@gnu.org \
--cc=git@vger.kernel.org \
--cc=pasky@ucw.cz \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.