[PATCH 2/3] qf: fix wrong grep to remove unused patches

Lucas De Marchi lucas.demarchi at intel.com
Wed Feb 21 01:02:57 UTC 2018


We would leave a trailing slash which causes patches on the git-root
directory to be removed since they don't have that slash in the series
file.

Considering we have a patches/0001-bla.patch this would lead to:

+ ...
+ for patch in patches/{*/,/}*.patch
+ grep '^/0001-bla.patch$' patches/series
+ echo No reference to patches//0001-bla.patch, deleting it.
+ rm patches//0001-bla.patch

The fix is to change the work directory to patches and stop fixing up
the path. It's also safer to just use git-ls-files so we don't
potentially remove patches still not added.

Signed-off-by: Lucas De Marchi <lucas.demarchi at intel.com>
---
 qf | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/qf b/qf
index a7b8b919d178..c9ade42225e7 100755
--- a/qf
+++ b/qf
@@ -303,9 +303,10 @@ function qf_refresh
 function qf_clean_patches
 {
 	cd_toplevel
+	cd patches
 
-	for patch in patches/{*/,/}*.patch ; do
-		if grep "^${patch##patches/}$" patches/series &> /dev/null ; then
+	for patch in $(git ls-files '*.patch') ; do
+		if grep "^${patch}$" series &> /dev/null ; then
 			continue
 		fi
 		echo No reference to $patch, deleting it.
@@ -479,9 +480,10 @@ function qf_patch_amend
 function qf_list_unused_patches
 {
 	cd_toplevel
+	cd patches
 
-	for patch in patches/{*/,/}*.patch ; do
-		if ! grep "^${patch#patches/}$" patches/series > /dev/null ; then
+	for patch in $(git ls-files '*.patch'); do
+		if ! grep "^${patch}$" series > /dev/null ; then
 			if [[ "$1" != --purge ]] ; then
 				echo $patch
 			else
-- 
2.14.3



More information about the dim-tools mailing list