Permalink
Browse files

Rewrite svn-clean to improve performance

Don't run svn status three times which is rather expensive.
Also, instead of sleeping, use a flag (-f) to force the clean.
This behavior is similar to git-clean.
  • Loading branch information...
1 parent 8b6b2c4 commit bfa9a58f9ec622854be66ed153e37f4ef9c84bf6 @rosslagerwall committed Aug 10, 2012
Showing with 25 additions and 10 deletions.
  1. +25 −10 svn-clean
View
@@ -1,16 +1,31 @@
#!/bin/sh
-if [ ! -d ".svn" ]; then
- echo "Not in svn working copy"
+cleanup() {
+ rm "$svn_out"
+ rm "$svn_err"
+}
+
+svn_out=$(mktemp)
+svn_err=$(mktemp)
+
+svn status --no-ignore 2> "$svn_err" | grep '^[?I]' | cut -c '9-' > "$svn_out"
+
+if [ -s "$svn_err" ]; then
+ echo "svn error:"
+ cat "$svn_err"
+ cleanup
exit 1
fi
-res=$(svn status --no-ignore | grep '^[?I]' | cut -c '9-')
-if [ -n "$res" ]; then
- echo "List of files to clean:"
- svn status --no-ignore | grep '^[?I]' | cut -c '9-'
- echo "Cleaning in 10 seconds"
- sleep 10
- svn status --no-ignore | grep '^[?I]' | cut -c '9-' | \
- xargs -d '\n' rm -rf
+if [ -s "$svn_out" ]; then
+ if [ -z "$1" ]; then
+ echo "Would remove (use -f to force):"
+ cat "$svn_out"
+ else
+ echo "Removing:"
+ cat "$svn_out"
+ xargs -d '\n' rm -rf < "$svn_out"
+ fi
fi
+
+cleanup

0 comments on commit bfa9a58

Please sign in to comment.