{"thread":{"id":"3891","subject":"[PATCH] Make cg-commit work with accented letters.","startedAt":"2006-04-16T17:57:00Z","lastAt":"2006-04-16T17:57:00Z","messageCount":1,"participants":["Yann Dirson"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"18747","messageId":"20060416175700.29745.26898.stgit@gandelf.nowhere.earth","threadId":"3891","inReplyTo":null,"subject":"[PATCH] Make cg-commit work with accented letters.","fromName":"Yann Dirson","fromEmail":"ydirson@altern.org","sentAt":"2006-04-16T17:57:00Z","receivedAt":"2006-04-16T17:57:00Z","isPatch":true,"sender":{"key":"ydirson@altern.org","avatar":"https://avatars.githubusercontent.com/u/1190950?v=4"},"body":"\ngit-diff-index in default mode has an annoying behaviour wrt filenames\ncontaining non-ascii chars.  As suggested by Pasky, we can use -z\nmode, which gives us a much better way of handling all other special\nchars.  With associated testcases ensuring it works with simple and\ndouble quotes, backslashes, and spaces as well.\n\nSigned-off-by: Yann Dirson <ydirson@altern.org>\n---\n\n cg-commit               |   10 ++++----\n t/t9900-specialchars.sh |   59 +++++++++++++++++++++++++++++++++++++++++++++++\n 2 files changed, 64 insertions(+), 5 deletions(-)\n\ndiff --git a/cg-commit b/cg-commit\nindex 8dac57c..9ec8289 100755\n--- a/cg-commit\n+++ b/cg-commit\n@@ -274,8 +274,8 @@ if [ \"$ARGS\" -o \"$_git_relpath\" ]; then\n \t\techo \"${_git_relpath}$file\" >>\"$filter\"\n \tdone\n \n-\teval \"commitfiles=($(cat \"$filter\" | path_xargs git-diff-index -r -m HEAD -- | \\\n-\t\tsed -e 's/\"\\|\\\\/\\\\&/g' -e 's/^\\([^\t]*\\)\\(.\\)\t\\(.*\\)\\(\t.*\\)*$/\"\\2 \\3\"/'))\"\n+\teval \"commitfiles=($(cat \"$filter\" | path_xargs git-diff-index -z -r -m HEAD -- | \\\n+\t\tperl -n0e 'if (defined $meta) { s/([\\\"\\\\])/\\\\\\1/; print \"\\\"$meta $_\\\"\\n\"; $meta=undef } else { $meta = (split(/\\s/))[4] }'))\"\n \tcustomfiles=1\n \n \t[ \"$review\" ] && cat \"$filter\" | path_xargs git-diff-index -r -m -p HEAD -- > \"$PATCH\"\n@@ -292,8 +292,8 @@ else\n \tif [ ! \"$ignorecache\" ]; then\n \t\t# \\t instead of the tab character itself works only with new\n \t\t# sed versions.\n-\t\teval \"commitfiles=($(git-diff-index -r -m HEAD | \\\n-\t\t\tsed -e 's/\"\\|\\\\/\\\\&/g' -e 's/^\\([^\t]*\\)\\(.\\)\t\\(.*\\)\\(\t.*\\)*$/\"\\2 \\3\"/'))\"\n+\t\teval \"commitfiles=($(git-diff-index -z -r -m HEAD | \\\n+\t\t\tperl -n0e 'if (defined $meta) { s/([\\\"\\\\])/\\\\\\1/; print \"\\\"$meta $_\\\"\\n\"; $meta=undef } else { $meta = (split(/\\s/))[4] }'))\"\n \n \t\tif [ -s \"$_git/commit-ignore\" ]; then\n \t\t\tnewcommitfiles=()\n@@ -439,7 +439,7 @@ __END__\n \t\texit 1\n \tfi\n \tif [ ! \"$ignorecache\" ] && [ ! \"$merging\" ] && [ ! \"$review\" ]; then\n-\t\teval \"newcommitfiles=($(grep ^CG:F \"$LOGMSG2\" | sed 's/^CG:F *\\(.*\\)$/\"\\1\"/'))\"\n+\t\teval \"newcommitfiles=($(grep ^CG:F \"$LOGMSG2\" | sed -e 's/\\\"/\\\\&/g' -e 's/^CG:F *\\(.*\\)$/\"\\1\"/'))\"\n \t\tif [ ! \"$force\" ] && [ ! \"${newcommitfiles[*]}\" ]; then\n \t\t\trm \"$LOGMSG\" \"$LOGMSG2\"\n \t\t\t[ \"$quiet\" ] && exit 0 || die 'Nothing to commit'\ndiff --git a/t/t9900-specialchars.sh b/t/t9900-specialchars.sh\nnew file mode 100755\nindex 0000000..a705052\n--- /dev/null\n+++ b/t/t9900-specialchars.sh\n@@ -0,0 +1,59 @@\n+#!/usr/bin/env bash\n+#\n+# Copyright (c) 2006 Yann Dirson\n+#\n+test_description=\"Tests various commands with shell-special chars.\n+\n+Filenames with embedded spaces, quotes, non-ascii letter, you name it.\"\n+\n+. ./test-lib.sh\n+\n+rm -rf .git\n+cg-init -m .\n+\n+touch \"a space\"\n+test_expect_success 'add file with space' 'cg-add \"a space\"'\n+test_expect_success 'commit file with space' 'cg-commit -m . \"a space\"'\n+\n+touch \"a'quote\"\n+test_expect_success 'add file with quote' \"cg-add \\\"a'quote\\\"\"\n+test_expect_success 'commit file with quote' \"cg-commit -m . \\\"a'quote\\\"\"\n+\n+touch \"d\\\"quote\"\n+test_expect_success 'add file with accent' 'cg-add \"d\\\"quote\"'\n+test_expect_success 'commit file with quote' 'cg-commit -m . \"d\\\"quote\"'\n+\n+touch \"back\\\\slash\"\n+test_expect_success 'add file with accent' 'cg-add \"back\\\\slash\"'\n+test_expect_success 'commit file with quote' 'cg-commit -m . \"back\\\\slash\"'\n+\n+touch \"accént\"\n+test_expect_success 'add file with accent' \"cg-add accént\"\n+test_expect_success 'commit file with quote' \"cg-commit -m . accént\"\n+\n+## same without a file arg to cg-commit\n+\n+rm -rf * .git\n+cg-init -m .\n+\n+touch \"a space\"\n+test_expect_success 'add file with space' 'cg-add \"a space\"'\n+test_expect_success 'commit file with space' 'cg-commit -m .'\n+\n+touch \"a'quote\"\n+test_expect_success 'add file with quote' \"cg-add \\\"a'quote\\\"\"\n+test_expect_success 'commit file with quote' \"cg-commit -m .\"\n+\n+touch \"d\\\"quote\"\n+test_expect_success 'add file with accent' 'cg-add \"d\\\"quote\"'\n+test_expect_success 'commit file with quote' 'cg-commit -m .'\n+\n+touch \"back\\\\slash\"\n+test_expect_success 'add file with accent' 'cg-add \"back\\\\slash\"'\n+test_expect_success 'commit file with quote' 'cg-commit -m .'\n+\n+touch \"accént\"\n+test_expect_success 'add file with accent' \"cg-add accént\"\n+test_expect_success 'commit file with quote' \"cg-commit -m .\"\n+\n+test_done\n"}]}