Skip to contentSkip to conversation

cg-clean -d removes "arch" and "include" in Linux

PATCH New Pavel Roskin 1 participant 1 message Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cg-clean -d removes "arch" and "include" in Linux

Hello!

"cg-clean -d" would delete directories that don't have versioned files in them, even if their subdirectories do. "arch" and "include" in Linux sources are such directories.

To be safe, every directory in the directory list should be complemented by all its parent directories.

The patch below is a quick hack that shows that bash is not the best language to implement this. Still, it's better to have such fix than having cg-clean remove source files.

cg-clean +12 -0
@@ -53,6 +53,18 @@ 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]
+			done
+		done |
 		sort -u >"$dirlist"
 
 	save_IFS="$IFS"
Signature · 2 lines
Regards,
Pavel Roskin