If you run something like "guilt header '.*'" the command would crash,
because the grep comand that tries to ensure that the patch exist
would detect a match, but the later code expected the match to be
exact.

Fixed by comparing exact strings.

And as a creeping feature "guilt header" will now try to use the
supplied patch name as an unanchored regexp if no exact match was
found.  If the regexp yields a unique match, it is used; if more than
one patch matches, the names of all patches are listed and the command
fails.  (Exercise left to the reader: generalized this so that "guilt
push" also accepts a unique regular expression.)

Signed-off-by: Per Cederqvist <ced...@opera.com>
Signed-off-by: Josef 'Jeff' Sipek <jef...@josefsipek.net>
---
 guilt-header | 29 ++++++++++++++++++++++++++---
 1 file changed, 26 insertions(+), 3 deletions(-)

diff --git a/guilt-header b/guilt-header
index 41e00cc..c3d24f9 100755
--- a/guilt-header
+++ b/guilt-header
@@ -45,10 +45,33 @@ esac
 [ -z "$patch" ] && die "No patches applied."
 
 # check that patch exists in the series
-ret=`get_full_series | grep -e "^$patch\$" | wc -l`
-if [ $ret -eq 0 ]; then
-       die "Patch $patch is not in the series"
+TMP_FULL_SERIES=`get_tmp_file series`
+get_full_series > "$TMP_FULL_SERIES"
+found_patch=
+while read x; do
+       if [ "$x" = "$patch" ]; then
+               found_patch="$patch"
+               break
+       fi
+done < "$TMP_FULL_SERIES"
+if [ -z "$found_patch" ]; then
+       TMP_MATCHES=`get_tmp_file series`
+       grep "$patch" < "$TMP_FULL_SERIES" > "$TMP_MATCHES"
+       nr=`wc -l < $TMP_MATCHES`
+       if [ $nr -gt 1 ]; then
+               echo "$patch does not uniquely identify a patch. Did you mean 
any of these?" >&2
+               sed 's/^/  /' "$TMP_MATCHES" >&2
+               rm -f "$TMP_MATCHES" "$TMP_FULL_SERIES"
+               exit 1
+       elif [ $nr -eq 0 ]; then
+               rm -f "$TMP_MATCHES" "$TMP_FULL_SERIES"
+               die "Patch $patch is not in the series"
+       fi
+       found_patch=`cat $TMP_MATCHES`
+       rm -f "$TMP_MATCHES"
 fi
+rm -f "$TMP_FULL_SERIES"
+patch="$found_patch"
 
 # FIXME: warn if we're editing an applied patch
 
-- 
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to