From: Pavel Roskin <proski@gnu.org>
To: Petr Baudis <pasky@suse.cz>
Cc: git <git@vger.kernel.org>
Subject: Re: New script: cg-clean
Date: Thu, 11 Aug 2005 23:59:00 -0400 [thread overview]
Message-ID: <1123819140.4248.55.camel@dv> (raw)
In-Reply-To: <20050812010811.GM25280@pasky.ji.cz>
On Fri, 2005-08-12 at 03:08 +0200, Petr Baudis wrote:
> Dear diary, on Fri, Aug 12, 2005 at 02:54:13AM CEST, I got a letter
> where Pavel Roskin <proski@gnu.org> told me that...
> > Hi, Petr!
>
> Hi,
>
> > Unfortunately, my latest revision of cg-clean has "committed suicide"
> > just when I was about to post it. Anyway, I would prefer to wait until
> > you apply my patch to cg-status to ignore all ignores. That would allow
> > me to reuse cg-status.
>
> well, I did quite a while ago. Unless the kernel.org mirroring system
> broke, it should be already public.
Yes, it's there. Thank you.
This is another attempt at cg-clean. Verbose mode is now default (i.e.
everything that's removed is reported), "-q" makes the script quiet.
I've reinstated the "hard" option, it's now "-D".
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.
# When run without arguments, files ignored by cg-status and directories
# are not removed.
#
# OPTIONS
# -------
# -d::
# Also clean directories and their contents.
#
# -D::
# Same as -d but try harder (change permissions first).
#
# -q::
# Quiet - don't report what's being cleaned.
#
# -x::
# Also clean files ignored by cg-status, such as object files.
USAGE="cg-clean [-d] [-D] [-q] [-x]"
. ${COGITO_LIB}cg-Xlib || exit 1
noexclude=
cleandir=
cleandirhard=
quiet=
while optparse; do
if optparse -d; then
cleandir=1
elif optparse -D; then
cleandir=1
cleandirhard=1
elif optparse -q; then
quiet=1
elif optparse -x; then
noexclude=1
else
optfail
fi
done
[ "$ARGS" ] && usage
clean_dirs()
{
dirlist=$(mktemp -t gitlsfiles.XXXXXX)
git-ls-files --cached | sed -n 's|^'"$_git_relpath"'||p' |
sed -n 's|/[^/]*$||p' | sort -u >"$dirlist"
save_IFS="$IFS"
IFS=$'\n'
fpath=${_git_relpath-./}
find "$fpath" -type d -print | \
sed 's|^'"$fpath"'||;/^$/d;/^\.git$/d;/^\.git\//d' |
cat - "$dirlist" | sort -u | diff - "$dirlist" |
sed -n 's/< //p' |
for file in $(cat); do
path="${_git_relpath}$file"
if [ -z "$cleandir" ]; then
echo "Not removing $file/"
continue
fi
if [ ! -d "$path" ]; then
# Perhaps directory was removed with its parent
continue
fi
[ "$quiet" ] || echo "Removing $file/"
if [ "$cleandirhard" ]; then
chmod -R 700 "$path"
fi
rm -rf "$path"
if [ -e "$path" -o -L "$path" ]; then
echo "Cannot remove $file/"
fi
done
IFS="$save_IFS"
rm -f "$dirlist"
}
clean_files()
{
xopt=
if [ "$noexclude" ]; then
xopt="-x"
fi
save_IFS="$IFS"
IFS=$'\n'
cg-status "$xopt" -w | sed -n 's/^? //p' |
for file in $(cat); do
path="${_git_relpath}$file"
if [ -d "$path" ]; then
# Sanity check, shouldn't happen
echo "FATAL: cg-status reports directories" >&2
exit 1
elif [ -e "$path" -o -L "$path" ]; then
[ "$quiet" ] || echo "Removing $file"
rm -f "$path"
if [ -e "$path" -o -L "$path" ]; then
echo "Cannot remove $file"
fi
else
echo "File $file has disappeared!"
fi
done
IFS="$save_IFS"
}
# Even if -d or -D is not specified, we want to tell user about
# directories that are not removed
if [ -z "$quiet" -o "$cleandir" ]; then
clean_dirs
fi
clean_files
--
Regards,
Pavel Roskin
prev parent reply other threads:[~2005-08-12 3:59 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-07-08 22:34 New script: cg-clean Pavel Roskin
2005-07-08 22:59 ` 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 [this message]
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=1123819140.4248.55.camel@dv \
--to=proski@gnu.org \
--cc=git@vger.kernel.org \
--cc=pasky@suse.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.