git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] Make cg-clean faster and space-safe

From
PRPavel Roskin <proski@gnu.org>
Date
Oct 28, 2005, 02:39 UTC
Message-ID
<1130467161.2186.25.camel@dv>

Use bash pattern matching to list all parent directories instead of using arrays. This makes cg-clean run twice as fast on the Linux kernel (4 seconds vs 8 seconds).

The new code is also for directory names containing spaces and other symbols that need to be quoted. Also, the new code is easier to read.

Signed-off-by: Pavel Roskin <proski@gnu.org>
diff --git a/cg-clean b/cg-clean
index ea00d2b..f7b5151 100755
--- a/cg-clean
+++ b/cg-clean
@@ -53,16 +53,12 @@ clean_dirs()
 	git-ls-files --cached |
 		sed -n 's|^'"$_git_relpath"'||p' |
 		sed -n 's|/[^/]*$||p' |
-		while IFS='/' read -a dir; do
-			i=0
-			while test $i != ${#dir[@]}; do
-				j=0
-				while test $i != $j; do
-					echo -n ${dir[$j]}/
-					j=$[$j+1]
-				done
-				echo ${dir[$i]}
-				i=$[$i+1]
+		while read dir; do
+			while true; do
+				echo "$dir"
+				updir="${dir%/*}"
+				test "$dir" = "$updir" && break
+				dir="$updir"
 			done
 		done |
 		sort -u >"$dirlist"
-- 
Regards,
Pavel Roskin
Message 1 of 1 in “Make cg-clean faster and space-safe”
  1. Make cg-clean faster and space-safePavel Roskin, Oct 28, 2005

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.