From: Pavel Roskin <proski@gnu.org>
To: git <git@vger.kernel.org>, Petr Baudis <pasky@suse.cz>
Subject: [PATCH] cg-clean: fix directory cleaning
Date: Mon, 12 Dec 2005 15:54:20 -0500 [thread overview]
Message-ID: <1134420860.4695.14.camel@dv> (raw)
cg-clean is broken by commit 3cddede46dcd24bd7c36827ca564de23b2bb3517 -
it removes all subdirectories when run in the top level directory.
Although it's easy to make a one-line fix, I'd prefer a solution that
makes cg-clean potentially safer. Since git-ls-files runs in
subdirectories now, it's no longer needed to run anything in the top
level directory and filter out the results. cg-clean now changes to
$_git_relpath on startup and never uses $_git_relpath again.
Signed-off-by: Pavel Roskin <proski@gnu.org>
diff --git a/cg-clean b/cg-clean
index 92fc48e..6909076 100755
--- a/cg-clean
+++ b/cg-clean
@@ -60,8 +60,6 @@ clean_dirs()
git-ls-files --cached |
sed -n 's|/[^/]*$||p' |
while IFS=$'\n' read dir; do
- [ x"${dir#$_git_relpath}" = x"${dir}" ] && continue
- dir="${dir#$_git_relpath}"
while true; do
echo "$dir"
updir="${dir%/*}"
@@ -74,32 +72,27 @@ clean_dirs()
save_IFS="$IFS"
IFS=$'\n'
- fpath=${_git_relpath-./}
- find "$fpath" -type d -print |
- while read dir; do
- echo "${dir#$fpath}"
- done |
- sed '/^$/d;/^\.git$/d;/^\.git\//d' |
+ find ./ -type d -print |
+ sed 's/^\.\///;/^$/d;/^\.git$/d;/^\.git\//d' |
cat - "$dirlist" | sort -u |
diff - "$dirlist" |
sed -n 's/< //p' |
- while read file; do
- path="${_git_relpath}$file"
- if [ ! -d "$path" ]; then
+ while read dir; do
+ if [ ! -d "$dir" ]; then
# Perhaps directory was removed with its parent
continue
fi
if [ -z "$cleandir" ]; then
- echo "Not removing $file/"
+ echo "Not removing $dir/"
continue
fi
- [ "$quiet" ] || echo "Removing $file/"
+ [ "$quiet" ] || echo "Removing $dir/"
if [ "$cleandirhard" ]; then
- chmod -R 700 "$path"
+ chmod -R 700 "$dir"
fi
- $rm -rf "$path"
- if [ -e "$path" -o -L "$path" ]; then
- echo "Cannot remove $file/"
+ $rm -rf "$dir"
+ if [ -e "$dir" -o -L "$dir" ]; then
+ echo "Cannot remove $dir/"
fi
done
@@ -117,14 +110,13 @@ clean_files()
cg-status -n -s '?' "$xopt" -w |
while read file; do
- path="${_git_relpath}$file"
- if [ -d "$path" -a ! -L "$path" ]; then
+ if [ -d "$file" -a ! -L "$file" ]; then
# Sanity check, shouldn't happen
echo "FATAL: cg-status reports directories (internal error)" >&2
exit 1
- elif [ -e "$path" -o -L "$path" ]; then
+ elif [ -e "$file" -o -L "$file" ]; then
[ "$quiet" ] || echo "Removing $file"
- $rm -f "$path"
+ $rm -f "$file"
# rm would complain itself on failure
else
echo "File $file has disappeared!"
@@ -135,6 +127,8 @@ clean_files()
}
+cd "${_git_relpath-.}"
+
# 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
--
Regards,
Pavel Roskin
next reply other threads:[~2005-12-12 20:56 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-12-12 20:54 Pavel Roskin [this message]
2005-12-13 0:42 ` [PATCH] cg-clean: fix directory cleaning Petr Baudis
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=1134420860.4695.14.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.