From: Yann Dirson <ydirson@altern.org>
To: Petr Baudis <pasky@suse.cz>
Cc: git@vger.kernel.org
Subject: [PATCH] Make cg-commit work with accented letters.
Date: Sun, 16 Apr 2006 19:57:00 +0200 [thread overview]
Message-ID: <20060416175700.29745.26898.stgit@gandelf.nowhere.earth> (raw)
git-diff-index in default mode has an annoying behaviour wrt filenames
containing non-ascii chars. As suggested by Pasky, we can use -z
mode, which gives us a much better way of handling all other special
chars. With associated testcases ensuring it works with simple and
double quotes, backslashes, and spaces as well.
Signed-off-by: Yann Dirson <ydirson@altern.org>
---
cg-commit | 10 ++++----
t/t9900-specialchars.sh | 59 +++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 64 insertions(+), 5 deletions(-)
diff --git a/cg-commit b/cg-commit
index 8dac57c..9ec8289 100755
--- a/cg-commit
+++ b/cg-commit
@@ -274,8 +274,8 @@ if [ "$ARGS" -o "$_git_relpath" ]; then
echo "${_git_relpath}$file" >>"$filter"
done
- eval "commitfiles=($(cat "$filter" | path_xargs git-diff-index -r -m HEAD -- | \
- sed -e 's/"\|\\/\\&/g' -e 's/^\([^ ]*\)\(.\) \(.*\)\( .*\)*$/"\2 \3"/'))"
+ eval "commitfiles=($(cat "$filter" | path_xargs git-diff-index -z -r -m HEAD -- | \
+ perl -n0e 'if (defined $meta) { s/([\"\\])/\\\1/; print "\"$meta $_\"\n"; $meta=undef } else { $meta = (split(/\s/))[4] }'))"
customfiles=1
[ "$review" ] && cat "$filter" | path_xargs git-diff-index -r -m -p HEAD -- > "$PATCH"
@@ -292,8 +292,8 @@ else
if [ ! "$ignorecache" ]; then
# \t instead of the tab character itself works only with new
# sed versions.
- eval "commitfiles=($(git-diff-index -r -m HEAD | \
- sed -e 's/"\|\\/\\&/g' -e 's/^\([^ ]*\)\(.\) \(.*\)\( .*\)*$/"\2 \3"/'))"
+ eval "commitfiles=($(git-diff-index -z -r -m HEAD | \
+ perl -n0e 'if (defined $meta) { s/([\"\\])/\\\1/; print "\"$meta $_\"\n"; $meta=undef } else { $meta = (split(/\s/))[4] }'))"
if [ -s "$_git/commit-ignore" ]; then
newcommitfiles=()
@@ -439,7 +439,7 @@ __END__
exit 1
fi
if [ ! "$ignorecache" ] && [ ! "$merging" ] && [ ! "$review" ]; then
- eval "newcommitfiles=($(grep ^CG:F "$LOGMSG2" | sed 's/^CG:F *\(.*\)$/"\1"/'))"
+ eval "newcommitfiles=($(grep ^CG:F "$LOGMSG2" | sed -e 's/\"/\\&/g' -e 's/^CG:F *\(.*\)$/"\1"/'))"
if [ ! "$force" ] && [ ! "${newcommitfiles[*]}" ]; then
rm "$LOGMSG" "$LOGMSG2"
[ "$quiet" ] && exit 0 || die 'Nothing to commit'
diff --git a/t/t9900-specialchars.sh b/t/t9900-specialchars.sh
new file mode 100755
index 0000000..a705052
--- /dev/null
+++ b/t/t9900-specialchars.sh
@@ -0,0 +1,59 @@
+#!/usr/bin/env bash
+#
+# Copyright (c) 2006 Yann Dirson
+#
+test_description="Tests various commands with shell-special chars.
+
+Filenames with embedded spaces, quotes, non-ascii letter, you name it."
+
+. ./test-lib.sh
+
+rm -rf .git
+cg-init -m .
+
+touch "a space"
+test_expect_success 'add file with space' 'cg-add "a space"'
+test_expect_success 'commit file with space' 'cg-commit -m . "a space"'
+
+touch "a'quote"
+test_expect_success 'add file with quote' "cg-add \"a'quote\""
+test_expect_success 'commit file with quote' "cg-commit -m . \"a'quote\""
+
+touch "d\"quote"
+test_expect_success 'add file with accent' 'cg-add "d\"quote"'
+test_expect_success 'commit file with quote' 'cg-commit -m . "d\"quote"'
+
+touch "back\\slash"
+test_expect_success 'add file with accent' 'cg-add "back\\slash"'
+test_expect_success 'commit file with quote' 'cg-commit -m . "back\\slash"'
+
+touch "accént"
+test_expect_success 'add file with accent' "cg-add accént"
+test_expect_success 'commit file with quote' "cg-commit -m . accént"
+
+## same without a file arg to cg-commit
+
+rm -rf * .git
+cg-init -m .
+
+touch "a space"
+test_expect_success 'add file with space' 'cg-add "a space"'
+test_expect_success 'commit file with space' 'cg-commit -m .'
+
+touch "a'quote"
+test_expect_success 'add file with quote' "cg-add \"a'quote\""
+test_expect_success 'commit file with quote' "cg-commit -m ."
+
+touch "d\"quote"
+test_expect_success 'add file with accent' 'cg-add "d\"quote"'
+test_expect_success 'commit file with quote' 'cg-commit -m .'
+
+touch "back\\slash"
+test_expect_success 'add file with accent' 'cg-add "back\\slash"'
+test_expect_success 'commit file with quote' 'cg-commit -m .'
+
+touch "accént"
+test_expect_success 'add file with accent' "cg-add accént"
+test_expect_success 'commit file with quote' "cg-commit -m ."
+
+test_done
reply other threads:[~2006-04-16 17:54 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20060416175700.29745.26898.stgit@gandelf.nowhere.earth \
--to=ydirson@altern.org \
--cc=git@vger.kernel.org \
--cc=pasky@suse.cz \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).