{"thread":{"id":"3894","subject":"[PATCH] Make cogito work with accented letters.","startedAt":"2006-04-16T20:46:23Z","lastAt":"2006-04-16T20:46:23Z","messageCount":1,"participants":["Yann Dirson"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"18754","messageId":"20060416204623.10411.26396.stgit@gandelf.nowhere.earth","threadId":"3894","inReplyTo":null,"subject":"[PATCH] Make cogito work with accented letters.","fromName":"Yann Dirson","fromEmail":"ydirson@altern.org","sentAt":"2006-04-16T20:46:23Z","receivedAt":"2006-04-16T20:46:23Z","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\nThis is an improved version of the previous patch, which fixes other\ncommands like cg-switch which use tree_timewarp.  A couple of other\ncommands using git-diff-index still need to be fixed in a similar\nmanner.\n\nSigned-off-by: Yann Dirson <ydirson@altern.org>\n---\n\n cg-Xlib                 |    7 ++----\n cg-commit               |   10 ++++----\n t/t9900-specialchars.sh |   59 +++++++++++++++++++++++++++++++++++++++++++++++\n 3 files changed, 67 insertions(+), 9 deletions(-)\n\ndiff --git a/cg-Xlib b/cg-Xlib\nindex 38172a0..e594986 100755\n--- a/cg-Xlib\n+++ b/cg-Xlib\n@@ -555,10 +555,9 @@ tree_timewarp()\n \t\t[ \"$no_head_update\" ] || git-update-ref HEAD \"$branch\" || :\n \n \t\t# Kill gone files\n-\t\tgit-diff-tree -r \"$base\" \"$branch\" |\n-\t\t\t# match \":100755 000000 14d43b1abf... 000000000... D\"\n-\t\t\tsed -ne 's/^:[^\\t]* D\\t//p' |\n-\t\t\txargs rm -f --\n+\t\tgit-diff-tree -z --name-status -r \"$base\" \"$branch\" |\n+\t\t\tperl -n0e 'chomp; if (defined $meta) { print \"$_\\0\" if $meta eq 'D'; $meta=undef } else { $meta = $_ }' |\n+\t\t\txargs --null rm -f --\n \t\tgit-checkout-index -u -f -a\n \n \t\t# FIXME: Can produce bogus \"contains only garbage\" messages.\ndiff --git a/cg-commit b/cg-commit\nindex 8dac57c..1d8de92 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 --name-status -z -r -m HEAD -- | \\\n+\t\tperl -n0e 'chomp; if (defined $meta) { s/([\\\"\\\\])/\\\\\\1/; print \"\\\"$meta $_\\\"\\n\"; $meta=undef } else { $meta = $_ }'))\"\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 --name-status -z -r -m HEAD | \\\n+\t\t\tperl -n0e 'chomp; if (defined $meta) { s/([\\\"\\\\])/\\\\\\1/; print \"\\\"$meta $_\\\"\\n\"; $meta=undef } else { $meta = $_ }'))\"\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"}]}