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

[PATCH 2/2] git-quiltimport: flip the default not to allow fuzz

From
Junio C Hamano <gitster@pobox.com>
Date
Oct 21, 2014, 21:38 UTC
Message-ID
<xmqq38ahje87.fsf_-_@gitster.dls.corp.google.com>
In-Reply-To
<xmqq7g0r9v04.fsf@gitster.dls.corp.google.com>

Trying to be as strict as possible when applying the patch may be a good discipline, so let's flip the default but we can be helpful to those who do rely on the original behaviour thanks to the previous change to add -C$n option.

Suggest using -C1 when (and only when):
 - "git apply" without fuzz fails to apply; and
 - the user did not specify a -C$n or --exact option; and
 - "git apply -C1" (old behaviour) would have succeeded.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 * And this is the "flipping of the default"
 git-quiltimport.sh | 26 ++++++++++++++++++++++++--
 1 file changed, 24 insertions(+), 2 deletions(-)
diff --git a/git-quiltimport.sh b/git-quiltimport.sh
index 929365f..1190eb9 100755
--- a/git-quiltimport.sh
+++ b/git-quiltimport.sh
@@ -15,7 +15,8 @@ SUBDIRECTORY_ON=Yes
 
 dry_run=""
 quilt_author=""
-cflag=-C1
+cflag=
+fuzz_specified=
 while test $# != 0
 do
 	case "$1" in
@@ -31,9 +32,11 @@ do
 		*) ;;
 		esac
 		cflag="-C$1"
+		fuzz_specified=yes
 		;;
 	--exact)
 		cflag=
+		fuzz_specified=yes
 		;;
 	-n|--dry-run)
 		dry_run=1
@@ -74,6 +77,25 @@ tmp_msg="$tmp_dir/msg"
 tmp_patch="$tmp_dir/patch"
 tmp_info="$tmp_dir/info"
 
+# Helper to warn about -C$n option
+do_apply () {
+	if git apply --index ${cflag+"$cflag"} "$@"
+	then
+		return
+	fi
+	if test -z "$fuzz_specified" &&
+	   git apply --check --index -C1 "$@" >/dev/null 2>&1
+	then
+		cat >&2 <<-\EOM
+		'git quiltimport' by default no longer attempts to apply
+		patches with reduced context lines to allow fuzz; if you
+		want the old 'unsafe' behaviour, run the command with -C1
+		option.
+		EOM
+
+	fi
+	return 1
+}
 
 # Find the initial commit
 commit=$(git rev-parse HEAD)
@@ -145,7 +167,7 @@ do
 	fi
 
 	if [ -z "$dry_run" ] ; then
-		git apply --index $cflag ${level:+"$level"} "$tmp_patch" &&
+		do_apply ${level:+"$level"} "$tmp_patch" &&
 		tree=$(git write-tree) &&
 		commit=$( (echo "$SUBJECT"; echo; cat "$tmp_msg") | git commit-tree $tree -p $commit) &&
 		git update-ref -m "quiltimport: $patch_name" HEAD $commit || exit 4
-- 
2.1.2-583-g325e495
Previous: Junio C Hamano
Message 8 of 8 in “git-quiltimport.sh: disallow fuzz”
  1. git-quiltimport.sh: disallow fuzzJörn Engel, Sep 24, 2014
  2. Junio C HamanoSep 25, 2014
  3. Jörn EngelSep 25, 2014
  4. Junio C HamanoSep 25, 2014
  5. Junio C HamanoSep 25, 2014
  6. Junio C HamanoSep 26, 2014
  7. Junio C HamanoOct 21, 2014
  8. 2/2 git-quiltimport: flip the default not to allow fuzzJunio C Hamano, Oct 21, 2014

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.