Skip to contentSkip to conversation

git log --oneline and git log --pretty=format... give differrent outputs

PATCH New Shumkin Alexey 5 participants 104 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

Hello everybody!

I have a repository. Basic development is on Windows platform (under Cygwin). I have commit messages on Russian, so i18n.commitEncoding = i18n.logOutputtEncoding = cp1251. It's ok. I works fine on Windows.
When I run on Windows
git log --graph --oneline
and
git log --graph --pretty=format:'%C(yellow)%h %Creset%s'

I get two identical outputs which look like
* ae0a70f merge v2.6.54 into v3.0

|\  
| * 581e071 + explicit changelog mail content-type (for claws-mail)...
| * 9bafb65 fixed: changelog does not recognize Mantis...
| * f417e91 fixed: #82 (Добавить в программу возможность...
| * 8553efa fixed: #87 (2.6.53 Добавить для рассылки e-mail...

....

But when I run the same commands (for the same repository and current commit, of course) on Linux machine (ru_RU.UTF-8 locale; Guake, xterm, gnome-terminal, etc ) I get different outputs

git log --graph --oneline
gives output identical to Windows (see above) but
git log --graph --pretty=format:'%C(yellow)%h %Creset%s' gives
* ae0a70f merge v2.6.54 into v3.0

|\  
| * 581e071 + explicit changelog mail content-type (for claws-mail)...
| * 9bafb65 fixed: changelog does not recognize Mantis...
| * f417e91 fixed: #82 (<C4><EE><E1><E0><E2><E8><F2><FC>...
| * 8553efa fixed: #87 (2.6.53<C4><EE><E1><E0><E2><E8><F2><FC>...

i.e. non-UTF-8 characters are represented with their codes and not converted to UTF-8 as they are for "git log --graph --oneline"

So, the question - why? I thought both commands use the same log output mechanism.
As I can edit Git sources but I'm not familiar to C well, so one more question "Where exactly in sources to fix it fast?"

Thanks

#3 lore raw

PATCH 1/1 pretty: user format ignores i18n.logOutputEncoding setting

git log --graph --oneline
and
git log --graph --pretty=format:'%C(yellow)%h %Creset%s' give different outputs on Linux UTF-8 console when commit messages contain non-UTF-8 characters (e.g. commits made on Windows)

Fix it.

---
 log-tree.c                    |    1 +
 t/t4205-log-pretty-formats.sh |   20 ++++++++++++++++++--
 2 files changed, 19 insertions(+), 2 deletions(-)
log-tree.c +1 -0
index e945701..39913d7 100644
@@ -488,6 +488,7 @@ void show_log(struct rev_info *opt)
 	ctx.preserve_subject = opt->preserve_subject;
 	ctx.reflog_info = opt->reflog_info;
 	ctx.fmt = opt->commit_format;
+	ctx.output_encoding = get_log_output_encoding();
 	pretty_print_commit(&ctx, commit, &msgbuf);
 
 	if (opt->add_signoff)
t/t4205-log-pretty-formats.sh +18 -2
index 2ae9faa..24e787a 100755
@@ -11,10 +11,12 @@ test_expect_success 'set up basic repos' '
 	>bar &&
 	git add foo &&
 	test_tick &&
-	git commit -m initial &&
+	git config i18n.commitEncoding cp1251 &&
+	printf "initial \320\272\320\276\320\274\320\274\320\270\321\202" | iconv -t cp1251 -f utf-8 | xargs -I{} git commit -m "{}" &&
 	git add bar &&
 	test_tick &&
-	git commit -m "add bar"
+	git commit -m "add bar" &&
+	git config --unset i18n.commitEncoding
 '
 
 test_expect_success 'alias builtin format' '
@@ -38,6 +40,20 @@ test_expect_success 'alias user-defined format' '
 	test_cmp expected actual
 '
 
+test_expect_success 'alias user-defined tformat with %s (native encoding)' '
+	git config i18n.logOutputEncoding cp1251 &&
+	git log --oneline >expected-s &&
+	git log --pretty="tformat:%h %s" >actual-s &&
+	git config --unset i18n.logOutputEncoding &&
+	test_cmp expected-s actual-s
+'
+
+test_expect_success 'alias user-defined tformat with %s (utf-8 encoding)' '
+	git log --oneline >expected-s &&
+	git log --pretty="tformat:%h %s" >actual-s &&
+	test_cmp expected-s actual-s
+'
+
 test_expect_success 'alias user-defined tformat' '
 	git log --pretty="tformat:%h" >expected &&
 	git config pretty.test-alias "tformat:%h" &&
Signature · 1 line
1.7.6.dirty
#4 lore raw

Re: [PATCH] pretty: user format ignores i18n.logOutputEncoding setting

Quoted 5 lines · Alexey Shumkin

git log --graph --oneline
and
git log --graph --pretty=format:'%C(yellow)%h %Creset%s' give different outputs on Linux UTF-8 console when commit messages contain non-UTF-8 characters

(content) "different" is not specific enough to describe a problem (in some cases, difference in command line arguments is the way to obtain different results), especially if you do not state that they "should" be the same to begin with, and preferrably under what condition they should be the same.

(content) Do you really need all of the above options to observe the breakage, or can you drop --graph? If so, drop it from the proposed commit log message, as it is distracting without merit.

(content) Do you really mean SP before %Creset, not after?

(style) Somehow I find this hard to read. Perhaps make the two "sample commands" stand out more from the surrounding text? E.g.

-- >8 --
The following two ought to give the same output to a terminal:

	$ git log --oneline
        $ git log --pretty=format:'%C(yellow)%h %creset%s'

However, the former pays attention to i18n.logOutputEncoding configuration, while the latter does not when it format "%s". A log messages written in an encoding i18n.commitEncoding that is not UTF-8 is shown corrupted with the latter even when i18n.logOutputEncoding is set to convert to UTF-8.

Signed-off-by: ...
-- 8< --

(question) Does this change affect other commands, most notably format-patch, and if so how?

Quoted 52 lines
log-tree.c +1 -0
index e945701..39913d7 100644
@@ -488,6 +488,7 @@ void show_log(struct rev_info *opt)
 	ctx.preserve_subject = opt->preserve_subject;
 	ctx.reflog_info = opt->reflog_info;
 	ctx.fmt = opt->commit_format;
+	ctx.output_encoding = get_log_output_encoding();
 	pretty_print_commit(&ctx, commit, &msgbuf);
 
 	if (opt->add_signoff)
t/t4205-log-pretty-formats.sh +18 -2
index 2ae9faa..24e787a 100755
@@ -11,10 +11,12 @@ test_expect_success 'set up basic repos' '
 	>bar &&
 	git add foo &&
 	test_tick &&
-	git commit -m initial &&
+	git config i18n.commitEncoding cp1251 &&
+	printf "initial \320\272\320\276\320\274\320\274\320\270\321\202" | iconv -t cp1251 -f utf-8 | xargs -I{} git commit -m "{}" &&
 	git add bar &&
 	test_tick &&
-	git commit -m "add bar"
+	git commit -m "add bar" &&
+	git config --unset i18n.commitEncoding
 '
 
 test_expect_success 'alias builtin format' '
@@ -38,6 +40,20 @@ test_expect_success 'alias user-defined format' '
 	test_cmp expected actual
 '
 
+test_expect_success 'alias user-defined tformat with %s (native encoding)' '
+	git config i18n.logOutputEncoding cp1251 &&
+	git log --oneline >expected-s &&
+	git log --pretty="tformat:%h %s" >actual-s &&
+	git config --unset i18n.logOutputEncoding &&
+	test_cmp expected-s actual-s
+'
+
+test_expect_success 'alias user-defined tformat with %s (utf-8 encoding)' '
+	git log --oneline >expected-s &&
+	git log --pretty="tformat:%h %s" >actual-s &&
+	test_cmp expected-s actual-s
+'
+
 test_expect_success 'alias user-defined tformat' '
 	git log --pretty="tformat:%h" >expected &&
 	git config pretty.test-alias "tformat:%h" &&
#5 lore raw

Re: [PATCH] pretty: user format ignores i18n.logOutputEncoding setting

В Mon, 25 Jul 2011 12:45:26 -0700
Junio C Hamano <[email protected]> пишет:

Quoted 8 lines
Quoted 5 lines · Alexey Shumkin

git log --graph --oneline
and
git log --graph --pretty=format:'%C(yellow)%h %Creset%s' give different outputs on Linux UTF-8 console when commit messages contain non-UTF-8 characters

Quoted 5 lines

(content) "different" is not specific enough to describe a problem (in some cases, difference in command line arguments is the way to obtain different results), especially if you do not state that they "should" be the same to begin with, and preferrably under what condition they should be the same.

Ok, I'll fix the description

Quoted 3 lines

(content) Do you really need all of the above options to observe the breakage, or can you drop --graph? If so, drop it from the proposed commit log message, as it is distracting without merit.

You're right. I do not. I just observed the error with such parameters, so I wrote them, but they are not neccessary for the error appearance.

Quoted 1 line

(content) Do you really mean SP before %Creset, not after?

Realy do, but it does not matter here

Quoted 9 lines

(style) Somehow I find this hard to read. Perhaps make the two "sample commands" stand out more from the surrounding text? E.g.

-- >8 --
The following two ought to give the same output to a terminal:

	$ git log --oneline
        $ git log --pretty=format:'%C(yellow)%h %creset%s'
Quoted 8 lines

However, the former pays attention to i18n.logOutputEncoding configuration, while the latter does not when it format "%s". A log messages written in an encoding i18n.commitEncoding that is not UTF-8 is shown corrupted with the latter even when i18n.logOutputEncoding is set to convert to UTF-8.

Signed-off-by: ...
-- 8< --

I'm sorry. I'm newbie in a patch distribution and collaborative work on Enlgish (it is not my native language). So thanks for the correction.

Quoted 2 lines

(question) Does this change affect other commands, most notably format-patch, and if so how?

I'll discover this, thanks for pointing me a direction.

#6 lore raw

PATCH v2 1/1 pretty: user format ignores i18n.logOutputEncoding setting

In reply to Junio C Hamano

I discovered two more commands affected with this bug. So I reroll this patch and tests for it.

Quoted 1 line
Quoted 1 line

(question) Does this change affect other commands, most notably

format-patch, and if so how?
No, it does not affect format-patc

---

 builtin/rev-list.c               |    1 +
 builtin/shortlog.c               |    1 +
 log-tree.c                       |    1 +
 submodule.c                      |    3 +
 t/t4041-diff-submodule-option.sh |   44 +++++----
 t/t4205-log-pretty-formats.sh    |   22 ++++-
 t/t6006-rev-list-format.sh       |  192 +++++++++++++++++++++++---------------
 7 files changed, 167 insertions(+), 97 deletions(-)
#7 lore raw

PATCH v3 1/2 pretty: Add failing tests: user format ignores i18n.logOutputEncoding setting

The following two ought to give the same output to a terminal:

	$ git log --oneline --no-color
	$ git log --pretty=format:'%h %s'

However, the former pays attention to i18n.logOutputEncoding configuration, while the latter does not when it format "%s". A log messages written in an encoding i18n.commitEncoding that differs from terminal encoding are shown corrupted with the latter even when i18n.logOutputEncoding and terminal encoding are the same.

The same corruption is true for

	$ git diff --submodule=log
and
	$ git rev-list --pretty=format:%s HEAD
---
 t/t4041-diff-submodule-option.sh |   44 +++++----
 t/t4205-log-pretty-formats.sh    |   22 ++++-
 t/t6006-rev-list-format.sh       |  192 +++++++++++++++++++++++---------------
 3 files changed, 161 insertions(+), 97 deletions(-)
t/t4041-diff-submodule-option.sh +25 -19
index bf9a752..4460cff 100755
@@ -1,6 +1,7 @@
 #!/bin/sh
 #
 # Copyright (c) 2009 Jens Lehmann, based on t7401 by Ping Yin
+# Copyright (c) 2011 Alexey Shumkin (+ non-UTF-8 commit encoding tests)
 #
 
 test_description='Support for verbose submodule differences in git diff
@@ -10,6 +11,7 @@ This test tries to verify the sanity of the --submodule option of git diff.
 
 . ./test-lib.sh
 
+added=$(printf "\320\264\320\276\320\261\320\260\320\262\320\273\320\265\320\275")
 add_file () {
 	sm=$1
 	shift
@@ -19,8 +21,12 @@ add_file () {
 		echo "$name" > "$name" &&
 		git add "$name" &&
 		test_tick &&
-		git commit -m "Add $name"
+		git config i18n.commitEncoding cp1251 &&
+		echo "Add $name ($added $name)" \
+			| iconv -f utf-8 -t cp1251 \
+			| xargs -I{} git commit -m "{}"
 	done >/dev/null
+	git config --unset i18n.commitEncoding
 	git rev-parse --verify HEAD | cut -c1-7
 	cd "$owd"
 }
@@ -37,7 +43,7 @@ head1=$(add_file sm1 foo1 foo2)
 test_expect_success 'added submodule' "
 	git add sm1 &&
 	git diff-index -p --submodule=log HEAD >actual &&
-	cat >expected <<-EOF &&
+	cat >expected <<EOF
 Submodule sm1 0000000...$head1 (new submodule)
 EOF
 	test_cmp expected actual
@@ -48,27 +54,27 @@ head2=$(add_file sm1 foo3)
 
 test_expect_success 'modified submodule(forward)' "
 	git diff-index -p --submodule=log HEAD >actual &&
-	cat >expected <<-EOF &&
+	cat >expected <<EOF
 Submodule sm1 $head1..$head2:
-  > Add foo3
+  > Add foo3 ($added foo3)
 EOF
 	test_cmp expected actual
 "
 
 test_expect_success 'modified submodule(forward)' "
 	git diff --submodule=log >actual &&
-	cat >expected <<-EOF &&
+	cat >expected <<EOF
 Submodule sm1 $head1..$head2:
-  > Add foo3
+  > Add foo3 ($added foo3)
 EOF
 	test_cmp expected actual
 "
 
 test_expect_success 'modified submodule(forward) --submodule' "
 	git diff --submodule >actual &&
-	cat >expected <<-EOF &&
+	cat >expected <<EOF
 Submodule sm1 $head1..$head2:
-  > Add foo3
+  > Add foo3 ($added foo3)
 EOF
 	test_cmp expected actual
 "
@@ -98,10 +104,10 @@ head3=$(
 
 test_expect_success 'modified submodule(backward)' "
 	git diff-index -p --submodule=log HEAD >actual &&
-	cat >expected <<-EOF &&
+	cat >expected <<EOF
 Submodule sm1 $head2..$head3 (rewind):
-  < Add foo3
-  < Add foo2
+  < Add foo3 ($added foo3)
+  < Add foo2 ($added foo2)
 EOF
 	test_cmp expected actual
 "
@@ -110,12 +116,12 @@ head4=$(add_file sm1 foo4 foo5) &&
 head4_full=$(GIT_DIR=sm1/.git git rev-parse --verify HEAD)
 test_expect_success 'modified submodule(backward and forward)' "
 	git diff-index -p --submodule=log HEAD >actual &&
-	cat >expected <<-EOF &&
+	cat >expected <<EOF
 Submodule sm1 $head2...$head4:
-  > Add foo5
-  > Add foo4
-  < Add foo3
-  < Add foo2
+  > Add foo5 ($added foo5)
+  > Add foo4 ($added foo4)
+  < Add foo3 ($added foo3)
+  < Add foo2 ($added foo2)
 EOF
 	test_cmp expected actual
 "
@@ -131,10 +137,10 @@ mv sm1-bak sm1
 test_expect_success 'typechanged submodule(submodule->blob), --cached' "
 	git diff --submodule=log --cached >actual &&
 	cat >expected <<-EOF &&
-Submodule sm1 41fbea9...0000000 (submodule deleted)
+Submodule sm1 $head4...0000000 (submodule deleted)
 diff --git a/sm1 b/sm1
 new file mode 100644
-index 0000000..9da5fb8
+index 0000000..$head5
 --- /dev/null
 +++ b/sm1
 @@ -0,0 +1 @@
@@ -148,7 +154,7 @@ test_expect_success 'typechanged submodule(submodule->blob)' "
 	cat >expected <<-EOF &&
 diff --git a/sm1 b/sm1
 deleted file mode 100644
-index 9da5fb8..0000000
+index $head5..0000000
 --- a/sm1
 +++ /dev/null
 @@ -1 +0,0 @@
t/t4205-log-pretty-formats.sh +20 -2
index 2ae9faa..96e0229 100755
@@ -1,6 +1,7 @@
 #!/bin/sh
 #
 # Copyright (c) 2010, Will Palmer
+# Copyright (c) 2011, Alexey Shumkin (+ non-UTF-8 commit encoding tests)
 #
 
 test_description='Test pretty formats'
@@ -11,10 +12,13 @@ test_expect_success 'set up basic repos' '
 	>bar &&
 	git add foo &&
 	test_tick &&
-	git commit -m initial &&
+	git config i18n.commitEncoding cp1251 &&
+	printf "initial \320\272\320\276\320\274\320\274\320\270\321\202" \
+		| iconv -f utf-8 -t cp1251 | xargs -I{} git commit -m "{}" &&
 	git add bar &&
 	test_tick &&
-	git commit -m "add bar"
+	git commit -m "add bar" &&
+	git config --unset i18n.commitEncoding
 '
 
 test_expect_success 'alias builtin format' '
@@ -38,6 +42,20 @@ test_expect_success 'alias user-defined format' '
 	test_cmp expected actual
 '
 
+test_expect_success 'alias user-defined tformat with %s (cp1251 encoding)' '
+	git config i18n.logOutputEncoding cp1251 &&
+	git log --oneline >expected-s &&
+	git log --pretty="tformat:%h %s" >actual-s &&
+	git config --unset i18n.logOutputEncoding &&
+	test_cmp expected-s actual-s
+'
+
+test_expect_success 'alias user-defined tformat with %s (utf-8 encoding)' '
+	git log --oneline >expected-s &&
+	git log --pretty="tformat:%h %s" >actual-s &&
+	test_cmp expected-s actual-s
+'
+
 test_expect_success 'alias user-defined tformat' '
 	git log --pretty="tformat:%h" >expected &&
 	git config pretty.test-alias "tformat:%h" &&
t/t6006-rev-list-format.sh +116 -76

290 lines not on this page · raw message

Signature · 1 line
1.7.6.1.g8f21c
#8 lore raw

PATCH v3 2/2 pretty: user format ignores i18n.logOutputEncoding setting

In reply to Alexey Shumkin

The following two ought to give the same output to a terminal:

	$ git log --oneline --no-color
	$ git log --pretty=format:'%h %s'

However, the former pays attention to i18n.logOutputEncoding configuration, while the latter does not when it format "%s". A log messages written in an encoding i18n.commitEncoding that differs from terminal encoding are shown corrupted with the latter even when i18n.logOutputEncoding and terminal encoding are the same.

The same corruption is true for

	$ git diff --submodule=log
and
	$ git rev-list --pretty=format:%s HEAD
---
 builtin/rev-list.c |    1 +
 builtin/shortlog.c |    1 +
 log-tree.c         |    1 +
 submodule.c        |    3 +++
 4 files changed, 6 insertions(+), 0 deletions(-)
builtin/rev-list.c +1 -0
index 56727e8..831077d 100644
@@ -105,6 +105,7 @@ static void show_commit(struct commit *commit, void *data)
 		ctx.abbrev = revs->abbrev;
 		ctx.date_mode = revs->date_mode;
 		ctx.fmt = revs->commit_format;
+		ctx.output_encoding = get_log_output_encoding();
 		pretty_print_commit(&ctx, commit, &buf);
 		if (revs->graph) {
 			if (buf.len) {
builtin/shortlog.c +1 -0
index 37f3193..eba4086 100644
@@ -163,6 +163,7 @@ void shortlog_add_commit(struct shortlog *log, struct commit *commit)
 		ctx.subject = "";
 		ctx.after_subject = "";
 		ctx.date_mode = DATE_NORMAL;
+		ctx.output_encoding = get_log_output_encoding();
 		pretty_print_commit(&ctx, commit, &ufbuf);
 		buffer = ufbuf.buf;
 	} else if (*buffer) {
log-tree.c +1 -0
index e945701..39913d7 100644
@@ -488,6 +488,7 @@ void show_log(struct rev_info *opt)
 	ctx.preserve_subject = opt->preserve_subject;
 	ctx.reflog_info = opt->reflog_info;
 	ctx.fmt = opt->commit_format;
+	ctx.output_encoding = get_log_output_encoding();
 	pretty_print_commit(&ctx, commit, &msgbuf);
 
 	if (opt->add_signoff)
submodule.c +3 -0
index b6dec70..26efef4 100644
@@ -213,10 +213,13 @@ static void print_submodule_summary(struct rev_info *rev, FILE *f,
 	static const char format[] = "  %m %s";
 	struct strbuf sb = STRBUF_INIT;
 	struct commit *commit;
+	const char *log_output_encoding;
 
+	log_output_encoding = get_log_output_encoding();
 	while ((commit = get_revision(rev))) {
 		struct pretty_print_context ctx = {0};
 		ctx.date_mode = rev->date_mode;
+		ctx.output_encoding = log_output_encoding;
 		strbuf_setlen(&sb, 0);
 		if (commit->object.flags & SYMMETRIC_LEFT) {
 			if (del)
Signature · 1 line
1.7.6.1.g8f21c
#9 lore raw

PATCH v2 1/1 pretty: user format ignores i18n.logOutputEncoding setting

In reply to Junio C Hamano

Ooops! previuos message haven't Cc-ed to Junio. This one is CC-ed.
I discovered two more commands affected with this bug. So I reroll this patch and tests for it.

Quoted 2 lines
Quoted 2 lines

(question) Does this change affect other commands, most notably format-patch, and if so how?

No, it does not affect format-patch

---

 builtin/rev-list.c               |    1 +
 builtin/shortlog.c               |    1 +
 log-tree.c                       |    1 +
 submodule.c                      |    3 +
 t/t4041-diff-submodule-option.sh |   44 +++++----
 t/t4205-log-pretty-formats.sh    |   22 ++++-
 t/t6006-rev-list-format.sh       |  192 +++++++++++++++++++++++---------------
 7 files changed, 167 insertions(+), 97 deletions(-)
#10 lore raw

PATCH v3 1/2 pretty: Add failing tests: user format ignores i18n.logOutputEncoding setting

The following two ought to give the same output to a terminal:

	$ git log --oneline --no-color
	$ git log --pretty=format:'%h %s'

However, the former pays attention to i18n.logOutputEncoding configuration, while the latter does not when it format "%s". A log messages written in an encoding i18n.commitEncoding that differs from terminal encoding are shown corrupted with the latter even when i18n.logOutputEncoding and terminal encoding are the same.

The same corruption is true for

	$ git diff --submodule=log
and
	$ git rev-list --pretty=format:%s HEAD
---
 t/t4041-diff-submodule-option.sh |   44 +++++----
 t/t4205-log-pretty-formats.sh    |   22 ++++-
 t/t6006-rev-list-format.sh       |  192 +++++++++++++++++++++++---------------
 3 files changed, 161 insertions(+), 97 deletions(-)
t/t4041-diff-submodule-option.sh +25 -19
index bf9a752..4460cff 100755
@@ -1,6 +1,7 @@
 #!/bin/sh
 #
 # Copyright (c) 2009 Jens Lehmann, based on t7401 by Ping Yin
+# Copyright (c) 2011 Alexey Shumkin (+ non-UTF-8 commit encoding tests)
 #
 
 test_description='Support for verbose submodule differences in git diff
@@ -10,6 +11,7 @@ This test tries to verify the sanity of the --submodule option of git diff.
 
 . ./test-lib.sh
 
+added=$(printf "\320\264\320\276\320\261\320\260\320\262\320\273\320\265\320\275")
 add_file () {
 	sm=$1
 	shift
@@ -19,8 +21,12 @@ add_file () {
 		echo "$name" > "$name" &&
 		git add "$name" &&
 		test_tick &&
-		git commit -m "Add $name"
+		git config i18n.commitEncoding cp1251 &&
+		echo "Add $name ($added $name)" \
+			| iconv -f utf-8 -t cp1251 \
+			| xargs -I{} git commit -m "{}"
 	done >/dev/null
+	git config --unset i18n.commitEncoding
 	git rev-parse --verify HEAD | cut -c1-7
 	cd "$owd"
 }
@@ -37,7 +43,7 @@ head1=$(add_file sm1 foo1 foo2)
 test_expect_success 'added submodule' "
 	git add sm1 &&
 	git diff-index -p --submodule=log HEAD >actual &&
-	cat >expected <<-EOF &&
+	cat >expected <<EOF
 Submodule sm1 0000000...$head1 (new submodule)
 EOF
 	test_cmp expected actual
@@ -48,27 +54,27 @@ head2=$(add_file sm1 foo3)
 
 test_expect_success 'modified submodule(forward)' "
 	git diff-index -p --submodule=log HEAD >actual &&
-	cat >expected <<-EOF &&
+	cat >expected <<EOF
 Submodule sm1 $head1..$head2:
-  > Add foo3
+  > Add foo3 ($added foo3)
 EOF
 	test_cmp expected actual
 "
 
 test_expect_success 'modified submodule(forward)' "
 	git diff --submodule=log >actual &&
-	cat >expected <<-EOF &&
+	cat >expected <<EOF
 Submodule sm1 $head1..$head2:
-  > Add foo3
+  > Add foo3 ($added foo3)
 EOF
 	test_cmp expected actual
 "
 
 test_expect_success 'modified submodule(forward) --submodule' "
 	git diff --submodule >actual &&
-	cat >expected <<-EOF &&
+	cat >expected <<EOF
 Submodule sm1 $head1..$head2:
-  > Add foo3
+  > Add foo3 ($added foo3)
 EOF
 	test_cmp expected actual
 "
@@ -98,10 +104,10 @@ head3=$(
 
 test_expect_success 'modified submodule(backward)' "
 	git diff-index -p --submodule=log HEAD >actual &&
-	cat >expected <<-EOF &&
+	cat >expected <<EOF
 Submodule sm1 $head2..$head3 (rewind):
-  < Add foo3
-  < Add foo2
+  < Add foo3 ($added foo3)
+  < Add foo2 ($added foo2)
 EOF
 	test_cmp expected actual
 "
@@ -110,12 +116,12 @@ head4=$(add_file sm1 foo4 foo5) &&
 head4_full=$(GIT_DIR=sm1/.git git rev-parse --verify HEAD)
 test_expect_success 'modified submodule(backward and forward)' "
 	git diff-index -p --submodule=log HEAD >actual &&
-	cat >expected <<-EOF &&
+	cat >expected <<EOF
 Submodule sm1 $head2...$head4:
-  > Add foo5
-  > Add foo4
-  < Add foo3
-  < Add foo2
+  > Add foo5 ($added foo5)
+  > Add foo4 ($added foo4)
+  < Add foo3 ($added foo3)
+  < Add foo2 ($added foo2)
 EOF
 	test_cmp expected actual
 "
@@ -131,10 +137,10 @@ mv sm1-bak sm1
 test_expect_success 'typechanged submodule(submodule->blob), --cached' "
 	git diff --submodule=log --cached >actual &&
 	cat >expected <<-EOF &&
-Submodule sm1 41fbea9...0000000 (submodule deleted)
+Submodule sm1 $head4...0000000 (submodule deleted)
 diff --git a/sm1 b/sm1
 new file mode 100644
-index 0000000..9da5fb8
+index 0000000..$head5
 --- /dev/null
 +++ b/sm1
 @@ -0,0 +1 @@
@@ -148,7 +154,7 @@ test_expect_success 'typechanged submodule(submodule->blob)' "
 	cat >expected <<-EOF &&
 diff --git a/sm1 b/sm1
 deleted file mode 100644
-index 9da5fb8..0000000
+index $head5..0000000
 --- a/sm1
 +++ /dev/null
 @@ -1 +0,0 @@
t/t4205-log-pretty-formats.sh +20 -2
index 2ae9faa..96e0229 100755
@@ -1,6 +1,7 @@
 #!/bin/sh
 #
 # Copyright (c) 2010, Will Palmer
+# Copyright (c) 2011, Alexey Shumkin (+ non-UTF-8 commit encoding tests)
 #
 
 test_description='Test pretty formats'
@@ -11,10 +12,13 @@ test_expect_success 'set up basic repos' '
 	>bar &&
 	git add foo &&
 	test_tick &&
-	git commit -m initial &&
+	git config i18n.commitEncoding cp1251 &&
+	printf "initial \320\272\320\276\320\274\320\274\320\270\321\202" \
+		| iconv -f utf-8 -t cp1251 | xargs -I{} git commit -m "{}" &&
 	git add bar &&
 	test_tick &&
-	git commit -m "add bar"
+	git commit -m "add bar" &&
+	git config --unset i18n.commitEncoding
 '
 
 test_expect_success 'alias builtin format' '
@@ -38,6 +42,20 @@ test_expect_success 'alias user-defined format' '
 	test_cmp expected actual
 '
 
+test_expect_success 'alias user-defined tformat with %s (cp1251 encoding)' '
+	git config i18n.logOutputEncoding cp1251 &&
+	git log --oneline >expected-s &&
+	git log --pretty="tformat:%h %s" >actual-s &&
+	git config --unset i18n.logOutputEncoding &&
+	test_cmp expected-s actual-s
+'
+
+test_expect_success 'alias user-defined tformat with %s (utf-8 encoding)' '
+	git log --oneline >expected-s &&
+	git log --pretty="tformat:%h %s" >actual-s &&
+	test_cmp expected-s actual-s
+'
+
 test_expect_success 'alias user-defined tformat' '
 	git log --pretty="tformat:%h" >expected &&
 	git config pretty.test-alias "tformat:%h" &&
t/t6006-rev-list-format.sh +116 -76

290 lines not on this page · raw message

Signature · 1 line
1.7.6.1.g8f21c
#11 lore raw

Re: [PATCH 1/2] pretty: Add failing tests: user format ignores i18n.logOutputEncoding setting

Quoted 10 lines · Alexey Shumkin

The following two ought to give the same output to a terminal:

	$ git log --oneline --no-color
	$ git log --pretty=format:'%h %s'

However, the former pays attention to i18n.logOutputEncoding configuration, while the latter does not when it format "%s". A log messages written in an encoding i18n.commitEncoding that differs from terminal encoding are shown corrupted with the latter even when i18n.logOutputEncoding and terminal encoding are the same.

You seem to have inherited bad grammar from some example; I wonder where... ;-)

t/t4041-diff-submodule-option.sh add_file () { · line 27

Quoted 9 lines
t/t4041-diff-submodule-option.sh +4 -1
@@ -19,8 +21,12 @@ add_file () {
 		echo "$name" > "$name" &&
 		git add "$name" &&
 		test_tick &&
-		git commit -m "Add $name"
+		git config i18n.commitEncoding cp1251 &&
+		echo "Add $name ($added $name)" \
+			| iconv -f utf-8 -t cp1251 \
+			| xargs -I{} git commit -m "{}"

Don't do this. Format it this way instead if you want to use multi-line:

	echo "..." |
        iconv ... |
        xargs ...

I also am not sure if -I{} in xargs is all that portable. Why isn't it more like this, which would be far easier to read?

	msg_in_cp1251=$(echo "Add ..." | iconv ...) &&
        git commit -m "$msg_in_cp1251" &&
        ...

Also do not break the && chain.

Quoted 5 lines
t/t4041-diff-submodule-option.sh +1 -0
 	done >/dev/null
+	git config --unset i18n.commitEncoding
 	git rev-parse --verify HEAD | cut -c1-7
 	cd "$owd"
 }
#12 lore raw

v3 cover pretty: user format ignores i18n.logOutputEncoding setting

Quoted 2 lines
Quoted 2 lines

You seem to have inherited bad grammar from some example; I wonder where... ;-)

I rephrased... I made an attempt to as least ;)

Quoted 4 lines
Quoted 4 lines

Format it this way instead if you want to use multi-line:

	echo "..." |

iconv ... |
xargs ...

done

Alexey Shumkin (2):
pretty: Add failing tests: user format ignores i18n.logOutputEncoding
setting
pretty: user format ignores i18n.logOutputEncoding setting

 builtin/rev-list.c               |    1 +
 builtin/shortlog.c               |    1 +
 log-tree.c                       |    1 +
 submodule.c                      |    3 +
 t/t4041-diff-submodule-option.sh |   56 ++++++------
 t/t4205-log-pretty-formats.sh    |   22 ++++-
 t/t6006-rev-list-format.sh       |  192 +++++++++++++++++++++++---------------
 7 files changed, 170 insertions(+), 106 deletions(-)
Signature · 1 line
1.7.6.3.4.gf71f
#13 lore raw

PATCH v3 1/2 pretty: Add failing tests: user format ignores i18n.logOutputEncoding setting

In reply to Junio C Hamano

The following two commands are expected to give the same output to a terminal:

	$ git log --oneline --no-color
	$ git log --pretty=format:'%h %s'

However, the former pays attention to i18n.logOutputEncoding configuration, while the latter does not when it format "%s". Log messages written in an encoding i18n.commitEncoding which differs from terminal encoding are shown corrupted with the latter even when i18n.logOutputEncoding and terminal encoding are the same.

The same corruption is true for

	$ git diff --submodule=log
and
	$ git rev-list --pretty=format:%s HEAD
---
 t/t4041-diff-submodule-option.sh |   56 ++++++------
 t/t4205-log-pretty-formats.sh    |   22 ++++-
 t/t6006-rev-list-format.sh       |  192 +++++++++++++++++++++++---------------
 3 files changed, 164 insertions(+), 106 deletions(-)
t/t4041-diff-submodule-option.sh +28 -28
index bf9a752..b0cec5e 100755
@@ -1,6 +1,7 @@
 #!/bin/sh
 #
 # Copyright (c) 2009 Jens Lehmann, based on t7401 by Ping Yin
+# Copyright (c) 2011 Alexey Shumkin (+ non-UTF-8 commit encoding tests)
 #
 
 test_description='Support for verbose submodule differences in git diff
@@ -10,6 +11,7 @@ This test tries to verify the sanity of the --submodule option of git diff.
 
 . ./test-lib.sh
 
+added=$(printf "\320\264\320\276\320\261\320\260\320\262\320\273\320\265\320\275")
 add_file () {
 	sm=$1
 	shift
@@ -19,8 +21,11 @@ add_file () {
 		echo "$name" > "$name" &&
 		git add "$name" &&
 		test_tick &&
-		git commit -m "Add $name"
+		msg_added_cp1251=$(echo "Add $name ($added $name)" | iconv -f utf-8 -t cp1251) && 
+		git config i18n.commitEncoding cp1251 &&
+		git commit -m "$msg_added_cp1251"
 	done >/dev/null
+	git config --unset i18n.commitEncoding
 	git rev-parse --verify HEAD | cut -c1-7
 	cd "$owd"
 }
@@ -48,28 +53,25 @@ head2=$(add_file sm1 foo3)
 
 test_expect_success 'modified submodule(forward)' "
 	git diff-index -p --submodule=log HEAD >actual &&
-	cat >expected <<-EOF &&
-Submodule sm1 $head1..$head2:
-  > Add foo3
-EOF
+	printf \"Submodule sm1 $head1..$head2:\n\
+  > Add foo3 ($added foo3)\n\
+\" > expected &&
 	test_cmp expected actual
 "
 
 test_expect_success 'modified submodule(forward)' "
 	git diff --submodule=log >actual &&
-	cat >expected <<-EOF &&
-Submodule sm1 $head1..$head2:
-  > Add foo3
-EOF
+	printf \"Submodule sm1 $head1..$head2:\n\
+  > Add foo3 ($added foo3)\n\
+\" > expected &&
 	test_cmp expected actual
 "
 
 test_expect_success 'modified submodule(forward) --submodule' "
 	git diff --submodule >actual &&
-	cat >expected <<-EOF &&
-Submodule sm1 $head1..$head2:
-  > Add foo3
-EOF
+	printf \"Submodule sm1 $head1..$head2:\n\
+  > Add foo3 ($added foo3)\n\
+\" > expected &&
 	test_cmp expected actual
 "
 
@@ -98,11 +100,10 @@ head3=$(
 
 test_expect_success 'modified submodule(backward)' "
 	git diff-index -p --submodule=log HEAD >actual &&
-	cat >expected <<-EOF &&
-Submodule sm1 $head2..$head3 (rewind):
-  < Add foo3
-  < Add foo2
-EOF
+	printf \"Submodule sm1 $head2..$head3 (rewind):\n\
+  < Add foo3 ($added foo3)\n\
+  < Add foo2 ($added foo2)\n\
+\" > expected &&
 	test_cmp expected actual
 "
 
@@ -110,13 +111,12 @@ head4=$(add_file sm1 foo4 foo5) &&
 head4_full=$(GIT_DIR=sm1/.git git rev-parse --verify HEAD)
 test_expect_success 'modified submodule(backward and forward)' "
 	git diff-index -p --submodule=log HEAD >actual &&
-	cat >expected <<-EOF &&
-Submodule sm1 $head2...$head4:
-  > Add foo5
-  > Add foo4
-  < Add foo3
-  < Add foo2
-EOF
+	printf \"Submodule sm1 $head2...$head4:\n\
+  > Add foo5 ($added foo5)\n\
+  > Add foo4 ($added foo4)\n\
+  < Add foo3 ($added foo3)\n\
+  < Add foo2 ($added foo2)\n\
+\" > expected &&
 	test_cmp expected actual
 "
 
@@ -131,10 +131,10 @@ mv sm1-bak sm1
 test_expect_success 'typechanged submodule(submodule->blob), --cached' "
 	git diff --submodule=log --cached >actual &&
 	cat >expected <<-EOF &&
-Submodule sm1 41fbea9...0000000 (submodule deleted)
+Submodule sm1 $head4...0000000 (submodule deleted)
 diff --git a/sm1 b/sm1
 new file mode 100644
-index 0000000..9da5fb8
+index 0000000..$head5
 --- /dev/null
 +++ b/sm1
 @@ -0,0 +1 @@
@@ -148,7 +148,7 @@ test_expect_success 'typechanged submodule(submodule->blob)' "
 	cat >expected <<-EOF &&
 diff --git a/sm1 b/sm1
 deleted file mode 100644
-index 9da5fb8..0000000
+index $head5..0000000
 --- a/sm1
 +++ /dev/null
 @@ -1 +0,0 @@
t/t4205-log-pretty-formats.sh +20 -2
index 2ae9faa..9da6835 100755
@@ -1,6 +1,7 @@
 #!/bin/sh
 #
 # Copyright (c) 2010, Will Palmer
+# Copyright (c) 2011, Alexey Shumkin (+ non-UTF-8 commit encoding tests)
 #
 
 test_description='Test pretty formats'
@@ -11,10 +12,13 @@ test_expect_success 'set up basic repos' '
 	>bar &&
 	git add foo &&
 	test_tick &&
-	git commit -m initial &&
+	git config i18n.commitEncoding cp1251 &&
+	msg_commit_cp1251=$(printf "initial \320\272\320\276\320\274\320\274\320\270\321\202" | iconv -f utf-8 -t cp1251) &&
+	git commit -m "$msg_commit_cp1251" &&
 	git add bar &&
 	test_tick &&
-	git commit -m "add bar"
+	git commit -m "add bar" &&
+	git config --unset i18n.commitEncoding
 '
 
 test_expect_success 'alias builtin format' '
@@ -38,6 +42,20 @@ test_expect_success 'alias user-defined format' '
 	test_cmp expected actual
 '
 
+test_expect_success 'alias user-defined tformat with %s (cp1251 encoding)' '
+	git config i18n.logOutputEncoding cp1251 &&
+	git log --oneline >expected-s &&
+	git log --pretty="tformat:%h %s" >actual-s &&
+	git config --unset i18n.logOutputEncoding &&
+	test_cmp expected-s actual-s
+'
+
+test_expect_success 'alias user-defined tformat with %s (utf-8 encoding)' '
+	git log --oneline >expected-s &&
+	git log --pretty="tformat:%h %s" >actual-s &&
+	test_cmp expected-s actual-s
+'
+
 test_expect_success 'alias user-defined tformat' '
 	git log --pretty="tformat:%h" >expected &&
 	git config pretty.test-alias "tformat:%h" &&
t/t6006-rev-list-format.sh +116 -76

290 lines not on this page · raw message

Signature · 1 line
1.7.6.3.4.gf71f
#14 lore raw

PATCH v3 2/2 pretty: user format ignores i18n.logOutputEncoding setting

The following two commands are expected to give the same output to a terminal:

	$ git log --oneline --no-color
	$ git log --pretty=format:'%h %s'

However, the former pays attention to i18n.logOutputEncoding configuration, while the latter does not when it format "%s". Log messages written in an encoding i18n.commitEncoding which differs from terminal encoding are shown corrupted with the latter even when i18n.logOutputEncoding and terminal encoding are the same.

The same corruption is true for

	$ git diff --submodule=log
and
	$ git rev-list --pretty=format:%s HEAD
---
 builtin/rev-list.c |    1 +
 builtin/shortlog.c |    1 +
 log-tree.c         |    1 +
 submodule.c        |    3 +++
 4 files changed, 6 insertions(+), 0 deletions(-)
builtin/rev-list.c +1 -0
index 56727e8..831077d 100644
@@ -105,6 +105,7 @@ static void show_commit(struct commit *commit, void *data)
 		ctx.abbrev = revs->abbrev;
 		ctx.date_mode = revs->date_mode;
 		ctx.fmt = revs->commit_format;
+		ctx.output_encoding = get_log_output_encoding();
 		pretty_print_commit(&ctx, commit, &buf);
 		if (revs->graph) {
 			if (buf.len) {
builtin/shortlog.c +1 -0
index 37f3193..eba4086 100644
@@ -163,6 +163,7 @@ void shortlog_add_commit(struct shortlog *log, struct commit *commit)
 		ctx.subject = "";
 		ctx.after_subject = "";
 		ctx.date_mode = DATE_NORMAL;
+		ctx.output_encoding = get_log_output_encoding();
 		pretty_print_commit(&ctx, commit, &ufbuf);
 		buffer = ufbuf.buf;
 	} else if (*buffer) {
log-tree.c +1 -0
index e945701..39913d7 100644
@@ -488,6 +488,7 @@ void show_log(struct rev_info *opt)
 	ctx.preserve_subject = opt->preserve_subject;
 	ctx.reflog_info = opt->reflog_info;
 	ctx.fmt = opt->commit_format;
+	ctx.output_encoding = get_log_output_encoding();
 	pretty_print_commit(&ctx, commit, &msgbuf);
 
 	if (opt->add_signoff)
submodule.c +3 -0
index b648927..8c96de7 100644
@@ -213,10 +213,13 @@ static void print_submodule_summary(struct rev_info *rev, FILE *f,
 	static const char format[] = "  %m %s";
 	struct strbuf sb = STRBUF_INIT;
 	struct commit *commit;
+	const char *log_output_encoding;
 
+	log_output_encoding = get_log_output_encoding();
 	while ((commit = get_revision(rev))) {
 		struct pretty_print_context ctx = {0};
 		ctx.date_mode = rev->date_mode;
+		ctx.output_encoding = log_output_encoding;
 		strbuf_setlen(&sb, 0);
 		if (commit->object.flags & SYMMETRIC_LEFT) {
 			if (del)
Signature · 1 line
1.7.6.3.4.gf71f
#15 lore raw

Re: [PATCH v3 1/2] pretty: Add failing tests: user format ignores i18n.logOutputEncoding setting

In reply to Alexey Shumkin

t/t4041-diff-submodule-option.sh head2=$(add_file sm1 foo3) · line 54

Quoted 5 lines · Alexey Shumkin
t/t4041-diff-submodule-option.sh +0 -0
...
@@ -48,28 +53,25 @@ head2=$(add_file sm1 foo3)
 
 test_expect_success 'modified submodule(forward)' "

As this is [PATCH 1/2], doesn't this patch make this test fail, calling for test_expect_failure here (and then later in 2/2 to be flipped back to test_expect_success)?

t/t4041-diff-submodule-option.sh head2=$(add_file sm1 foo3) · line 60

Quoted 10 lines
t/t4041-diff-submodule-option.sh +3 -4
 	git diff-index -p --submodule=log HEAD >actual &&
-	cat >expected <<-EOF &&
-Submodule sm1 $head1..$head2:
-  > Add foo3
-EOF
+	printf \"Submodule sm1 $head1..$head2:\n\
+  > Add foo3 ($added foo3)\n\
+\" > expected &&
 	test_cmp expected actual
 "

Hmmm... why printf? Is it worth to force reviewers wonder what would happen if any of these $variables happened to have "%" in them? Are you benefiting from any printf features that you cannot achieve with the original cat?

This hunk and others throughout your patch that change cat with here doc into printf seem to make the tests less legible, at least to me.

Perhaps like this instead, if the "flushed left" of the original looked ugly to your eyes?

@@ -49,27 +54,25 @@ head2=$(add_file sm1 foo3)
test_expect_success 'modified submodule(forward)' "
git diff-index -p --submodule=log HEAD >actual && cat >expected <<-EOF &&
-Submodule sm1 $head1..$head2:
- > Add foo3
-EOF
+ Submodule sm1 $head1..$head2:
+ > Add foo3 ($added foo3)
+ EOF
test_cmp expected actual
"

#16 lore raw

Re: [PATCH v3 1/2] pretty: Add failing tests: user format ignores i18n.logOutputEncoding setting

Quoted 11 lines

Review head2=$(add_file sm1 foo3) · line 54

Quoted 5 lines · Alexey Shumkin
(quoted diff) +0 -0

b/t/t4041-diff-submodule-option.sh ...

(quoted diff) +0 -0
@@ -48,28 +53,25 @@ head2=$(add_file sm1 foo3)
 
 test_expect_success 'modified submodule(forward)' "

As this is [PATCH 1/2], doesn't this patch make this test fail, calling for test_expect_failure here (and then later in 2/2 to be flipped back to test_expect_success)?

I did not know how is right.
AFAIK, XP way tells to write failing tests and then patch/fix the code to pass them.

Here, As I understand now all tests must be successful The difference is in expectation of failure or success. Ok. I got it and I will reroll the patches.

Quoted 16 lines

t/t4041-diff-submodule-option.sh head2=$(add_file sm1 foo3) · line 60

Quoted 11 lines
t/t4041-diff-submodule-option.sh +3 -4
 	git diff-index -p --submodule=log HEAD >actual &&
-	cat >expected <<-EOF &&
-Submodule sm1 $head1..$head2:
-  > Add foo3
-EOF
+	printf \"Submodule sm1 $head1..$head2:\n\
+  > Add foo3 ($added foo3)\n\
+\" > expected &&
 	test_cmp expected actual
 "

Hmmm... why printf? Is it worth to force reviewers wonder what would happen if any of these $variables happened to have "%" in them? Are you benefiting from any printf features that you cannot achieve with the original cat?

This is a remained from v1 patch code. It is not required now. I'll fix it. Thanks.

Quoted 5 lines

This hunk and others throughout your patch that change cat with here doc into printf seem to make the tests less legible, at least to me.

Perhaps like this instead, if the "flushed left" of the original looked ugly to your eyes?

No, the reason was not in "flushed left". And, BTW, this code generates expected output that has predefined format...

Quoted 14 lines
t/t4041-diff-submodule-option.sh +3 -3
@@ -49,27 +54,25 @@ head2=$(add_file sm1 foo3)
 test_expect_success 'modified submodule(forward)' "
 	git diff-index -p --submodule=log HEAD >actual &&
 	cat >expected <<-EOF &&
-Submodule sm1 $head1..$head2:
-  > Add foo3
-EOF
+	Submodule sm1 $head1..$head2:
+	  > Add foo3 ($added foo3)
+	EOF
 	test_cmp expected actual
 "
 
Signature · 6 lines
С уважением, Алексей Шумкин
Программист компании 1С-Рарус
E-mail: [email protected]
ICQ: 118001447
Jabber (GoogleTalk): [email protected]
Skype: crezoff
#17 lore raw

v4 cover Reroll patches against v1.8.1.1

Woooof!
Reroll my patches again after 1.5 years ;)
They must be applied against v1.8.1.1
Sorry for my laziness ;)

Alexey Shumkin (4):
t6006 (rev-list-format): don't hardcode SHA-1 in expected outputs t7102 (reset): refactoring: don't hardcode SHA-1 in expected outputs
pretty: Add failing tests: user format ignores i18n.logOutputEncoding
setting
pretty: user format ignores i18n.logOutputEncoding setting

 builtin/reset.c                  |   8 +-
 builtin/rev-list.c               |   1 +
 builtin/shortlog.c               |   1 +
 log-tree.c                       |   1 +
 submodule.c                      |   3 +
 t/t4041-diff-submodule-option.sh |  23 +++--
 t/t4205-log-pretty-formats.sh    |  37 ++++++--
 t/t6006-rev-list-format.sh       | 200 +++++++++++++++++++++++----------------
 t/t7102-reset.sh                 |  71 +++++++++-----
 9 files changed, 224 insertions(+), 121 deletions(-)
Signature · 1 line
1.8.1.1.10.g9255f3f
#18 lore raw

PATCH v4 1/4 t6006 (rev-list-format): don't hardcode SHA-1 in expected outputs

The expected SHA-1 digests are always available in variables. Use them instead of hardcoding.

---
 t/t6006-rev-list-format.sh | 130 +++++++++++++++++++++++++--------------------
 1 file changed, 72 insertions(+), 58 deletions(-)
t/t6006-rev-list-format.sh +72 -58
index f94f0c4..c248509 100755
@@ -6,8 +6,19 @@ test_description='git rev-list --pretty=format test'
 
 test_tick
 test_expect_success 'setup' '
-touch foo && git add foo && git commit -m "added foo" &&
-  echo changed >foo && git commit -a -m "changed foo"
+	touch foo &&
+	git add foo &&
+	git commit -m "added foo" &&
+	head1=$(git rev-parse --verify HEAD) &&
+	head1_7=$(echo $head1 | cut -c1-7) &&
+	echo changed >foo &&
+	git commit -a -m "changed foo" &&
+	head2=$(git rev-parse --verify HEAD) &&
+	head2_7=$(echo $head2 | cut -c1-7) &&
+	head2_parent=$(git cat-file -p HEAD | grep parent | cut -f 2 -d" ") &&
+	head2_parent_7=$(echo $head2_parent | cut -c1-7) &&
+	tree2=$(git cat-file -p HEAD | grep tree | cut -f 2 -d" ") &&
+	tree2_7=$(echo $tree2 | cut -c1-7)
 '
 
 # usage: test_format name format_string <expected_output
@@ -19,49 +30,49 @@ test_cmp expect.$1 output.$1
 "
 }
 
-test_format percent %%h <<'EOF'
-commit 131a310eb913d107dd3c09a65d1651175898735d
+test_format percent %%h <<EOF
+commit $head2
 %h
-commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
+commit $head1
 %h
 EOF
 
-test_format hash %H%n%h <<'EOF'
-commit 131a310eb913d107dd3c09a65d1651175898735d
-131a310eb913d107dd3c09a65d1651175898735d
-131a310
-commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
-86c75cfd708a0e5868dc876ed5b8bb66c80b4873
-86c75cf
+test_format hash %H%n%h <<EOF
+commit $head2
+$head2
+$head2_7
+commit $head1
+$head1
+$head1_7
 EOF
 
-test_format tree %T%n%t <<'EOF'
-commit 131a310eb913d107dd3c09a65d1651175898735d
-fe722612f26da5064c32ca3843aa154bdb0b08a0
-fe72261
-commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
+test_format tree %T%n%t <<EOF
+commit $head2
+$tree2
+$tree2_7
+commit $head1
 4d5fcadc293a348e88f777dc0920f11e7d71441c
 4d5fcad
 EOF
 
-test_format parents %P%n%p <<'EOF'
-commit 131a310eb913d107dd3c09a65d1651175898735d
-86c75cfd708a0e5868dc876ed5b8bb66c80b4873
-86c75cf
-commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
+test_format parents %P%n%p <<EOF
+commit $head2
+$head1
+$head2_parent_7
+commit $head1
 
 
 EOF
 
 # we don't test relative here
-test_format author %an%n%ae%n%ad%n%aD%n%at <<'EOF'
-commit 131a310eb913d107dd3c09a65d1651175898735d
+test_format author %an%n%ae%n%ad%n%aD%n%at <<EOF
+commit $head2
 A U Thor
 [email protected]
 Thu Apr 7 15:13:13 2005 -0700
 Thu, 7 Apr 2005 15:13:13 -0700
 1112911993
-commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
+commit $head1
 A U Thor
 [email protected]
 Thu Apr 7 15:13:13 2005 -0700
@@ -69,14 +80,14 @@ Thu, 7 Apr 2005 15:13:13 -0700
 1112911993
 EOF
 
-test_format committer %cn%n%ce%n%cd%n%cD%n%ct <<'EOF'
-commit 131a310eb913d107dd3c09a65d1651175898735d
+test_format committer %cn%n%ce%n%cd%n%cD%n%ct <<EOF
+commit $head2
 C O Mitter
 [email protected]
 Thu Apr 7 15:13:13 2005 -0700
 Thu, 7 Apr 2005 15:13:13 -0700
 1112911993
-commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
+commit $head1
 C O Mitter
 [email protected]
 Thu Apr 7 15:13:13 2005 -0700
@@ -84,21 +95,21 @@ Thu, 7 Apr 2005 15:13:13 -0700
 1112911993
 EOF
 
-test_format encoding %e <<'EOF'
-commit 131a310eb913d107dd3c09a65d1651175898735d
-commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
+test_format encoding %e <<EOF
+commit $head2
+commit $head1
 EOF
 
-test_format subject %s <<'EOF'
-commit 131a310eb913d107dd3c09a65d1651175898735d
+test_format subject %s <<EOF
+commit $head2
 changed foo
-commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
+commit $head1
 added foo
 EOF
 
-test_format body %b <<'EOF'
-commit 131a310eb913d107dd3c09a65d1651175898735d
-commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
+test_format body %b <<EOF
+commit $head2
+commit $head1
 EOF
 
 test_format raw-body %B <<'EOF'
@@ -110,17 +121,17 @@ added foo
 
 EOF
 
-test_format colors %Credfoo%Cgreenbar%Cbluebaz%Cresetxyzzy <<'EOF'
-commit 131a310eb913d107dd3c09a65d1651175898735d
+test_format colors %Credfoo%Cgreenbar%Cbluebaz%Cresetxyzzy <<EOF
+commit $head2
 foobarbazxyzzy
-commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
+commit $head1
 foobarbazxyzzy
 EOF
 
-test_format advanced-colors '%C(red yellow bold)foo%C(reset)' <<'EOF'
-commit 131a310eb913d107dd3c09a65d1651175898735d
+test_format advanced-colors '%C(red yellow bold)foo%C(reset)' <<EOF
+commit $head2
 foo
-commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
+commit $head1
 foo
 EOF
 
@@ -131,39 +142,42 @@ This commit message is much longer than the others,
 and it will be encoded in iso8859-1. We should therefore
 include an iso8859 character: ¡bueno!
 EOF
+
 test_expect_success 'setup complex body' '
-git config i18n.commitencoding iso8859-1 &&
-  echo change2 >foo && git commit -a -F commit-msg
+	git config i18n.commitencoding iso8859-1 &&
+	echo change2 >foo && git commit -a -F commit-msg &&
+	head3=$(git rev-parse --verify HEAD) &&
+	head3_7=$(echo $head3 | cut -c1-7)
 '
 
-test_format complex-encoding %e <<'EOF'
-commit f58db70b055c5718631e5c61528b28b12090cdea
+test_format complex-encoding %e <<EOF
+commit $head3
 iso8859-1
-commit 131a310eb913d107dd3c09a65d1651175898735d
-commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
+commit $head2
+commit $head1
 EOF
 
-test_format complex-subject %s <<'EOF'
-commit f58db70b055c5718631e5c61528b28b12090cdea
+test_format complex-subject %s <<EOF
+commit $head3
 Test printing of complex bodies
-commit 131a310eb913d107dd3c09a65d1651175898735d
+commit $head2
 changed foo
-commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
+commit $head1
 added foo
 EOF
 
-test_format complex-body %b <<'EOF'
-commit f58db70b055c5718631e5c61528b28b12090cdea
+test_format complex-body %b <<EOF
+commit $head3
 This commit message is much longer than the others,
 and it will be encoded in iso8859-1. We should therefore
 include an iso8859 character: ¡bueno!
 
-commit 131a310eb913d107dd3c09a65d1651175898735d
-commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
+commit $head2
+commit $head1
 EOF
 
 test_expect_success '%x00 shows NUL' '
-	echo  >expect commit f58db70b055c5718631e5c61528b28b12090cdea &&
+	echo  >expect commit $head3 &&
 	echo >>expect fooQbar &&
 	git rev-list -1 --format=foo%x00bar HEAD >actual.nul &&
 	nul_to_q <actual.nul >actual &&
Signature · 1 line
1.8.1.1.10.g9255f3f
#19 lore raw

Re: [PATCH v4 1/4] t6006 (rev-list-format): don't hardcode SHA-1 in expected outputs

Quoted 13 lines · Alexey Shumkin

The expected SHA-1 digests are always available in variables. Use them instead of hardcoding.

---
 t/t6006-rev-list-format.sh | 130 +++++++++++++++++++++++++--------------------
 1 file changed, 72 insertions(+), 58 deletions(-)
t/t6006-rev-list-format.sh +0 -0
index f94f0c4..c248509 100755

t/t6006-rev-list-format.sh test_description='git rev-list --pretty=format test' · line 9

Quoted 6 lines
t/t6006-rev-list-format.sh +1 -2
@@ -6,8 +6,19 @@ test_description='git rev-list --pretty=format test'
 
 test_tick
 test_expect_success 'setup' '
-touch foo && git add foo && git commit -m "added foo" &&
-  echo changed >foo && git commit -a -m "changed foo"
+	touch foo &&

This is inherited from the original, but these days we try to avoid touch, unless it is about setting a new file timestamp. The canonical (in the script we write) way to create an empty file is:

    : >foo

with or without ": ", it does not matter that much.

t/t6006-rev-list-format.sh test_description='git rev-list --pretty=format test' · line 13

Quoted 4 lines
t/t6006-rev-list-format.sh +4 -0
+	git add foo &&
+	git commit -m "added foo" &&
+	head1=$(git rev-parse --verify HEAD) &&
+	head1_7=$(echo $head1 | cut -c1-7) &&

Why do we want "whatever_7" variables and use "cut -c1-7" to produce them? Is "7" something we care deeply about?

I think what we care a lot more than "7" that happens to be the current default value is to make sure that, if we ever update the default abbreviation length to a larger value, the abbreviation shown with --format=%h is consistent with the abbreviation that is given by rev-parse --short.

    head1_short=$(git rev-parse --short $head1)

perhaps?

t/t6006-rev-list-format.sh test_description='git rev-list --pretty=format test' · line 18

Quoted 5 lines
t/t6006-rev-list-format.sh +5 -0
+	echo changed >foo &&
+	git commit -a -m "changed foo" &&
+	head2=$(git rev-parse --verify HEAD) &&
+	head2_7=$(echo $head2 | cut -c1-7) &&
+	head2_parent=$(git cat-file -p HEAD | grep parent | cut -f 2 -d" ") &&

Do not use "cat-file -p" that is for human consumption in scripts, unless you are testing how the format for human consumption should look like (we may later add more pretty-print to them), which is not the case here.

Also be careful and pay attention to the end of the header; you do not want to pick up a random "parent" string in the middle of a log message.

    head2_parent=$(git cat-file commit HEAD | sed -n -e "s/^parent //p" -e "/^$/q")

would be much better.

t/t6006-rev-list-format.sh test_description='git rev-list --pretty=format test' · line 20

Quoted 2 lines
t/t6006-rev-list-format.sh +2 -0
+	head2_parent_7=$(echo $head2_parent | cut -c1-7) &&
+	tree2=$(git cat-file -p HEAD | grep tree | cut -f 2 -d" ") &&

Likewise.

t/t6006-rev-list-format.sh test_description='git rev-list --pretty=format test' · line 21

Quoted 1 line
t/t6006-rev-list-format.sh +1 -0
+	tree2_7=$(echo $tree2 | cut -c1-7)

Likewise.

t/t6006-rev-list-format.sh This commit message is much longer than the others, · line 151

Quoted 13 lines
t/t6006-rev-list-format.sh +5 -2
@@ -131,39 +142,42 @@ This commit message is much longer than the others,
 and it will be encoded in iso8859-1. We should therefore
 include an iso8859 character: ¡bueno!
 EOF
+
 test_expect_success 'setup complex body' '
-git config i18n.commitencoding iso8859-1 &&
-  echo change2 >foo && git commit -a -F commit-msg
+	git config i18n.commitencoding iso8859-1 &&
+	echo change2 >foo && git commit -a -F commit-msg &&
+	head3=$(git rev-parse --verify HEAD) &&
+	head3_7=$(echo $head3 | cut -c1-7)
 '

Likewise.

Thanks.

#20 lore raw

Re: [PATCH v4 1/4] t6006 (rev-list-format): don't hardcode SHA-1 in expected outputs

Quoted 27 lines
Quoted 17 lines · Alexey Shumkin

The expected SHA-1 digests are always available in variables. Use them instead of hardcoding.

---
 t/t6006-rev-list-format.sh | 130

+++++++++++++++++++++++++-------------------- 1 file changed, 72 insertions(+), 58 deletions(-)

t/t6006-rev-list-format.sh +0 -0
index f94f0c4..c248509 100755
@@ -6,8 +6,19 @@ test_description='git rev-list --pretty=format

test'
test_tick
test_expect_success 'setup' '

t/t6006-rev-list-format.sh test_description='git rev-list --pretty=format test' · line 9

Quoted 3 lines
t/t6006-rev-list-format.sh +1 -2
-touch foo && git add foo && git commit -m "added foo" &&
-  echo changed >foo && git commit -a -m "changed foo"
+	touch foo &&

This is inherited from the original, but these days we try to avoid touch, unless it is about setting a new file timestamp. The canonical (in the script we write) way to create an empty file is:

Quoted 3 lines
    : >foo

with or without ": ", it does not matter that much.

Ok!

Quoted 8 lines

t/t6006-rev-list-format.sh test_description='git rev-list --pretty=format test' · line 13

Quoted 5 lines
t/t6006-rev-list-format.sh +4 -0
+	git add foo &&
+	git commit -m "added foo" &&
+	head1=$(git rev-parse --verify HEAD) &&
+	head1_7=$(echo $head1 | cut -c1-7) &&

Why do we want "whatever_7" variables and use "cut -c1-7" to produce them? Is "7" something we care deeply about?

I did not spend too much time to think of names of variables at the moment I was writing this code )

Quoted 10 lines

I think what we care a lot more than "7" that happens to be the current default value is to make sure that, if we ever update the default abbreviation length to a larger value, the abbreviation shown with --format=%h is consistent with the abbreviation that is given by rev-parse --short.

    head1_short=$(git rev-parse --short $head1)

perhaps?

It's an inherited code from 1.5 years ago Git ;) taken from some other tests
I'll change it as you propose )

Quoted 13 lines
Quoted 7 lines
t/t6006-rev-list-format.sh +5 -0
+	echo changed >foo &&
+	git commit -a -m "changed foo" &&
+	head2=$(git rev-parse --verify HEAD) &&
+	head2_7=$(echo $head2 | cut -c1-7) &&
+	head2_parent=$(git cat-file -p HEAD | grep parent | cut -f

2 -d" ") &&

Do not use "cat-file -p" that is for human consumption in scripts, unless you are testing how the format for human consumption should look like (we may later add more pretty-print to them), which is not the case here.

Quoted 8 lines

Also be careful and pay attention to the end of the header; you do not want to pick up a random "parent" string in the middle of a log message.

    head2_parent=$(git cat-file commit HEAD | sed -n -e

"s/^parent //p" -e "/^$/q")

would be much better.

yep! you're definitely right

Quoted 28 lines
Quoted 4 lines
t/t6006-rev-list-format.sh +2 -0
+	head2_parent_7=$(echo $head2_parent | cut -c1-7) &&
+	tree2=$(git cat-file -p HEAD | grep tree | cut -f 2 -d" ")

&&

Likewise.

t/t6006-rev-list-format.sh test_description='git rev-list --pretty=format test' · line 21

Quoted 1 line
t/t6006-rev-list-format.sh +1 -0
+	tree2_7=$(echo $tree2 | cut -c1-7)

Likewise.

t/t6006-rev-list-format.sh This commit message is much longer than the others, · line 151

Quoted 13 lines
t/t6006-rev-list-format.sh +0 -0
@@ -131,39 +142,42 @@ This commit message is much longer than the

others, and it will be encoded in iso8859-1. We should therefore
include an iso8859 character: ¡bueno!
EOF

t/t6006-rev-list-format.sh +5 -2
+
 test_expect_success 'setup complex body' '
-git config i18n.commitencoding iso8859-1 &&
-  echo change2 >foo && git commit -a -F commit-msg
+	git config i18n.commitencoding iso8859-1 &&
+	echo change2 >foo && git commit -a -F commit-msg &&
+	head3=$(git rev-parse --verify HEAD) &&
+	head3_7=$(echo $head3 | cut -c1-7)
 '

Likewise.

Thanks.

#21 lore raw

Re: [PATCH v4 1/4] t6006 (rev-list-format): don't hardcode SHA-1 in expected outputs

In reply to Junio C Hamano
Quoted 40 lines

Why do we want "whatever_7" variables and use "cut -c1-7" to produce them? Is "7" something we care deeply about?

I think what we care a lot more than "7" that happens to be the current default value is to make sure that, if we ever update the default abbreviation length to a larger value, the abbreviation shown with --format=%h is consistent with the abbreviation that is given by rev-parse --short.

    head1_short=$(git rev-parse --short $head1)

perhaps?

Quoted 6 lines
t/t6006-rev-list-format.sh +5 -0
+	echo changed >foo &&
+	git commit -a -m "changed foo" &&
+	head2=$(git rev-parse --verify HEAD) &&
+	head2_7=$(echo $head2 | cut -c1-7) &&
+	head2_parent=$(git cat-file -p HEAD | grep parent | cut -f

2 -d" ") &&

Do not use "cat-file -p" that is for human consumption in scripts, unless you are testing how the format for human consumption should look like (we may later add more pretty-print to them), which is not the case here.

Also be careful and pay attention to the end of the header; you do not want to pick up a random "parent" string in the middle of a log message.

    head2_parent=$(git cat-file commit HEAD | sed -n -e

"s/^parent //p" -e "/^$/q")

would be much better.

Quoted 3 lines
(quoted diff) +2 -0
+	head2_parent_7=$(echo $head2_parent | cut -c1-7) &&
+	tree2=$(git cat-file -p HEAD | grep tree | cut -f 2 -d" ")

&&

Likewise.

Quoted 3 lines

t/t6006-rev-list-format.sh test_description='git rev-list --pretty=format test' · line 21

Quoted 1 line
t/t6006-rev-list-format.sh +1 -0
+	tree2_7=$(echo $tree2 | cut -c1-7)

Likewise.

but is there "git something" to return abbreviated tree hash except "pretty formats" that is implicitly tested here?

#22 lore raw

Re: [PATCH v4 1/4] t6006 (rev-list-format): don't hardcode SHA-1 in expected outputs

Quoted 15 lines · Alexey Shumkin
Quoted 15 lines

Why do we want "whatever_7" variables and use "cut -c1-7" to produce them? Is "7" something we care deeply about?

I think what we care a lot more than "7" that happens to be the current default value is to make sure that, if we ever update the default abbreviation length to a larger value, the abbreviation shown with --format=%h is consistent with the abbreviation that is given by rev-parse --short.

    head1_short=$(git rev-parse --short $head1)

perhaps?
...
Likewise.

Quoted 5 lines
Quoted 3 lines

t/t6006-rev-list-format.sh test_description='git rev-list --pretty=format test' · line 21

Quoted 1 line
t/t6006-rev-list-format.sh +1 -0
+	tree2_7=$(echo $tree2 | cut -c1-7)

Likewise.

but is there "git something" to return abbreviated tree hash except "pretty formats" that is implicitly tested here?

Does "git rev-parse --short $tree2" count?

#23 lore raw

Re: [PATCH v4 1/4] t6006 (rev-list-format): don't hardcode SHA-1 in expected outputs

Quoted 17 lines
Quoted 15 lines · Alexey Shumkin
Quoted 15 lines

Why do we want "whatever_7" variables and use "cut -c1-7" to produce them? Is "7" something we care deeply about?

I think what we care a lot more than "7" that happens to be the current default value is to make sure that, if we ever update the default abbreviation length to a larger value, the abbreviation shown with --format=%h is consistent with the abbreviation that is given by rev-parse --short.

    head1_short=$(git rev-parse --short $head1)

perhaps?
...
Likewise.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

t/t6006-rev-list-format.sh test_description='git rev-list --pretty=format test' · line 21

Quoted 1 line
t/t6006-rev-list-format.sh +1 -0
+	tree2_7=$(echo $tree2 | cut -c1-7)

Likewise.

but is there "git something" to return abbreviated tree hash except "pretty formats" that is implicitly tested here?

Does "git rev-parse --short $tree2" count?

Oops! Yep!

#24 lore raw

PATCH v4 2/4 t7102 (reset): refactoring: don't hardcode SHA-1 in expected outputs

In reply to Alexey Shumkin

The expected SHA-1 digests are always available in variables. Use them instead of hardcoding.

---
 t/t7102-reset.sh | 41 +++++++++++++++++++++--------------------
 1 file changed, 21 insertions(+), 20 deletions(-)
t/t7102-reset.sh +21 -20
index b096dc8..cf492f4 100755
@@ -28,7 +28,8 @@ test_expect_success 'creating initial files and commits' '
 
 	echo "1st line 2nd file" >secondfile &&
 	echo "2nd line 2nd file" >>secondfile &&
-	git commit -a -m "modify 2nd file"
+	git commit -a -m "modify 2nd file" &&
+	head5=$(git rev-parse --verify HEAD)
 '
 # git log --pretty=oneline # to see those SHA1 involved
 
@@ -56,7 +57,7 @@ test_expect_success 'giving a non existing revision should fail' '
 	test_must_fail git reset --mixed aaaaaa &&
 	test_must_fail git reset --soft aaaaaa &&
 	test_must_fail git reset --hard aaaaaa &&
-	check_changes 3ec39651e7f44ea531a5de18a9fa791c0fd370fc
+	check_changes $head5
 '
 
 test_expect_success 'reset --soft with unmerged index should fail' '
@@ -74,7 +75,7 @@ test_expect_success \
 	test_must_fail git reset --hard -- first &&
 	test_must_fail git reset --soft HEAD^ -- first &&
 	test_must_fail git reset --hard HEAD^ -- first &&
-	check_changes 3ec39651e7f44ea531a5de18a9fa791c0fd370fc
+	check_changes $head5
 '
 
 test_expect_success 'giving unrecognized options should fail' '
@@ -86,7 +87,7 @@ test_expect_success 'giving unrecognized options should fail' '
 	test_must_fail git reset --soft -o &&
 	test_must_fail git reset --hard --other &&
 	test_must_fail git reset --hard -o &&
-	check_changes 3ec39651e7f44ea531a5de18a9fa791c0fd370fc
+	check_changes $head5
 '
 
 test_expect_success \
@@ -110,7 +111,7 @@ test_expect_success \
 
 	git checkout master &&
 	git branch -D branch1 branch2 &&
-	check_changes 3ec39651e7f44ea531a5de18a9fa791c0fd370fc
+	check_changes $head5
 '
 
 test_expect_success \
@@ -133,27 +134,27 @@ test_expect_success \
 
 	git checkout master &&
 	git branch -D branch3 branch4 &&
-	check_changes 3ec39651e7f44ea531a5de18a9fa791c0fd370fc
+	check_changes $head5
 '
 
 test_expect_success \
 	'resetting to HEAD with no changes should succeed and do nothing' '
 	git reset --hard &&
-		check_changes 3ec39651e7f44ea531a5de18a9fa791c0fd370fc &&
+		check_changes $head5 &&
 	git reset --hard HEAD &&
-		check_changes 3ec39651e7f44ea531a5de18a9fa791c0fd370fc &&
+		check_changes $head5 &&
 	git reset --soft &&
-		check_changes 3ec39651e7f44ea531a5de18a9fa791c0fd370fc &&
+		check_changes $head5 &&
 	git reset --soft HEAD &&
-		check_changes 3ec39651e7f44ea531a5de18a9fa791c0fd370fc &&
+		check_changes $head5 &&
 	git reset --mixed &&
-		check_changes 3ec39651e7f44ea531a5de18a9fa791c0fd370fc &&
+		check_changes $head5 &&
 	git reset --mixed HEAD &&
-		check_changes 3ec39651e7f44ea531a5de18a9fa791c0fd370fc &&
+		check_changes $head5 &&
 	git reset &&
-		check_changes 3ec39651e7f44ea531a5de18a9fa791c0fd370fc &&
+		check_changes $head5 &&
 	git reset HEAD &&
-		check_changes 3ec39651e7f44ea531a5de18a9fa791c0fd370fc
+		check_changes $head5
 '
 
 >.diff_expect
@@ -176,7 +177,7 @@ test_expect_success '--soft reset only should show changes in diff --cached' '
 	git reset --soft HEAD^ &&
 	check_changes d1a4bc3abce4829628ae2dcb0d60ef3d1a78b1c4 &&
 	test "$(git rev-parse ORIG_HEAD)" = \
-			3ec39651e7f44ea531a5de18a9fa791c0fd370fc
+			$head5
 '
 
 >.diff_expect
@@ -193,7 +194,7 @@ test_expect_success \
 	git commit -a -C ORIG_HEAD &&
 	check_changes 3d3b7be011a58ca0c179ae45d94e6c83c0b0cd0d &&
 	test "$(git rev-parse ORIG_HEAD)" = \
-			3ec39651e7f44ea531a5de18a9fa791c0fd370fc
+			$head5
 '
 
 >.diff_expect
@@ -303,7 +304,7 @@ test_expect_success 'redoing the last two commits should succeed' '
 	echo "1st line 2nd file" >secondfile &&
 	echo "2nd line 2nd file" >>secondfile &&
 	git commit -a -m "modify 2nd file" &&
-	check_changes 3ec39651e7f44ea531a5de18a9fa791c0fd370fc
+	check_changes $head5
 '
 
 >.diff_expect
@@ -341,15 +342,15 @@ EOF
 test_expect_success \
 	'--hard reset to ORIG_HEAD should clear a fast-forward merge' '
 	git reset --hard HEAD^ &&
-	check_changes 3ec39651e7f44ea531a5de18a9fa791c0fd370fc &&
+	check_changes $head5 &&
 
 	git pull . branch1 &&
 	git reset --hard ORIG_HEAD &&
-	check_changes 3ec39651e7f44ea531a5de18a9fa791c0fd370fc &&
+	check_changes $head5 &&
 
 	git checkout master &&
 	git branch -D branch1 branch2 &&
-	check_changes 3ec39651e7f44ea531a5de18a9fa791c0fd370fc
+	check_changes $head5
 '
 
 cat > expect << EOF
Signature · 1 line
1.8.1.1.10.g9255f3f
#25 lore raw

Re: [PATCH v4 2/4] t7102 (reset): refactoring: don't hardcode SHA-1 in expected outputs

Quoted 5 lines · Alexey Shumkin

The expected SHA-1 digests are always available in variables. Use them instead of hardcoding.

---

Looks good (" refactoring:" in the title may not want to be there, though).

Thanks.

Quoted 136 lines
 t/t7102-reset.sh | 41 +++++++++++++++++++++--------------------
 1 file changed, 21 insertions(+), 20 deletions(-)
t/t7102-reset.sh +21 -20
index b096dc8..cf492f4 100755
@@ -28,7 +28,8 @@ test_expect_success 'creating initial files and commits' '
 
 	echo "1st line 2nd file" >secondfile &&
 	echo "2nd line 2nd file" >>secondfile &&
-	git commit -a -m "modify 2nd file"
+	git commit -a -m "modify 2nd file" &&
+	head5=$(git rev-parse --verify HEAD)
 '
 # git log --pretty=oneline # to see those SHA1 involved
 
@@ -56,7 +57,7 @@ test_expect_success 'giving a non existing revision should fail' '
 	test_must_fail git reset --mixed aaaaaa &&
 	test_must_fail git reset --soft aaaaaa &&
 	test_must_fail git reset --hard aaaaaa &&
-	check_changes 3ec39651e7f44ea531a5de18a9fa791c0fd370fc
+	check_changes $head5
 '
 
 test_expect_success 'reset --soft with unmerged index should fail' '
@@ -74,7 +75,7 @@ test_expect_success \
 	test_must_fail git reset --hard -- first &&
 	test_must_fail git reset --soft HEAD^ -- first &&
 	test_must_fail git reset --hard HEAD^ -- first &&
-	check_changes 3ec39651e7f44ea531a5de18a9fa791c0fd370fc
+	check_changes $head5
 '
 
 test_expect_success 'giving unrecognized options should fail' '
@@ -86,7 +87,7 @@ test_expect_success 'giving unrecognized options should fail' '
 	test_must_fail git reset --soft -o &&
 	test_must_fail git reset --hard --other &&
 	test_must_fail git reset --hard -o &&
-	check_changes 3ec39651e7f44ea531a5de18a9fa791c0fd370fc
+	check_changes $head5
 '
 
 test_expect_success \
@@ -110,7 +111,7 @@ test_expect_success \
 
 	git checkout master &&
 	git branch -D branch1 branch2 &&
-	check_changes 3ec39651e7f44ea531a5de18a9fa791c0fd370fc
+	check_changes $head5
 '
 
 test_expect_success \
@@ -133,27 +134,27 @@ test_expect_success \
 
 	git checkout master &&
 	git branch -D branch3 branch4 &&
-	check_changes 3ec39651e7f44ea531a5de18a9fa791c0fd370fc
+	check_changes $head5
 '
 
 test_expect_success \
 	'resetting to HEAD with no changes should succeed and do nothing' '
 	git reset --hard &&
-		check_changes 3ec39651e7f44ea531a5de18a9fa791c0fd370fc &&
+		check_changes $head5 &&
 	git reset --hard HEAD &&
-		check_changes 3ec39651e7f44ea531a5de18a9fa791c0fd370fc &&
+		check_changes $head5 &&
 	git reset --soft &&
-		check_changes 3ec39651e7f44ea531a5de18a9fa791c0fd370fc &&
+		check_changes $head5 &&
 	git reset --soft HEAD &&
-		check_changes 3ec39651e7f44ea531a5de18a9fa791c0fd370fc &&
+		check_changes $head5 &&
 	git reset --mixed &&
-		check_changes 3ec39651e7f44ea531a5de18a9fa791c0fd370fc &&
+		check_changes $head5 &&
 	git reset --mixed HEAD &&
-		check_changes 3ec39651e7f44ea531a5de18a9fa791c0fd370fc &&
+		check_changes $head5 &&
 	git reset &&
-		check_changes 3ec39651e7f44ea531a5de18a9fa791c0fd370fc &&
+		check_changes $head5 &&
 	git reset HEAD &&
-		check_changes 3ec39651e7f44ea531a5de18a9fa791c0fd370fc
+		check_changes $head5
 '
 
 >.diff_expect
@@ -176,7 +177,7 @@ test_expect_success '--soft reset only should show changes in diff --cached' '
 	git reset --soft HEAD^ &&
 	check_changes d1a4bc3abce4829628ae2dcb0d60ef3d1a78b1c4 &&
 	test "$(git rev-parse ORIG_HEAD)" = \
-			3ec39651e7f44ea531a5de18a9fa791c0fd370fc
+			$head5
 '
 
 >.diff_expect
@@ -193,7 +194,7 @@ test_expect_success \
 	git commit -a -C ORIG_HEAD &&
 	check_changes 3d3b7be011a58ca0c179ae45d94e6c83c0b0cd0d &&
 	test "$(git rev-parse ORIG_HEAD)" = \
-			3ec39651e7f44ea531a5de18a9fa791c0fd370fc
+			$head5
 '
 
 >.diff_expect
@@ -303,7 +304,7 @@ test_expect_success 'redoing the last two commits should succeed' '
 	echo "1st line 2nd file" >secondfile &&
 	echo "2nd line 2nd file" >>secondfile &&
 	git commit -a -m "modify 2nd file" &&
-	check_changes 3ec39651e7f44ea531a5de18a9fa791c0fd370fc
+	check_changes $head5
 '
 
 >.diff_expect
@@ -341,15 +342,15 @@ EOF
 test_expect_success \
 	'--hard reset to ORIG_HEAD should clear a fast-forward merge' '
 	git reset --hard HEAD^ &&
-	check_changes 3ec39651e7f44ea531a5de18a9fa791c0fd370fc &&
+	check_changes $head5 &&
 
 	git pull . branch1 &&
 	git reset --hard ORIG_HEAD &&
-	check_changes 3ec39651e7f44ea531a5de18a9fa791c0fd370fc &&
+	check_changes $head5 &&
 
 	git checkout master &&
 	git branch -D branch1 branch2 &&
-	check_changes 3ec39651e7f44ea531a5de18a9fa791c0fd370fc
+	check_changes $head5
 '
 
 cat > expect << EOF
#26 lore raw

Re: [PATCH v4 2/4] t7102 (reset): refactoring: don't hardcode SHA-1 in expected outputs

Quoted 10 lines
Quoted 5 lines · Alexey Shumkin

The expected SHA-1 digests are always available in variables. Use them instead of hardcoding.

---

Looks good (" refactoring:" in the title may not want to be there, though).

oops, it's remained from "working version" after rebasing

Quoted 147 lines

Thanks.

Quoted 144 lines
 t/t7102-reset.sh | 41 +++++++++++++++++++++--------------------
 1 file changed, 21 insertions(+), 20 deletions(-)
t/t7102-reset.sh +0 -0
index b096dc8..cf492f4 100755
@@ -28,7 +28,8 @@ test_expect_success 'creating initial files and

commits' '

t/t7102-reset.sh +2 -1
 	echo "1st line 2nd file" >secondfile &&
 	echo "2nd line 2nd file" >>secondfile &&
-	git commit -a -m "modify 2nd file"
+	git commit -a -m "modify 2nd file" &&
+	head5=$(git rev-parse --verify HEAD)
 '
 # git log --pretty=oneline # to see those SHA1 involved
@@ -56,7 +57,7 @@ test_expect_success 'giving a non existing

revision should fail' ' test_must_fail git reset --mixed aaaaaa &&

t/t7102-reset.sh +1 -1
 	test_must_fail git reset --soft aaaaaa &&
 	test_must_fail git reset --hard aaaaaa &&
-	check_changes 3ec39651e7f44ea531a5de18a9fa791c0fd370fc
+	check_changes $head5
 '
 
 test_expect_success 'reset --soft with unmerged index should fail'

' @@ -74,7 +75,7 @@ test_expect_success \

t/t7102-reset.sh +1 -1
 	test_must_fail git reset --hard -- first &&
 	test_must_fail git reset --soft HEAD^ -- first &&
 	test_must_fail git reset --hard HEAD^ -- first &&
-	check_changes 3ec39651e7f44ea531a5de18a9fa791c0fd370fc
+	check_changes $head5
 '
 
 test_expect_success 'giving unrecognized options should fail' '
@@ -86,7 +87,7 @@ test_expect_success 'giving unrecognized options

should fail' ' test_must_fail git reset --soft -o &&

t/t7102-reset.sh +3 -3
 	test_must_fail git reset --hard --other &&
 	test_must_fail git reset --hard -o &&
-	check_changes 3ec39651e7f44ea531a5de18a9fa791c0fd370fc
+	check_changes $head5
 '
 
 test_expect_success \
@@ -110,7 +111,7 @@ test_expect_success \
 
 	git checkout master &&
 	git branch -D branch1 branch2 &&
-	check_changes 3ec39651e7f44ea531a5de18a9fa791c0fd370fc
+	check_changes $head5
 '
 
 test_expect_success \
@@ -133,27 +134,27 @@ test_expect_success \
 
 	git checkout master &&
 	git branch -D branch3 branch4 &&
-	check_changes 3ec39651e7f44ea531a5de18a9fa791c0fd370fc
+	check_changes $head5
 '
 
 test_expect_success \
 	'resetting to HEAD with no changes should succeed and do

nothing' ' git reset --hard &&

t/t7102-reset.sh +0 -1
-		check_changes

3ec39651e7f44ea531a5de18a9fa791c0fd370fc &&

t/t7102-reset.sh +1 -1
+		check_changes $head5 &&
 	git reset --hard HEAD &&
-		check_changes

3ec39651e7f44ea531a5de18a9fa791c0fd370fc &&

t/t7102-reset.sh +1 -1
+		check_changes $head5 &&
 	git reset --soft &&
-		check_changes

3ec39651e7f44ea531a5de18a9fa791c0fd370fc &&

t/t7102-reset.sh +1 -1
+		check_changes $head5 &&
 	git reset --soft HEAD &&
-		check_changes

3ec39651e7f44ea531a5de18a9fa791c0fd370fc &&

t/t7102-reset.sh +1 -1
+		check_changes $head5 &&
 	git reset --mixed &&
-		check_changes

3ec39651e7f44ea531a5de18a9fa791c0fd370fc &&

t/t7102-reset.sh +1 -1
+		check_changes $head5 &&
 	git reset --mixed HEAD &&
-		check_changes

3ec39651e7f44ea531a5de18a9fa791c0fd370fc &&

t/t7102-reset.sh +1 -1
+		check_changes $head5 &&
 	git reset &&
-		check_changes

3ec39651e7f44ea531a5de18a9fa791c0fd370fc &&

t/t7102-reset.sh +1 -1
+		check_changes $head5 &&
 	git reset HEAD &&
-		check_changes

3ec39651e7f44ea531a5de18a9fa791c0fd370fc

t/t7102-reset.sh +1 -0
+		check_changes $head5
 '
 
 >.diff_expect
@@ -176,7 +177,7 @@ test_expect_success '--soft reset only should

show changes in diff --cached' ' git reset --soft HEAD^ &&

t/t7102-reset.sh +2 -2
 	check_changes d1a4bc3abce4829628ae2dcb0d60ef3d1a78b1c4 &&
 	test "$(git rev-parse ORIG_HEAD)" = \
-			3ec39651e7f44ea531a5de18a9fa791c0fd370fc
+			$head5
 '
 
 >.diff_expect
@@ -193,7 +194,7 @@ test_expect_success \
 	git commit -a -C ORIG_HEAD &&
 	check_changes 3d3b7be011a58ca0c179ae45d94e6c83c0b0cd0d &&
 	test "$(git rev-parse ORIG_HEAD)" = \
-			3ec39651e7f44ea531a5de18a9fa791c0fd370fc
+			$head5
 '
 
 >.diff_expect
@@ -303,7 +304,7 @@ test_expect_success 'redoing the last two

commits should succeed' ' echo "1st line 2nd file" >secondfile &&

t/t7102-reset.sh +1 -1
 	echo "2nd line 2nd file" >>secondfile &&
 	git commit -a -m "modify 2nd file" &&
-	check_changes 3ec39651e7f44ea531a5de18a9fa791c0fd370fc
+	check_changes $head5
 '
 
 >.diff_expect
@@ -341,15 +342,15 @@ EOF
 test_expect_success \
 	'--hard reset to ORIG_HEAD should clear a fast-forward

merge' ' git reset --hard HEAD^ &&

t/t7102-reset.sh +3 -3
-	check_changes 3ec39651e7f44ea531a5de18a9fa791c0fd370fc &&
+	check_changes $head5 &&
 
 	git pull . branch1 &&
 	git reset --hard ORIG_HEAD &&
-	check_changes 3ec39651e7f44ea531a5de18a9fa791c0fd370fc &&
+	check_changes $head5 &&
 
 	git checkout master &&
 	git branch -D branch1 branch2 &&
-	check_changes 3ec39651e7f44ea531a5de18a9fa791c0fd370fc
+	check_changes $head5
 '
 
 cat > expect << EOF
#27 lore raw

PATCH v4 3/4 pretty: Add failing tests: user format ignores i18n.logOutputEncoding setting

In reply to Alexey Shumkin

The following two commands are expected to give the same output to a terminal:

	$ git log --oneline --no-color
	$ git log --pretty=format:'%h %s'

However, the former pays attention to i18n.logOutputEncoding configuration, while the latter does not when it format "%s". Log messages written in an encoding i18n.commitEncoding which differs from terminal encoding are shown corrupted with the latter even when i18n.logOutputEncoding and terminal encoding are the same.

The same corruption is true for

	$ git diff --submodule=log
and
	$ git rev-list --pretty=format:%s HEAD
and
	$ git reset --hard
---
 t/t4041-diff-submodule-option.sh | 33 ++++++++-------
 t/t4205-log-pretty-formats.sh    | 43 +++++++++++++++----
 t/t6006-rev-list-format.sh       | 90 ++++++++++++++++++++++++++--------------
 t/t7102-reset.sh                 | 32 +++++++++++---
 4 files changed, 138 insertions(+), 60 deletions(-)
t/t4041-diff-submodule-option.sh +18 -15
index 32d4a60..e7d6363 100755
@@ -1,6 +1,7 @@
 #!/bin/sh
 #
 # Copyright (c) 2009 Jens Lehmann, based on t7401 by Ping Yin
+# Copyright (c) 2011 Alexey Shumkin (+ non-UTF-8 commit encoding tests)
 #
 
 test_description='Support for verbose submodule differences in git diff
@@ -10,6 +11,7 @@ This test tries to verify the sanity of the --submodule option of git diff.
 
 . ./test-lib.sh
 
+added=$(printf "\320\264\320\276\320\261\320\260\320\262\320\273\320\265\320\275")
 add_file () {
 	(
 		cd "$1" &&
@@ -19,7 +21,8 @@ add_file () {
 			echo "$name" >"$name" &&
 			git add "$name" &&
 			test_tick &&
-			git commit -m "Add $name" || exit
+			msg_added_cp1251=$(echo "Add $name ($added $name)" | iconv -f utf-8 -t cp1251) &&
+			git -c 'i18n.commitEncoding=cp1251' commit -m "$msg_added_cp1251"
 		done >/dev/null &&
 		git rev-parse --short --verify HEAD
 	)
@@ -89,29 +92,29 @@ test_expect_success 'diff.submodule does not affect plumbing' '
 commit_file sm1 &&
 head2=$(add_file sm1 foo3)
 
-test_expect_success 'modified submodule(forward)' '
+test_expect_failure 'modified submodule(forward)' '
 	git diff-index -p --submodule=log HEAD >actual &&
 	cat >expected <<-EOF &&
 	Submodule sm1 $head1..$head2:
-	  > Add foo3
+	  > Add foo3 ($added foo3)
 	EOF
 	test_cmp expected actual
 '
 
-test_expect_success 'modified submodule(forward)' '
+test_expect_failure 'modified submodule(forward)' '
 	git diff --submodule=log >actual &&
 	cat >expected <<-EOF &&
 	Submodule sm1 $head1..$head2:
-	  > Add foo3
+	  > Add foo3 ($added foo3)
 	EOF
 	test_cmp expected actual
 '
 
-test_expect_success 'modified submodule(forward) --submodule' '
+test_expect_failure 'modified submodule(forward) --submodule' '
 	git diff --submodule >actual &&
 	cat >expected <<-EOF &&
 	Submodule sm1 $head1..$head2:
-	  > Add foo3
+	  > Add foo3 ($added foo3)
 	EOF
 	test_cmp expected actual
 '
@@ -138,25 +141,25 @@ head3=$(
 	git rev-parse --short --verify HEAD
 )
 
-test_expect_success 'modified submodule(backward)' '
+test_expect_failure 'modified submodule(backward)' '
 	git diff-index -p --submodule=log HEAD >actual &&
 	cat >expected <<-EOF &&
 	Submodule sm1 $head2..$head3 (rewind):
-	  < Add foo3
-	  < Add foo2
+	  < Add foo3 ($added foo3)
+	  < Add foo2 ($added foo2)
 	EOF
 	test_cmp expected actual
 '
 
 head4=$(add_file sm1 foo4 foo5)
-test_expect_success 'modified submodule(backward and forward)' '
+test_expect_failure 'modified submodule(backward and forward)' '
 	git diff-index -p --submodule=log HEAD >actual &&
 	cat >expected <<-EOF &&
 	Submodule sm1 $head2...$head4:
-	  > Add foo5
-	  > Add foo4
-	  < Add foo3
-	  < Add foo2
+	  > Add foo5 ($added foo5)
+	  > Add foo4 ($added foo4)
+	  < Add foo3 ($added foo3)
+	  < Add foo2 ($added foo2)
 	EOF
 	test_cmp expected actual
 '
t/t4205-log-pretty-formats.sh +34 -9

89 lines not on this page · raw message

t/t6006-rev-list-format.sh +59 -31

173 lines not on this page · raw message

t/t7102-reset.sh +27 -5
index cf492f4..699c824 100755
@@ -9,6 +9,14 @@ Documented tests for git reset'
 
 . ./test-lib.sh
 
+commit_msg() {
+	msg=$(printf "modify 2nd file (\320\270\320\267\320\274\320\265\320\275\321\221\320\275 \321\204\320\260\320\271\320\273)")
+	if test -n "$1"; then
+		msg=$(echo $msg | iconv -f utf-8 -t $1)
+	fi
+	echo $msg
+}
+
 test_expect_success 'creating initial files and commits' '
 	test_tick &&
 	echo "1st file" >first &&
@@ -28,7 +36,7 @@ test_expect_success 'creating initial files and commits' '
 
 	echo "1st line 2nd file" >secondfile &&
 	echo "2nd line 2nd file" >>secondfile &&
-	git commit -a -m "modify 2nd file" &&
+	git -c "i18n.commitEncoding=cp1251" commit -a -m "$(commit_msg cp1251)" &&
 	head5=$(git rev-parse --verify HEAD)
 '
 # git log --pretty=oneline # to see those SHA1 involved
@@ -44,6 +52,20 @@ check_changes () {
 	done | test_cmp .cat_expect -
 }
 
+test_expect_failure 'reset --hard message' '
+	hex=$(git log -1 --format="%h") &&
+	git reset --hard > .actual &&
+	echo HEAD is now at $hex $(commit_msg) > .expected &&
+	test_cmp .actual .expected
+'
+
+test_expect_success 'reset --hard message (cp1251 logoutencoding)' '
+	hex=$(git log -1 --format="%h") &&
+	git -c "i18n.logOutputEncoding=cp1251" reset --hard > .actual &&
+	echo HEAD is now at $hex $(commit_msg cp1251) > .expected &&
+	test_cmp .actual .expected
+'
+
 >.diff_expect
 >.cached_expect
 cat >.cat_expect <<EOF
@@ -192,7 +214,7 @@ test_expect_success \
 	'changing files and redo the last commit should succeed' '
 	echo "3rd line 2nd file" >>secondfile &&
 	git commit -a -C ORIG_HEAD &&
-	check_changes 3d3b7be011a58ca0c179ae45d94e6c83c0b0cd0d &&
+	check_changes f06f78b8dd468c722952b77569dd0db212442c25 &&
 	test "$(git rev-parse ORIG_HEAD)" = \
 			$head5
 '
@@ -211,7 +233,7 @@ test_expect_success \
 	git reset --hard HEAD~2 &&
 	check_changes ddaefe00f1da16864591c61fdc7adb5d7cd6b74e &&
 	test "$(git rev-parse ORIG_HEAD)" = \
-			3d3b7be011a58ca0c179ae45d94e6c83c0b0cd0d
+			f06f78b8dd468c722952b77569dd0db212442c25
 '
 
 >.diff_expect
@@ -303,7 +325,7 @@ test_expect_success 'redoing the last two commits should succeed' '
 
 	echo "1st line 2nd file" >secondfile &&
 	echo "2nd line 2nd file" >>secondfile &&
-	git commit -a -m "modify 2nd file" &&
+	git -c "i18n.commitEncoding=cp1251" commit -a -m "$(commit_msg cp1251)" &&
 	check_changes $head5
 '
 
@@ -329,7 +351,7 @@ test_expect_success '--hard reset to HEAD should clear a failed merge' '
 
 	test_must_fail git pull . branch1 &&
 	git reset --hard &&
-	check_changes 77abb337073fb4369a7ad69ff6f5ec0e4d6b54bb
+	check_changes f26fb896db2344fe158ce3720249e1df4d26174b
 '
 
 >.diff_expect
Signature · 1 line
1.8.1.1.10.g9255f3f
#28 lore raw

Re: [PATCH v4 3/4] pretty: Add failing tests: user format ignores i18n.logOutputEncoding setting

Quoted 12 lines · Alexey Shumkin
t/t6006-rev-list-format.sh +0 -3
index c248509..4db43a4 100755
...
@@ -112,12 +133,12 @@ commit $head2
 commit $head1
 EOF
 
-test_format raw-body %B <<'EOF'
-commit 131a310eb913d107dd3c09a65d1651175898735d
-changed foo

t/t6006-rev-list-format.sh commit $head2 · line 143

Quoted 10 lines
t/t6006-rev-list-format.sh +5 -2
+test_format failure raw-body %B <<EOF
+commit $head2
+$changed
 
-commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
-added foo
+commit $head1
+$added
 
 EOF

It may have been easier to follow if you did this "Don't hardcode" as a separate preparatory patch, like your first two patches.

Quoted 8 lines
t/t6006-rev-list-format.sh +1 -1
@@ -135,16 +156,16 @@ commit $head1
 foo
 EOF
 
-cat >commit-msg <<'EOF'
+iconv -f utf-8 -t cp1251 > commit-msg <<EOF
 Test printing of complex bodies
 

t/t6006-rev-list-format.sh commit $head1 · line 168

Quoted 10 lines
t/t6006-rev-list-format.sh +3 -3
 This commit message is much longer than the others,
-and it will be encoded in iso8859-1. We should therefore
-include an iso8859 character: ¡bueno!
+and it will be encoded in cp1251. We should therefore
+include an cp1251 character: так вот!
 EOF
 
 test_expect_success 'setup complex body' '
-	git config i18n.commitencoding iso8859-1 &&
+	git config i18n.commitencoding cp1251 &&

What is going on here?

Is this an example that shows that i18n.commitencoding works correctly with iso8859-1 but not with cp1251?

Quoted 6 lines
t/t7102-reset.sh +0 -0
index cf492f4..699c824 100755
...

t/t7102-reset.sh test_expect_success \ · line 220

Quoted 8 lines
t/t7102-reset.sh +1 -1
@@ -192,7 +214,7 @@ test_expect_success \
 	'changing files and redo the last commit should succeed' '
 	echo "3rd line 2nd file" >>secondfile &&
 	git commit -a -C ORIG_HEAD &&
-	check_changes 3d3b7be011a58ca0c179ae45d94e6c83c0b0cd0d &&
+	check_changes f06f78b8dd468c722952b77569dd0db212442c25 &&
 	test "$(git rev-parse ORIG_HEAD)" = \
 			$head5
 '

This and remaining hunks to this script shows that it would be helped by the same love you gave to other scripts with your first two patches before you add the "non-unicode" tests, no?

#29 lore raw

Re: [PATCH v4 3/4] pretty: Add failing tests: user format ignores i18n.logOutputEncoding setting

Quoted 23 lines
Quoted 21 lines · Alexey Shumkin
t/t6006-rev-list-format.sh +5 -5
index c248509..4db43a4 100755
...
@@ -112,12 +133,12 @@ commit $head2
 commit $head1
 EOF
 
-test_format raw-body %B <<'EOF'
-commit 131a310eb913d107dd3c09a65d1651175898735d
-changed foo
+test_format failure raw-body %B <<EOF
+commit $head2
+$changed
 
-commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
-added foo
+commit $head1
+$added
 
Quoted 4 lines

t/t6006-rev-list-format.sh commit $head2 · line 143

Quoted 1 line
t/t6006-rev-list-format.sh +0 -0
 EOF

It may have been easier to follow if you did this "Don't hardcode" as a separate preparatory patch, like your first two patches.

Yep, I missed that in my bunch of rebasing ;)

Quoted 16 lines
Quoted 16 lines
t/t6006-rev-list-format.sh +3 -3
@@ -135,16 +156,16 @@ commit $head1
 foo
 EOF
 
-cat >commit-msg <<'EOF'
+iconv -f utf-8 -t cp1251 > commit-msg <<EOF
 Test printing of complex bodies
 
 This commit message is much longer than the others,
-and it will be encoded in iso8859-1. We should therefore
-include an iso8859 character: ¡bueno!
+and it will be encoded in cp1251. We should therefore
+include an cp1251 character: так вот!
 EOF
 
Quoted 8 lines

t/t6006-rev-list-format.sh commit $head1 · line 168

Quoted 3 lines
t/t6006-rev-list-format.sh +1 -1
 test_expect_success 'setup complex body' '
-	git config i18n.commitencoding iso8859-1 &&
+	git config i18n.commitencoding cp1251 &&

What is going on here?

Is this an example that shows that i18n.commitencoding works correctly with iso8859-1 but not with cp1251?

It show only that I speak and write Russian not Spanish )) I'll revert back these changes.

Quoted 11 lines
Quoted 11 lines
t/t7102-reset.sh +0 -1
index cf492f4..699c824 100755
...
@@ -192,7 +214,7 @@ test_expect_success \
 	'changing files and redo the last commit should succeed' '
 	echo "3rd line 2nd file" >>secondfile &&
 	git commit -a -C ORIG_HEAD &&
-	check_changes 3d3b7be011a58ca0c179ae45d94e6c83c0b0cd0d &&
Quoted 8 lines

t/t7102-reset.sh test_expect_success \ · line 220

Quoted 4 lines
t/t7102-reset.sh +1 -0
+	check_changes f06f78b8dd468c722952b77569dd0db212442c25 &&
 	test "$(git rev-parse ORIG_HEAD)" = \
 			$head5
 '

This and remaining hunks to this script shows that it would be helped by the same love you gave to other scripts with your first two patches before you add the "non-unicode" tests, no?

Sorry, I haven't got you :-[ (it seems, my English is not good enough) Do you mean "avoid hardcoded SHA-1"?

#30 lore raw

Re: [PATCH v4 3/4] pretty: Add failing tests: user format ignores i18n.logOutputEncoding setting

In reply to Alexey Shumkin
Quoted 39 lines · Alexey Shumkin

The following two commands are expected to give the same output to a terminal:

	$ git log --oneline --no-color
	$ git log --pretty=format:'%h %s'

However, the former pays attention to i18n.logOutputEncoding configuration, while the latter does not when it format "%s". Log messages written in an encoding i18n.commitEncoding which differs from terminal encoding are shown corrupted with the latter even when i18n.logOutputEncoding and terminal encoding are the same.

The same corruption is true for

	$ git diff --submodule=log
and
	$ git rev-list --pretty=format:%s HEAD
and
	$ git reset --hard
---
 t/t4041-diff-submodule-option.sh | 33 ++++++++-------
 t/t4205-log-pretty-formats.sh    | 43 +++++++++++++++----
 t/t6006-rev-list-format.sh       | 90 ++++++++++++++++++++++++++--------------
 t/t7102-reset.sh                 | 32 +++++++++++---
 4 files changed, 138 insertions(+), 60 deletions(-)
t/t4041-diff-submodule-option.sh +1 -0
index 32d4a60..e7d6363 100755
@@ -1,6 +1,7 @@
 #!/bin/sh
 #
 # Copyright (c) 2009 Jens Lehmann, based on t7401 by Ping Yin
+# Copyright (c) 2011 Alexey Shumkin (+ non-UTF-8 commit encoding tests)
 #
 
 test_description='Support for verbose submodule differences in git diff

t/t4041-diff-submodule-option.sh This test tries to verify the sanity of the --submodule option of git diff. · line 14

Quoted 4 lines
t/t4041-diff-submodule-option.sh +1 -0
@@ -10,6 +11,7 @@ This test tries to verify the sanity of the --submodule option of git diff.
 
 . ./test-lib.sh
 
+added=$(printf "\320\264\320\276\320\261\320\260\320\262\320\273\320\265\320\275")

Please have an in-code comment before this line to explain what this variable is about, e.g.

# String "added" in Russian, encoded in UTF-8, used in # sample commit log messages in add_file() function below. added=$(printf "...")

t/t4041-diff-submodule-option.sh add_file () { · line 28

Quoted 13 lines
t/t4041-diff-submodule-option.sh +2 -1
 add_file () {
 	(
 		cd "$1" &&
@@ -19,7 +21,8 @@ add_file () {
 			echo "$name" >"$name" &&
 			git add "$name" &&
 			test_tick &&
-			git commit -m "Add $name" || exit
+			msg_added_cp1251=$(echo "Add $name ($added $name)" | iconv -f utf-8 -t cp1251) &&
+			git -c 'i18n.commitEncoding=cp1251' commit -m "$msg_added_cp1251"
 		done >/dev/null &&
 		git rev-parse --short --verify HEAD
 	)

Does this patch make the all tests in this script fail for people without cp1251 locale installed? We already have tests that depend on 8859-1 and some other locales, and we'd be better off limiting such dependency to the minimum.

Same comment applies to the changes to other test scripts.

Thanks.

#31 lore raw

Re: [PATCH v4 3/4] pretty: Add failing tests: user format ignores i18n.logOutputEncoding setting

Quoted 52 lines
Quoted 39 lines · Alexey Shumkin

The following two commands are expected to give the same output to a terminal:

	$ git log --oneline --no-color
	$ git log --pretty=format:'%h %s'

However, the former pays attention to i18n.logOutputEncoding configuration, while the latter does not when it format "%s". Log messages written in an encoding i18n.commitEncoding which differs from terminal encoding are shown corrupted with the latter even when i18n.logOutputEncoding and terminal encoding are the same.

The same corruption is true for

	$ git diff --submodule=log
and
	$ git rev-list --pretty=format:%s HEAD
and
	$ git reset --hard
---
 t/t4041-diff-submodule-option.sh | 33 ++++++++-------
 t/t4205-log-pretty-formats.sh    | 43 +++++++++++++++----
 t/t6006-rev-list-format.sh       | 90

++++++++++++++++++++++++++--------------
t/t7102-reset.sh | 32 +++++++++++--- 4 files
changed, 138 insertions(+), 60 deletions(-)

(quoted diff) +0 -0

b/t/t4041-diff-submodule-option.sh index 32d4a60..e7d6363 100755

t/t4041-diff-submodule-option.sh +1 -0
@@ -1,6 +1,7 @@
 #!/bin/sh
 #
 # Copyright (c) 2009 Jens Lehmann, based on t7401 by Ping Yin
+# Copyright (c) 2011 Alexey Shumkin (+ non-UTF-8 commit encoding

tests) #

Quoted 7 lines

test_description='Support for verbose submodule differences in git
diff @@ -10,6 +11,7 @@ This test tries to verify the sanity of the --submodule option of git diff.
. ./test-lib.sh

+added=$(printf "\320\264\320\276\320\261\320\260\320\262\320\273\320\265\320\275")

Please have an in-code comment before this line to explain what this variable is about, e.g.

Quoted 3 lines

# String "added" in Russian, encoded in UTF-8, used in # sample commit log messages in add_file() function below. added=$(printf "...")

Ok!

Quoted 12 lines
Quoted 12 lines

add_file () {

t/t4041-diff-submodule-option.sh +1 -1
 	(
 		cd "$1" &&
@@ -19,7 +21,8 @@ add_file () {
 			echo "$name" >"$name" &&
 			git add "$name" &&
 			test_tick &&
-			git commit -m "Add $name" || exit
+			msg_added_cp1251=$(echo "Add $name ($added

$name)" | iconv -f utf-8 -t cp1251) &&

t/t4041-diff-submodule-option.sh +1 -0
+			git -c 'i18n.commitEncoding=cp1251' commit
Quoted 8 lines

t/t4041-diff-submodule-option.sh add_file () { · line 28

Quoted 3 lines
t/t4041-diff-submodule-option.sh +0 -1
-m "$msg_added_cp1251" done >/dev/null &&
 		git rev-parse --short --verify HEAD
 	)

Does this patch make the all tests in this script fail for people without cp1251 locale installed? We already have tests that depend on 8859-1 and some other locales, and we'd be better off limiting such dependency to the minimum.

Hmmm, I'll try to feign something to avoid using cp1251

Quoted 4 lines

Same comment applies to the changes to other test scripts.

Thanks.

#32 lore raw

PATCH v4 4/4 pretty: user format ignores i18n.logOutputEncoding setting

In reply to Alexey Shumkin

From: Alexey Shumkin <[email protected]>

The following two commands are expected to give the same output to a terminal:

	$ git log --oneline --no-color
	$ git log --pretty=format:'%h %s'

However, the former pays attention to i18n.logOutputEncoding configuration, while the latter does not when it format "%s". Log messages written in an encoding i18n.commitEncoding which differs from terminal encoding are shown corrupted with the latter even when i18n.logOutputEncoding and terminal encoding are the same.

The same corruption is true for

	$ git diff --submodule=log
and
	$ git rev-list --pretty=format:%s HEAD
and
	$ git reset --hard
---
 builtin/reset.c                  |  8 ++++++--
 builtin/rev-list.c               |  1 +
 builtin/shortlog.c               |  1 +
 log-tree.c                       |  1 +
 submodule.c                      |  3 +++
 t/t4041-diff-submodule-option.sh | 10 +++++-----
 t/t4205-log-pretty-formats.sh    |  8 ++++----
 t/t6006-rev-list-format.sh       | 10 +++++-----
 t/t7102-reset.sh                 |  2 +-
 9 files changed, 27 insertions(+), 17 deletions(-)
builtin/reset.c +6 -2
index 915cc9f..11c0aa4 100644
@@ -100,11 +100,15 @@ static int reset_index_file(const unsigned char *sha1, int reset_type, int quiet
 
 static void print_new_head_line(struct commit *commit)
 {
-	const char *hex, *body;
+	const char *hex, *body, *encoding;
 
 	hex = find_unique_abbrev(commit->object.sha1, DEFAULT_ABBREV);
 	printf(_("HEAD is now at %s"), hex);
-	body = strstr(commit->buffer, "\n\n");
+	encoding = get_log_output_encoding();
+	body = logmsg_reencode(commit, encoding);
+	if (!body)
+		body = commit->buffer;
+	body = strstr(body, "\n\n");
 	if (body) {
 		const char *eol;
 		size_t len;
builtin/rev-list.c +1 -0
index 67701be..a5ec30d 100644
@@ -111,6 +111,7 @@ static void show_commit(struct commit *commit, void *data)
 		ctx.date_mode = revs->date_mode;
 		ctx.date_mode_explicit = revs->date_mode_explicit;
 		ctx.fmt = revs->commit_format;
+		ctx.output_encoding = get_log_output_encoding();
 		pretty_print_commit(&ctx, commit, &buf);
 		if (revs->graph) {
 			if (buf.len) {
builtin/shortlog.c +1 -0
index 8360514..23c05cd 100644
@@ -163,6 +163,7 @@ void shortlog_add_commit(struct shortlog *log, struct commit *commit)
 		ctx.subject = "";
 		ctx.after_subject = "";
 		ctx.date_mode = DATE_NORMAL;
+		ctx.output_encoding = get_log_output_encoding();
 		pretty_print_commit(&ctx, commit, &ufbuf);
 		buffer = ufbuf.buf;
 	} else if (*buffer) {
log-tree.c +1 -0
index 4f86def..e1ff3a5 100644
@@ -671,6 +671,7 @@ void show_log(struct rev_info *opt)
 	ctx.preserve_subject = opt->preserve_subject;
 	ctx.reflog_info = opt->reflog_info;
 	ctx.fmt = opt->commit_format;
+	ctx.output_encoding = get_log_output_encoding();
 	pretty_print_commit(&ctx, commit, &msgbuf);
 
 	if (opt->add_signoff)
submodule.c +3 -0
index 2f55436..8e42750 100644
@@ -222,10 +222,13 @@ static void print_submodule_summary(struct rev_info *rev, FILE *f,
 	static const char format[] = "  %m %s";
 	struct strbuf sb = STRBUF_INIT;
 	struct commit *commit;
+	const char *log_output_encoding;
 
+	log_output_encoding = get_log_output_encoding();
 	while ((commit = get_revision(rev))) {
 		struct pretty_print_context ctx = {0};
 		ctx.date_mode = rev->date_mode;
+		ctx.output_encoding = log_output_encoding;
 		strbuf_setlen(&sb, 0);
 		if (commit->object.flags & SYMMETRIC_LEFT) {
 			if (del)
t/t4041-diff-submodule-option.sh +5 -5
index e7d6363..39f0609 100755
@@ -92,7 +92,7 @@ test_expect_success 'diff.submodule does not affect plumbing' '
 commit_file sm1 &&
 head2=$(add_file sm1 foo3)
 
-test_expect_failure 'modified submodule(forward)' '
+test_expect_success 'modified submodule(forward)' '
 	git diff-index -p --submodule=log HEAD >actual &&
 	cat >expected <<-EOF &&
 	Submodule sm1 $head1..$head2:
@@ -101,7 +101,7 @@ test_expect_failure 'modified submodule(forward)' '
 	test_cmp expected actual
 '
 
-test_expect_failure 'modified submodule(forward)' '
+test_expect_success 'modified submodule(forward)' '
 	git diff --submodule=log >actual &&
 	cat >expected <<-EOF &&
 	Submodule sm1 $head1..$head2:
@@ -110,7 +110,7 @@ test_expect_failure 'modified submodule(forward)' '
 	test_cmp expected actual
 '
 
-test_expect_failure 'modified submodule(forward) --submodule' '
+test_expect_success 'modified submodule(forward) --submodule' '
 	git diff --submodule >actual &&
 	cat >expected <<-EOF &&
 	Submodule sm1 $head1..$head2:
@@ -141,7 +141,7 @@ head3=$(
 	git rev-parse --short --verify HEAD
 )
 
-test_expect_failure 'modified submodule(backward)' '
+test_expect_success 'modified submodule(backward)' '
 	git diff-index -p --submodule=log HEAD >actual &&
 	cat >expected <<-EOF &&
 	Submodule sm1 $head2..$head3 (rewind):
@@ -152,7 +152,7 @@ test_expect_failure 'modified submodule(backward)' '
 '
 
 head4=$(add_file sm1 foo4 foo5)
-test_expect_failure 'modified submodule(backward and forward)' '
+test_expect_success 'modified submodule(backward and forward)' '
 	git diff-index -p --submodule=log HEAD >actual &&
 	cat >expected <<-EOF &&
 	Submodule sm1 $head2...$head4:
t/t4205-log-pretty-formats.sh +4 -4
index 76ffa0d..54a9704 100755
@@ -57,7 +57,7 @@ test_expect_success 'alias user-defined tformat with %s (cp1251 encoding)' '
 	test_cmp expected-s actual-s
 '
 
-test_expect_failure 'alias user-defined tformat with %s (utf-8 encoding)' '
+test_expect_success 'alias user-defined tformat with %s (utf-8 encoding)' '
 	git log --oneline >expected-s &&
 	git log --pretty="tformat:%h %s" >actual-s &&
 	test_cmp expected-s actual-s
@@ -96,19 +96,19 @@ test_expect_success 'alias loop' '
 	test_must_fail git log --pretty=test-foo
 '
 
-test_expect_failure 'NUL separation' '
+test_expect_success 'NUL separation' '
 	printf "add bar\0$(commit_msg)" >expected &&
 	git log -z --pretty="format:%s" >actual &&
 	test_cmp expected actual
 '
 
-test_expect_failure 'NUL termination' '
+test_expect_success 'NUL termination' '
 	printf "add bar\0$(commit_msg)\0" >expected &&
 	git log -z --pretty="tformat:%s" >actual &&
 	test_cmp expected actual
 '
 
-test_expect_failure 'NUL separation with --stat' '
+test_expect_success 'NUL separation with --stat' '
 	stat0_part=$(git diff --stat HEAD^ HEAD) &&
 	stat1_part=$(git diff-tree --no-commit-id --stat --root HEAD^) &&
 	printf "add bar\n$stat0_part\n\0$(commit_msg)\n$stat1_part\n" >expected &&
t/t6006-rev-list-format.sh +5 -5
index 4db43a4..006e6ab 100755
@@ -116,12 +116,12 @@ Thu, 7 Apr 2005 15:13:13 -0700
 1112911993
 EOF
 
-test_format failure encoding %e <<EOF
+test_format encoding %e <<EOF
 commit $head2
 commit $head1
 EOF
 
-test_format failure subject %s <<EOF
+test_format subject %s <<EOF
 commit $head2
 $changed
 commit $head1
@@ -133,7 +133,7 @@ commit $head2
 commit $head1
 EOF
 
-test_format failure raw-body %B <<EOF
+test_format raw-body %B <<EOF
 commit $head2
 $changed
 
@@ -185,7 +185,7 @@ EOF
 # and following test fails
 git config --unset i18n.commitencoding
 
-test_format failure complex-subject %s <<EOF
+test_format complex-subject %s <<EOF
 commit $head3
 Test printing of complex bodies
 commit $head2
@@ -194,7 +194,7 @@ commit $head1
 $added
 EOF
 
-test_format failure complex-body %b <<EOF
+test_format complex-body %b <<EOF
 commit $head3
 This commit message is much longer than the others,
 and it will be encoded in cp1251. We should therefore
t/t7102-reset.sh +1 -1
index 699c824..ea14c97 100755
@@ -52,7 +52,7 @@ check_changes () {
 	done | test_cmp .cat_expect -
 }
 
-test_expect_failure 'reset --hard message' '
+test_expect_success 'reset --hard message' '
 	hex=$(git log -1 --format="%h") &&
 	git reset --hard > .actual &&
 	echo HEAD is now at $hex $(commit_msg) > .expected &&
Signature · 1 line
1.8.1.1.10.g9255f3f
#33 lore raw

v5 cover Reroll patches against v1.8.3.1

In reply to Alexey Shumkin

Alexey Shumkin (5):
t6006 (rev-list-format): don't hardcode SHA-1 in expected outputs t7102 (reset): don't hardcode SHA-1 in expected outputs t4205 (log-pretty-formats): don't hardcode SHA-1 in expected outputs
pretty: Add failing tests: user format ignores i18n.logOutputEncoding
setting
pretty: user format ignores i18n.logOutputEncoding setting

 builtin/reset.c                  |   8 +-
 builtin/rev-list.c               |   1 +
 builtin/shortlog.c               |   1 +
 log-tree.c                       |   1 +
 submodule.c                      |   3 +
 t/t4041-diff-submodule-option.sh |  25 +++--
 t/t4205-log-pretty-formats.sh    | 179 ++++++++++++++++++++-------------
 t/t6006-rev-list-format.sh       | 209 ++++++++++++++++++++++++---------------
 t/t7102-reset.sh                 |  37 ++++++-
 9 files changed, 299 insertions(+), 165 deletions(-)
Signature · 1 line
1.8.3.1.15.g5c23c1e
#34 lore raw

PATCH v5 1/5 t6006 (rev-list-format): don't hardcode SHA-1 in expected outputs

The expected SHA-1 digests are always available in variables. Use them instead of hardcoding.

---
 t/t6006-rev-list-format.sh | 142 +++++++++++++++++++++++++--------------------
 1 file changed, 79 insertions(+), 63 deletions(-)
t/t6006-rev-list-format.sh +79 -63
index 0393c9f..d32e65e 100755
@@ -7,8 +7,21 @@ test_description='git rev-list --pretty=format test'
 
 test_tick
 test_expect_success 'setup' '
-touch foo && git add foo && git commit -m "added foo" &&
-  echo changed >foo && git commit -a -m "changed foo"
+	: >foo &&
+	git add foo &&
+	git commit -m "added foo" &&
+	head1=$(git rev-parse --verify HEAD) &&
+	head1_short=$(git rev-parse --short $head1) &&
+	tree1=$(git cat-file commit HEAD | sed -n -e "s/^tree //p" -e "/^$/q") &&
+	tree1_short=$(git rev-parse --short $tree1) &&
+	echo changed >foo &&
+	git commit -a -m "changed foo" &&
+	head2=$(git rev-parse --verify HEAD) &&
+	head2_short=$(git rev-parse --short $head2) &&
+	head2_parent=$(git cat-file commit HEAD | sed -n -e "s/^parent //p" -e "/^$/q") &&
+	head2_parent_short=$(git rev-parse --short $head2_parent) &&
+	tree2=$(git cat-file commit HEAD | sed -n -e "s/^tree //p" -e "/^$/q") &&
+	tree2_short=$(git rev-parse --short $tree2)
 '
 
 # usage: test_format name format_string <expected_output
@@ -32,49 +45,49 @@ has_no_color () {
 	test_cmp expect "$1"
 }
 
-test_format percent %%h <<'EOF'
-commit 131a310eb913d107dd3c09a65d1651175898735d
+test_format percent %%h <<EOF
+commit $head2
 %h
-commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
+commit $head1
 %h
 EOF
 
-test_format hash %H%n%h <<'EOF'
-commit 131a310eb913d107dd3c09a65d1651175898735d
-131a310eb913d107dd3c09a65d1651175898735d
-131a310
-commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
-86c75cfd708a0e5868dc876ed5b8bb66c80b4873
-86c75cf
+test_format hash %H%n%h <<EOF
+commit $head2
+$head2
+$head2_short
+commit $head1
+$head1
+$head1_short
 EOF
 
-test_format tree %T%n%t <<'EOF'
-commit 131a310eb913d107dd3c09a65d1651175898735d
-fe722612f26da5064c32ca3843aa154bdb0b08a0
-fe72261
-commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
-4d5fcadc293a348e88f777dc0920f11e7d71441c
-4d5fcad
+test_format tree %T%n%t <<EOF
+commit $head2
+$tree2
+$tree2_short
+commit $head1
+$tree1
+$tree1_short
 EOF
 
-test_format parents %P%n%p <<'EOF'
-commit 131a310eb913d107dd3c09a65d1651175898735d
-86c75cfd708a0e5868dc876ed5b8bb66c80b4873
-86c75cf
-commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
+test_format parents %P%n%p <<EOF
+commit $head2
+$head1
+$head2_parent_short
+commit $head1
 
 
 EOF
 
 # we don't test relative here
-test_format author %an%n%ae%n%ad%n%aD%n%at <<'EOF'
-commit 131a310eb913d107dd3c09a65d1651175898735d
+test_format author %an%n%ae%n%ad%n%aD%n%at <<EOF
+commit $head2
 A U Thor
 [email protected]
 Thu Apr 7 15:13:13 2005 -0700
 Thu, 7 Apr 2005 15:13:13 -0700
 1112911993
-commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
+commit $head1
 A U Thor
 [email protected]
 Thu Apr 7 15:13:13 2005 -0700
@@ -82,14 +95,14 @@ Thu, 7 Apr 2005 15:13:13 -0700
 1112911993
 EOF
 
-test_format committer %cn%n%ce%n%cd%n%cD%n%ct <<'EOF'
-commit 131a310eb913d107dd3c09a65d1651175898735d
+test_format committer %cn%n%ce%n%cd%n%cD%n%ct <<EOF
+commit $head2
 C O Mitter
 [email protected]
 Thu Apr 7 15:13:13 2005 -0700
 Thu, 7 Apr 2005 15:13:13 -0700
 1112911993
-commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
+commit $head1
 C O Mitter
 [email protected]
 Thu Apr 7 15:13:13 2005 -0700
@@ -97,43 +110,43 @@ Thu, 7 Apr 2005 15:13:13 -0700
 1112911993
 EOF
 
-test_format encoding %e <<'EOF'
-commit 131a310eb913d107dd3c09a65d1651175898735d
-commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
+test_format encoding %e <<EOF
+commit $head2
+commit $head1
 EOF
 
-test_format subject %s <<'EOF'
-commit 131a310eb913d107dd3c09a65d1651175898735d
+test_format subject %s <<EOF
+commit $head2
 changed foo
-commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
+commit $head1
 added foo
 EOF
 
-test_format body %b <<'EOF'
-commit 131a310eb913d107dd3c09a65d1651175898735d
-commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
+test_format body %b <<EOF
+commit $head2
+commit $head1
 EOF
 
-test_format raw-body %B <<'EOF'
-commit 131a310eb913d107dd3c09a65d1651175898735d
+test_format raw-body %B <<EOF
+commit $head2
 changed foo
 
-commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
+commit $head1
 added foo
 
 EOF
 
-test_format colors %Credfoo%Cgreenbar%Cbluebaz%Cresetxyzzy <<'EOF'
-commit 131a310eb913d107dd3c09a65d1651175898735d
+test_format colors %Credfoo%Cgreenbar%Cbluebaz%Cresetxyzzy <<EOF
+commit $head2
 foobarbazxyzzy
-commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
+commit $head1
 foobarbazxyzzy
 EOF
 
-test_format advanced-colors '%C(red yellow bold)foo%C(reset)' <<'EOF'
-commit 131a310eb913d107dd3c09a65d1651175898735d
+test_format advanced-colors '%C(red yellow bold)foo%C(reset)' <<EOF
+commit $head2
 foo
-commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
+commit $head1
 foo
 EOF
 
@@ -186,39 +199,42 @@ This commit message is much longer than the others,
 and it will be encoded in iso8859-1. We should therefore
 include an iso8859 character: �bueno!
 EOF
+
 test_expect_success 'setup complex body' '
-git config i18n.commitencoding iso8859-1 &&
-  echo change2 >foo && git commit -a -F commit-msg
+	git config i18n.commitencoding iso8859-1 &&
+	echo change2 >foo && git commit -a -F commit-msg &&
+	head3=$(git rev-parse --verify HEAD) &&
+	head3_short=$(git rev-parse --short $head3)
 '
 
-test_format complex-encoding %e <<'EOF'
-commit 1ed88da4a5b5ed8c449114ac131efc62178734c3
+test_format complex-encoding %e <<EOF
+commit $head3
 iso8859-1
-commit 131a310eb913d107dd3c09a65d1651175898735d
-commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
+commit $head2
+commit $head1
 EOF
 
-test_format complex-subject %s <<'EOF'
-commit 1ed88da4a5b5ed8c449114ac131efc62178734c3
+test_format complex-subject %s <<EOF
+commit $head3
 Test printing of complex bodies
-commit 131a310eb913d107dd3c09a65d1651175898735d
+commit $head2
 changed foo
-commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
+commit $head1
 added foo
 EOF
 
-test_format complex-body %b <<'EOF'
-commit 1ed88da4a5b5ed8c449114ac131efc62178734c3
+test_format complex-body %b <<EOF
+commit $head3
 This commit message is much longer than the others,
 and it will be encoded in iso8859-1. We should therefore
 include an iso8859 character: �bueno!
 
-commit 131a310eb913d107dd3c09a65d1651175898735d
-commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
+commit $head2
+commit $head1
 EOF
 
 test_expect_success '%x00 shows NUL' '
-	echo  >expect commit 1ed88da4a5b5ed8c449114ac131efc62178734c3 &&
+	echo  >expect commit $head3 &&
 	echo >>expect fooQbar &&
 	git rev-list -1 --format=foo%x00bar HEAD >actual.nul &&
 	nul_to_q <actual.nul >actual &&
Signature · 1 line
1.8.3.1.15.g5c23c1e
#35 lore raw

Re: [PATCH v5 1/5] t6006 (rev-list-format): don't hardcode SHA-1 in expected outputs

Quoted 22 lines · Alexey Shumkin

The expected SHA-1 digests are always available in variables. Use them instead of hardcoding.

---
 t/t6006-rev-list-format.sh | 142 +++++++++++++++++++++++++--------------------
 1 file changed, 79 insertions(+), 63 deletions(-)
t/t6006-rev-list-format.sh +4 -2
index 0393c9f..d32e65e 100755
@@ -7,8 +7,21 @@ test_description='git rev-list --pretty=format test'
 
 test_tick
 test_expect_success 'setup' '
-touch foo && git add foo && git commit -m "added foo" &&
-  echo changed >foo && git commit -a -m "changed foo"
+	: >foo &&
+	git add foo &&
+	git commit -m "added foo" &&
+	head1=$(git rev-parse --verify HEAD) &&

t/t6006-rev-list-format.sh test_description='git rev-list --pretty=format test' · line 23

Quoted 10 lines
t/t6006-rev-list-format.sh +10 -0
+	head1_short=$(git rev-parse --short $head1) &&
+	tree1=$(git cat-file commit HEAD | sed -n -e "s/^tree //p" -e "/^$/q") &&
+	tree1_short=$(git rev-parse --short $tree1) &&
+	echo changed >foo &&
+	git commit -a -m "changed foo" &&
+	head2=$(git rev-parse --verify HEAD) &&
+	head2_short=$(git rev-parse --short $head2) &&
+	head2_parent=$(git cat-file commit HEAD | sed -n -e "s/^parent //p" -e "/^$/q") &&
+	head2_parent_short=$(git rev-parse --short $head2_parent) &&
+	tree2=$(git cat-file commit HEAD | sed -n -e "s/^tree //p" -e "/^$/q") &&

With modern Git, you can (and would) write this as

	tree2=$(git rev-parse HEAD:)

(the same for tree1). Other than that, looks sensible.

Will queue with a tweak.

#36 lore raw

PATCH v5 2/5 t7102 (reset): don't hardcode SHA-1 in expected outputs

In reply to Alexey Shumkin

The expected SHA-1 digests are always available in variables. Use them instead of hardcoding.

---
 t/t7102-reset.sh | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
t/t7102-reset.sh +5 -3
index df82ec9..05dfb27 100755
@@ -192,7 +192,8 @@ test_expect_success \
 	'changing files and redo the last commit should succeed' '
 	echo "3rd line 2nd file" >>secondfile &&
 	git commit -a -C ORIG_HEAD &&
-	check_changes 3d3b7be011a58ca0c179ae45d94e6c83c0b0cd0d &&
+	head4=$(git rev-parse --verify HEAD) &&
+	check_changes $head4 &&
 	test "$(git rev-parse ORIG_HEAD)" = \
 			$head5
 '
@@ -211,7 +212,7 @@ test_expect_success \
 	git reset --hard HEAD~2 &&
 	check_changes ddaefe00f1da16864591c61fdc7adb5d7cd6b74e &&
 	test "$(git rev-parse ORIG_HEAD)" = \
-			3d3b7be011a58ca0c179ae45d94e6c83c0b0cd0d
+			$head4
 '
 
 >.diff_expect
@@ -326,10 +327,11 @@ test_expect_success '--hard reset to HEAD should clear a failed merge' '
 	git checkout branch2 &&
 	echo "3rd line in branch2" >>secondfile &&
 	git commit -a -m "change in branch2" &&
+	head3=$(git rev-parse --verify HEAD) &&
 
 	test_must_fail git pull . branch1 &&
 	git reset --hard &&
-	check_changes 77abb337073fb4369a7ad69ff6f5ec0e4d6b54bb
+	check_changes $head3
 '
 
 >.diff_expect
Signature · 1 line
1.8.3.1.15.g5c23c1e
#37 lore raw

PATCH v5 3/5 t4205 (log-pretty-formats): don't hardcode SHA-1 in expected outputs

In reply to Alexey Shumkin

The expected SHA-1 digests are always available in variables. Use them instead of hardcoding.

---
 t/t4205-log-pretty-formats.sh | 48 +++++++++++++++++++++++--------------------
 1 file changed, 26 insertions(+), 22 deletions(-)
t/t4205-log-pretty-formats.sh +26 -22
index 26fbfde..6d8d457 100755
@@ -101,7 +101,11 @@ test_expect_failure 'NUL termination with --stat' '
 
 test_expect_success 'setup more commits' '
 	test_commit "message one" one one message-one &&
-	test_commit "message two" two two message-two
+	test_commit "message two" two two message-two &&
+	head1=$(git rev-list --max-count=1 --abbrev-commit HEAD~0) &&
+	head2=$(git rev-list --max-count=1 --abbrev-commit HEAD~1) &&
+	head3=$(git rev-list --max-count=1 --abbrev-commit HEAD~2) &&
+	head4=$(git rev-list --max-count=1 --abbrev-commit HEAD~3)
 '
 
 test_expect_success 'left alignment formatting' '
@@ -117,18 +121,18 @@ EOF
 	test_cmp expected actual
 '
 
-test_expect_success 'left alignment formatting at the nth column' '
-	git log --pretty="format:%h %<|(40)%s" >actual &&
+test_expect_success 'left alignment formatting at the nth column' "
+	git log --pretty='format:%h %<|(40)%s' >actual &&
 	# complete the incomplete line at the end
 	echo >>actual &&
 	qz_to_tab_space <<\EOF >expected &&
-fa33ab1 message two                    Z
-7cd6c63 message one                    Z
-1711bf9 add bar                        Z
-af20c06 initial                        Z
+$head1 message two                    Z
+$head2 message one                    Z
+$head3 add bar                        Z
+$head4 initial                        Z
 EOF
 	test_cmp expected actual
-'
+"
 
 test_expect_success 'left alignment formatting with no padding' '
 	git log --pretty="format:%<(1)%s" >actual &&
@@ -195,18 +199,18 @@ EOF
 	test_cmp expected actual
 '
 
-test_expect_success 'right alignment formatting at the nth column' '
-	git log --pretty="format:%h %>|(40)%s" >actual &&
+test_expect_success 'right alignment formatting at the nth column' "
+	git log --pretty='format:%h %>|(40)%s' >actual &&
 	# complete the incomplete line at the end
 	echo >>actual &&
 	qz_to_tab_space <<\EOF >expected &&
-fa33ab1                      message two
-7cd6c63                      message one
-1711bf9                          add bar
-af20c06                          initial
+$head1                      message two
+$head2                      message one
+$head3                          add bar
+$head4                          initial
 EOF
 	test_cmp expected actual
-'
+"
 
 test_expect_success 'right alignment formatting with no padding' '
 	git log --pretty="format:%>(1)%s" >actual &&
@@ -234,18 +238,18 @@ EOF
 	test_cmp expected actual
 '
 
-test_expect_success 'center alignment formatting at the nth column' '
-	git log --pretty="format:%h %><|(40)%s" >actual &&
+test_expect_success 'center alignment formatting at the nth column' "
+	git log --pretty='format:%h %><|(40)%s' >actual &&
 	# complete the incomplete line at the end
 	echo >>actual &&
 	qz_to_tab_space <<\EOF >expected &&
-fa33ab1           message two          Z
-7cd6c63           message one          Z
-1711bf9             add bar            Z
-af20c06             initial            Z
+$head1           message two          Z
+$head2           message one          Z
+$head3             add bar            Z
+$head4             initial            Z
 EOF
 	test_cmp expected actual
-'
+"
 
 test_expect_success 'center alignment formatting with no padding' '
 	git log --pretty="format:%><(1)%s" >actual &&
Signature · 1 line
1.8.3.1.15.g5c23c1e
#38 lore raw

Re: [PATCH v5 3/5] t4205 (log-pretty-formats): don't hardcode SHA-1 in expected outputs

Quoted 13 lines · Alexey Shumkin

The expected SHA-1 digests are always available in variables. Use them instead of hardcoding.

---
 t/t4205-log-pretty-formats.sh | 48 +++++++++++++++++++++++--------------------
 1 file changed, 26 insertions(+), 22 deletions(-)
t/t4205-log-pretty-formats.sh +0 -0
index 26fbfde..6d8d457 100755

t/t4205-log-pretty-formats.sh test_expect_failure 'NUL termination with --stat' ' · line 108

Quoted 9 lines
t/t4205-log-pretty-formats.sh +5 -1
@@ -101,7 +101,11 @@ test_expect_failure 'NUL termination with --stat' '
 
 test_expect_success 'setup more commits' '
 	test_commit "message one" one one message-one &&
-	test_commit "message two" two two message-two
+	test_commit "message two" two two message-two &&
+	head1=$(git rev-list --max-count=1 --abbrev-commit HEAD~0) &&
+	head2=$(git rev-list --max-count=1 --abbrev-commit HEAD~1) &&
+	head3=$(git rev-list --max-count=1 --abbrev-commit HEAD~2) &&
+	head4=$(git rev-list --max-count=1 --abbrev-commit HEAD~3)

Hmmph. Why not rev-parse --short like in your 1/5?

#39 lore raw

PATCH v5 4/5 pretty: Add failing tests: user format ignores i18n.logOutputEncoding setting

In reply to Alexey Shumkin

The following two commands are expected to give the same output to a terminal:

	$ git log --oneline --no-color
	$ git log --pretty=format:'%h %s'

However, the former pays attention to i18n.logOutputEncoding configuration, while the latter does not when it format "%s". Log messages written in an encoding i18n.commitEncoding which differs from terminal encoding are shown corrupted with the latter even when i18n.logOutputEncoding and terminal encoding are the same.

The same corruption is true for

	$ git diff --submodule=log
and
	$ git rev-list --pretty=format:%s HEAD
and
	$ git reset --hard
---
 t/t4041-diff-submodule-option.sh |  35 +++++----
 t/t4205-log-pretty-formats.sh    | 149 ++++++++++++++++++++++++---------------
 t/t6006-rev-list-format.sh       |  85 +++++++++++++++-------
 t/t7102-reset.sh                 |  29 +++++++-
 4 files changed, 200 insertions(+), 98 deletions(-)
t/t4041-diff-submodule-option.sh +20 -15
index 32d4a60..22bf4df 100755
@@ -1,6 +1,7 @@
 #!/bin/sh
 #
 # Copyright (c) 2009 Jens Lehmann, based on t7401 by Ping Yin
+# Copyright (c) 2011 Alexey Shumkin (+ non-UTF-8 commit encoding tests)
 #
 
 test_description='Support for verbose submodule differences in git diff
@@ -10,6 +11,9 @@ This test tries to verify the sanity of the --submodule option of git diff.
 
 . ./test-lib.sh
 
+# String "added" in Russian, encoded in UTF-8, used in
+# sample commit log messages in add_file() function below.
+added=$(printf "\320\264\320\276\320\261\320\260\320\262\320\273\320\265\320\275")
 add_file () {
 	(
 		cd "$1" &&
@@ -19,7 +23,8 @@ add_file () {
 			echo "$name" >"$name" &&
 			git add "$name" &&
 			test_tick &&
-			git commit -m "Add $name" || exit
+			msg_added_iso88595=$(echo "Add $name ($added $name)" | iconv -f utf-8 -t iso88595) &&
+			git -c 'i18n.commitEncoding=iso88595' commit -m "$msg_added_iso88595"
 		done >/dev/null &&
 		git rev-parse --short --verify HEAD
 	)
@@ -89,29 +94,29 @@ test_expect_success 'diff.submodule does not affect plumbing' '
 commit_file sm1 &&
 head2=$(add_file sm1 foo3)
 
-test_expect_success 'modified submodule(forward)' '
+test_expect_failure 'modified submodule(forward)' '
 	git diff-index -p --submodule=log HEAD >actual &&
 	cat >expected <<-EOF &&
 	Submodule sm1 $head1..$head2:
-	  > Add foo3
+	  > Add foo3 ($added foo3)
 	EOF
 	test_cmp expected actual
 '
 
-test_expect_success 'modified submodule(forward)' '
+test_expect_failure 'modified submodule(forward)' '
 	git diff --submodule=log >actual &&
 	cat >expected <<-EOF &&
 	Submodule sm1 $head1..$head2:
-	  > Add foo3
+	  > Add foo3 ($added foo3)
 	EOF
 	test_cmp expected actual
 '
 
-test_expect_success 'modified submodule(forward) --submodule' '
+test_expect_failure 'modified submodule(forward) --submodule' '
 	git diff --submodule >actual &&
 	cat >expected <<-EOF &&
 	Submodule sm1 $head1..$head2:
-	  > Add foo3
+	  > Add foo3 ($added foo3)
 	EOF
 	test_cmp expected actual
 '
@@ -138,25 +143,25 @@ head3=$(
 	git rev-parse --short --verify HEAD
 )
 
-test_expect_success 'modified submodule(backward)' '
+test_expect_failure 'modified submodule(backward)' '
 	git diff-index -p --submodule=log HEAD >actual &&
 	cat >expected <<-EOF &&
 	Submodule sm1 $head2..$head3 (rewind):
-	  < Add foo3
-	  < Add foo2
+	  < Add foo3 ($added foo3)
+	  < Add foo2 ($added foo2)
 	EOF
 	test_cmp expected actual
 '
 
 head4=$(add_file sm1 foo4 foo5)
-test_expect_success 'modified submodule(backward and forward)' '
+test_expect_failure 'modified submodule(backward and forward)' '
 	git diff-index -p --submodule=log HEAD >actual &&
 	cat >expected <<-EOF &&
 	Submodule sm1 $head2...$head4:
-	  > Add foo5
-	  > Add foo4
-	  < Add foo3
-	  < Add foo2
+	  > Add foo5 ($added foo5)
+	  > Add foo4 ($added foo4)
+	  < Add foo3 ($added foo3)
+	  < Add foo2 ($added foo2)
 	EOF
 	test_cmp expected actual
 '
t/t4205-log-pretty-formats.sh +93 -56

319 lines not on this page · raw message

t/t6006-rev-list-format.sh +60 -25

176 lines not on this page · raw message

t/t7102-reset.sh +27 -2
index 05dfb27..48534f1 100755
@@ -9,6 +9,17 @@ Documented tests for git reset'
 
 . ./test-lib.sh
 
+commit_msg() {
+	# String "2nd file modified" in Russian, encoded in UTF-8,
+	# used as a commit log message below.
+	msg=$(printf "modify 2nd file (\320\270\320\267\320\274\320\265\320\275\321\221\320\275 \321\204\320\260\320\271\320\273)")
+	if test -n "$1"
+	then
+		msg=$(echo $msg | iconv -f utf-8 -t $1)
+	fi
+	echo $msg
+}
+
 test_expect_success 'creating initial files and commits' '
 	test_tick &&
 	echo "1st file" >first &&
@@ -28,7 +39,7 @@ test_expect_success 'creating initial files and commits' '
 
 	echo "1st line 2nd file" >secondfile &&
 	echo "2nd line 2nd file" >>secondfile &&
-	git commit -a -m "modify 2nd file" &&
+	git -c "i18n.commitEncoding=iso88595" commit -a -m "$(commit_msg iso88595)" &&
 	head5=$(git rev-parse --verify HEAD)
 '
 # git log --pretty=oneline # to see those SHA1 involved
@@ -44,6 +55,20 @@ check_changes () {
 	done | test_cmp .cat_expect -
 }
 
+test_expect_failure 'reset --hard message' '
+	hex=$(git log -1 --format="%h") &&
+	git reset --hard > .actual &&
+	echo HEAD is now at $hex $(commit_msg) > .expected &&
+	test_cmp .expected .actual
+'
+
+test_expect_success 'reset --hard message (iso88595 logoutencoding)' '
+	hex=$(git log -1 --format="%h") &&
+	git -c "i18n.logOutputEncoding=iso88595" reset --hard > .actual &&
+	echo HEAD is now at $hex $(commit_msg iso88595) > .expected &&
+	test_cmp .expected .actual
+'
+
 >.diff_expect
 >.cached_expect
 cat >.cat_expect <<EOF
@@ -304,7 +329,7 @@ test_expect_success 'redoing the last two commits should succeed' '
 
 	echo "1st line 2nd file" >secondfile &&
 	echo "2nd line 2nd file" >>secondfile &&
-	git commit -a -m "modify 2nd file" &&
+	git -c "i18n.commitEncoding=iso88595" commit -a -m "$(commit_msg iso88595)" &&
 	check_changes $head5
 '
 
Signature · 1 line
1.8.3.1.15.g5c23c1e
#40 lore raw

Re: [PATCH v5 4/5] pretty: Add failing tests: user format ignores i18n.logOutputEncoding setting

t/t4041-diff-submodule-option.sh add_file () { · line 27

Quoted 7 lines · Alexey Shumkin
t/t4041-diff-submodule-option.sh +2 -1
@@ -19,7 +23,8 @@ add_file () {
 			echo "$name" >"$name" &&
 			git add "$name" &&
 			test_tick &&
-			git commit -m "Add $name" || exit
+			msg_added_iso88595=$(echo "Add $name ($added $name)" | iconv -f utf-8 -t iso88595) &&
+			git -c 'i18n.commitEncoding=iso88595' commit -m "$msg_added_iso88595"

Hmph. Do we know 8859-5 is available or do these need to be protected with prereq?

Can these tests be done with 8859-1 i.e. something we already depend on, by changing that $added message to latin-1, or is there something very Russian specific breakage we want to test here?

If the former, please redo this entire patch (not just t4041) with 8859-1.

If there is some Russian specific breakage you cannot demonstrate with 8859-1, then please explain it in the log message.

t/t6006-rev-list-format.sh line 42

Quoted 9 lines
t/t6006-rev-list-format.sh +2 -1
index d32e65e..36e4cc0 100755
...
-# usage: test_format name format_string <expected_output
+# usage: test_format [failure] name format_string <expected_output
 test_format () {
+	local must_fail=0

This breaks tests for non-bash users. "local" is not even in POSIX.

#41 lore raw

PATCH v5 5/5 pretty: user format ignores i18n.logOutputEncoding setting

In reply to Alexey Shumkin

The following two commands are expected to give the same output to a terminal:

	$ git log --oneline --no-color
	$ git log --pretty=format:'%h %s'

However, the former pays attention to i18n.logOutputEncoding configuration, while the latter does not when it format "%s". Log messages written in an encoding i18n.commitEncoding which differs from terminal encoding are shown corrupted with the latter even when i18n.logOutputEncoding and terminal encoding are the same.

The same corruption is true for

	$ git diff --submodule=log
and
	$ git rev-list --pretty=format:%s HEAD
and
	$ git reset --hard
---
 builtin/reset.c                  |  8 ++++++--
 builtin/rev-list.c               |  1 +
 builtin/shortlog.c               |  1 +
 log-tree.c                       |  1 +
 submodule.c                      |  3 +++
 t/t4041-diff-submodule-option.sh | 10 +++++-----
 t/t4205-log-pretty-formats.sh    | 34 +++++++++++++++++-----------------
 t/t6006-rev-list-format.sh       |  8 ++++----
 t/t7102-reset.sh                 |  2 +-
 9 files changed, 39 insertions(+), 29 deletions(-)
builtin/reset.c +6 -2
index 6032131..b23ed63 100644
@@ -92,11 +92,15 @@ static int reset_index(const unsigned char *sha1, int reset_type, int quiet)
 
 static void print_new_head_line(struct commit *commit)
 {
-	const char *hex, *body;
+	const char *hex, *body, *encoding;
 
 	hex = find_unique_abbrev(commit->object.sha1, DEFAULT_ABBREV);
 	printf(_("HEAD is now at %s"), hex);
-	body = strstr(commit->buffer, "\n\n");
+	encoding = get_log_output_encoding();
+	body = logmsg_reencode(commit, NULL, encoding);
+	if (!body)
+		body = commit->buffer;
+	body = strstr(body, "\n\n");
 	if (body) {
 		const char *eol;
 		size_t len;
builtin/rev-list.c +1 -0
index 67701be..a5ec30d 100644
@@ -111,6 +111,7 @@ static void show_commit(struct commit *commit, void *data)
 		ctx.date_mode = revs->date_mode;
 		ctx.date_mode_explicit = revs->date_mode_explicit;
 		ctx.fmt = revs->commit_format;
+		ctx.output_encoding = get_log_output_encoding();
 		pretty_print_commit(&ctx, commit, &buf);
 		if (revs->graph) {
 			if (buf.len) {
builtin/shortlog.c +1 -0
index 1fd6f8a..1434f8f 100644
@@ -137,6 +137,7 @@ void shortlog_add_commit(struct shortlog *log, struct commit *commit)
 		ctx.subject = "";
 		ctx.after_subject = "";
 		ctx.date_mode = DATE_NORMAL;
+		ctx.output_encoding = get_log_output_encoding();
 		pretty_print_commit(&ctx, commit, &ufbuf);
 		buffer = ufbuf.buf;
 	} else if (*buffer) {
log-tree.c +1 -0
index 1946e9c..5277d3e 100644
@@ -616,6 +616,7 @@ void show_log(struct rev_info *opt)
 	ctx.fmt = opt->commit_format;
 	ctx.mailmap = opt->mailmap;
 	ctx.color = opt->diffopt.use_color;
+	ctx.output_encoding = get_log_output_encoding();
 	pretty_print_commit(&ctx, commit, &msgbuf);
 
 	if (opt->add_signoff)
submodule.c +3 -0
index 1821a5b..baa8669 100644
@@ -222,10 +222,13 @@ static void print_submodule_summary(struct rev_info *rev, FILE *f,
 	static const char format[] = "  %m %s";
 	struct strbuf sb = STRBUF_INIT;
 	struct commit *commit;
+	const char *log_output_encoding;
 
+	log_output_encoding = get_log_output_encoding();
 	while ((commit = get_revision(rev))) {
 		struct pretty_print_context ctx = {0};
 		ctx.date_mode = rev->date_mode;
+		ctx.output_encoding = log_output_encoding;
 		strbuf_setlen(&sb, 0);
 		strbuf_addstr(&sb, line_prefix);
 		if (commit->object.flags & SYMMETRIC_LEFT) {
t/t4041-diff-submodule-option.sh +5 -5
index 22bf4df..ce192b0 100755
@@ -94,7 +94,7 @@ test_expect_success 'diff.submodule does not affect plumbing' '
 commit_file sm1 &&
 head2=$(add_file sm1 foo3)
 
-test_expect_failure 'modified submodule(forward)' '
+test_expect_success 'modified submodule(forward)' '
 	git diff-index -p --submodule=log HEAD >actual &&
 	cat >expected <<-EOF &&
 	Submodule sm1 $head1..$head2:
@@ -103,7 +103,7 @@ test_expect_failure 'modified submodule(forward)' '
 	test_cmp expected actual
 '
 
-test_expect_failure 'modified submodule(forward)' '
+test_expect_success 'modified submodule(forward)' '
 	git diff --submodule=log >actual &&
 	cat >expected <<-EOF &&
 	Submodule sm1 $head1..$head2:
@@ -112,7 +112,7 @@ test_expect_failure 'modified submodule(forward)' '
 	test_cmp expected actual
 '
 
-test_expect_failure 'modified submodule(forward) --submodule' '
+test_expect_success 'modified submodule(forward) --submodule' '
 	git diff --submodule >actual &&
 	cat >expected <<-EOF &&
 	Submodule sm1 $head1..$head2:
@@ -143,7 +143,7 @@ head3=$(
 	git rev-parse --short --verify HEAD
 )
 
-test_expect_failure 'modified submodule(backward)' '
+test_expect_success 'modified submodule(backward)' '
 	git diff-index -p --submodule=log HEAD >actual &&
 	cat >expected <<-EOF &&
 	Submodule sm1 $head2..$head3 (rewind):
@@ -154,7 +154,7 @@ test_expect_failure 'modified submodule(backward)' '
 '
 
 head4=$(add_file sm1 foo4 foo5)
-test_expect_failure 'modified submodule(backward and forward)' '
+test_expect_success 'modified submodule(backward and forward)' '
 	git diff-index -p --submodule=log HEAD >actual &&
 	cat >expected <<-EOF &&
 	Submodule sm1 $head2...$head4:
t/t4205-log-pretty-formats.sh +17 -17
index 6a56019..1739a86 100755
@@ -69,7 +69,7 @@ test_expect_success 'alias user-defined tformat with %s (iso88595 encoding)' '
 	test_cmp expected-s actual-s
 '
 
-test_expect_failure 'alias user-defined tformat with %s (utf-8 encoding)' '
+test_expect_success 'alias user-defined tformat with %s (utf-8 encoding)' '
 	git log --oneline >expected-s &&
 	git log --pretty="tformat:%h %s" >actual-s &&
 	test_cmp expected-s actual-s
@@ -108,19 +108,19 @@ test_expect_success 'alias loop' '
 	test_must_fail git log --pretty=test-foo
 '
 
-test_expect_failure 'NUL separation' '
+test_expect_success 'NUL separation' '
 	printf "add bar\0$(commit_msg)" >expected &&
 	git log -z --pretty="format:%s" >actual &&
 	test_cmp expected actual
 '
 
-test_expect_failure 'NUL termination' '
+test_expect_success 'NUL termination' '
 	printf "add bar\0$(commit_msg)\0" >expected &&
 	git log -z --pretty="tformat:%s" >actual &&
 	test_cmp expected actual
 '
 
-test_expect_failure 'NUL separation with --stat' '
+test_expect_success 'NUL separation with --stat' '
 	stat0_part=$(git diff --stat HEAD^ HEAD) &&
 	stat1_part=$(git diff-tree --no-commit-id --stat --root HEAD^) &&
 	printf "add bar\n$stat0_part\n\0$(commit_msg)\n$stat1_part\n" >expected &&
@@ -145,7 +145,7 @@ test_expect_success 'setup more commits' '
 	head4=$(git rev-list --max-count=1 --abbrev-commit HEAD~3)
 '
 
-test_expect_failure 'left alignment formatting' "
+test_expect_success 'left alignment formatting' "
 	git log --pretty='format:%<(40)%s' >actual &&
 	# complete the incomplete line at the end
 	echo >>actual &&
@@ -158,7 +158,7 @@ EOF
 	test_cmp expected actual
 "
 
-test_expect_failure 'left alignment formatting at the nth column' "
+test_expect_success 'left alignment formatting at the nth column' "
 	git log --pretty='format:%h %<|(40)%s' >actual &&
 	# complete the incomplete line at the end
 	echo >>actual &&
@@ -171,7 +171,7 @@ EOF
 	test_cmp expected actual
 "
 
-test_expect_failure 'left alignment formatting with no padding' "
+test_expect_success 'left alignment formatting with no padding' "
 	git log --pretty='format:%<(1)%s' >actual &&
 	# complete the incomplete line at the end
 	echo >>actual &&
@@ -184,7 +184,7 @@ EOF
 	test_cmp expected actual
 "
 
-test_expect_failure 'left alignment formatting with trunc' "
+test_expect_success 'left alignment formatting with trunc' "
 	git log --pretty='format:%<(10,trunc)%s' >actual &&
 	# complete the incomplete line at the end
 	echo >>actual &&
@@ -197,7 +197,7 @@ EOF
 	test_cmp expected actual
 "
 
-test_expect_failure 'left alignment formatting with ltrunc' "
+test_expect_success 'left alignment formatting with ltrunc' "
 	git log --pretty='format:%<(10,ltrunc)%s' >actual &&
 	# complete the incomplete line at the end
 	echo >>actual &&
@@ -210,7 +210,7 @@ EOF
 	test_cmp expected actual
 "
 
-test_expect_failure 'left alignment formatting with mtrunc' "
+test_expect_success 'left alignment formatting with mtrunc' "
 	git log --pretty='format:%<(10,mtrunc)%s' >actual &&
 	# complete the incomplete line at the end
 	echo >>actual &&
@@ -223,7 +223,7 @@ EOF
 	test_cmp expected actual
 "
 
-test_expect_failure 'right alignment formatting' "
+test_expect_success 'right alignment formatting' "
 	git log --pretty='format:%>(40)%s' >actual &&
 	# complete the incomplete line at the end
 	echo >>actual &&
@@ -236,7 +236,7 @@ EOF
 	test_cmp expected actual
 "
 
-test_expect_failure 'right alignment formatting at the nth column' "
+test_expect_success 'right alignment formatting at the nth column' "
 	git log --pretty='format:%h %>|(40)%s' >actual &&
 	# complete the incomplete line at the end
 	echo >>actual &&
@@ -249,7 +249,7 @@ EOF
 	test_cmp expected actual
 "
 
-test_expect_failure 'right alignment formatting with no padding' "
+test_expect_success 'right alignment formatting with no padding' "
 	git log --pretty='format:%>(1)%s' >actual &&
 	# complete the incomplete line at the end
 	echo >>actual &&
@@ -262,7 +262,7 @@ EOF
 	test_cmp expected actual
 "
 
-test_expect_failure 'center alignment formatting' "
+test_expect_success 'center alignment formatting' "
 	git log --pretty='format:%><(40)%s' >actual &&
 	# complete the incomplete line at the end
 	echo >>actual &&
@@ -275,7 +275,7 @@ EOF
 	test_cmp expected actual
 "
 
-test_expect_failure 'center alignment formatting at the nth column' "
+test_expect_success 'center alignment formatting at the nth column' "
 	git log --pretty='format:%h %><|(40)%s' >actual &&
 	# complete the incomplete line at the end
 	echo >>actual &&
@@ -288,7 +288,7 @@ EOF
 	test_cmp expected actual
 "
 
-test_expect_failure 'center alignment formatting with no padding' "
+test_expect_success 'center alignment formatting with no padding' "
 	git log --pretty='format:%><(1)%s' >actual &&
 	# complete the incomplete line at the end
 	echo >>actual &&
@@ -301,7 +301,7 @@ EOF
 	test_cmp expected actual
 "
 
-test_expect_failure 'left/right alignment formatting with stealing' "
+test_expect_success 'left/right alignment formatting with stealing' "
 	git commit --amend -m short --author 'long long long <[email protected]>' &&
 	git log --pretty='format:%<(10,trunc)%s%>>(10,ltrunc)% an' >actual &&
 	# complete the incomplete line at the end
t/t6006-rev-list-format.sh +4 -4
index 36e4cc0..055655c 100755
@@ -143,7 +143,7 @@ commit $head1
 iso88595
 EOF
 
-test_format failure subject %s <<EOF
+test_format subject %s <<EOF
 commit $head2
 $changed
 commit $head1
@@ -155,7 +155,7 @@ commit $head2
 commit $head1
 EOF
 
-test_format failure raw-body %B <<EOF
+test_format raw-body %B <<EOF
 commit $head2
 $changed
 
@@ -249,7 +249,7 @@ commit $head1
 iso88595
 EOF
 
-test_format failure complex-subject %s <<EOF
+test_format complex-subject %s <<EOF
 commit $head3
 Test printing of complex bodies
 commit $head2
@@ -258,7 +258,7 @@ commit $head1
 $added
 EOF
 
-test_format failure complex-body %b <<EOF
+test_format complex-body %b <<EOF
 commit $head3
 This commit message is much longer than the others,
 and it will be encoded in iso8859-1. We should therefore
t/t7102-reset.sh +1 -1
index 48534f1..5a7b383 100755
@@ -55,7 +55,7 @@ check_changes () {
 	done | test_cmp .cat_expect -
 }
 
-test_expect_failure 'reset --hard message' '
+test_expect_success 'reset --hard message' '
 	hex=$(git log -1 --format="%h") &&
 	git reset --hard > .actual &&
 	echo HEAD is now at $hex $(commit_msg) > .expected &&
Signature · 1 line
1.8.3.1.15.g5c23c1e
#42 lore raw

Re: [PATCH v5 5/5] pretty: user format ignores i18n.logOutputEncoding setting

Alexey Shumkin <[email protected]> writes:

Subject: Re: [PATCH v5 5/5] pretty: user format ignores i18n.logOutputEncoding setting

That is a statement of fact, and does not tell much to the reader.

I think you are saying that in the current implementation, logoutputencoding is not honored in user format, that it is a bug that needs to be fixed (as opposed to "that is by design, the scripts that read from --format='' is responsible for doing the conversion"), and that this patch fixes it.

So

pretty: --format output should honor logOutputEncoding

or something? At least it says what is the _desired_ outcome with "should", hints that the status-quo is different from that desired outcome and implies that this is a patch to fix it.

The "Subject" line is very important as that is the only thing we see in many summarizing output format, e.g. shortlog, cover letter and merge message.

Quoted 41 lines

The following two commands are expected to give the same output to a terminal:

	$ git log --oneline --no-color
	$ git log --pretty=format:'%h %s'

However, the former pays attention to i18n.logOutputEncoding configuration, while the latter does not when it format "%s". Log messages written in an encoding i18n.commitEncoding which differs from terminal encoding are shown corrupted with the latter even when i18n.logOutputEncoding and terminal encoding are the same.

The same corruption is true for

	$ git diff --submodule=log
and
	$ git rev-list --pretty=format:%s HEAD
and
	$ git reset --hard
---
 builtin/reset.c                  |  8 ++++++--
 builtin/rev-list.c               |  1 +
 builtin/shortlog.c               |  1 +
 log-tree.c                       |  1 +
 submodule.c                      |  3 +++
 t/t4041-diff-submodule-option.sh | 10 +++++-----
 t/t4205-log-pretty-formats.sh    | 34 +++++++++++++++++-----------------
 t/t6006-rev-list-format.sh       |  8 ++++----
 t/t7102-reset.sh                 |  2 +-
 9 files changed, 39 insertions(+), 29 deletions(-)
builtin/reset.c +1 -1
index 6032131..b23ed63 100644
@@ -92,11 +92,15 @@ static int reset_index(const unsigned char *sha1, int reset_type, int quiet)
 
 static void print_new_head_line(struct commit *commit)
 {
-	const char *hex, *body;
+	const char *hex, *body, *encoding;

builtin/reset.c static int reset_index(const unsigned char *sha1, int reset_type, int quiet) · line 104

Quoted 10 lines
builtin/reset.c +4 -1
 
 	hex = find_unique_abbrev(commit->object.sha1, DEFAULT_ABBREV);
 	printf(_("HEAD is now at %s"), hex);
-	body = strstr(commit->buffer, "\n\n");
+	encoding = get_log_output_encoding();
+	body = logmsg_reencode(commit, NULL, encoding);
 
 
+	if (!body)
+		body = commit->buffer;

Does this happen? I thought body, without an error, can be the same as commit->buffer.

builtin/reset.c

Quoted 4 lines
builtin/reset.c +1 -0
+	body = strstr(body, "\n\n");
 	if (body) {
builtin/reset.c +0 -0
 		const char *eol;
 		size_t len;

Do we have a leak here? body may point at a new piece of memory logmsg_reencode() have allocated to hold the UTF-8 version of your 8859-5 message in commit->buffer.

It would be more like this, no?

builtin/reset.c +5 -2
index 6032131..8d22ffe 100644
@@ -92,11 +92,13 @@ static int reset_index(const unsigned char *sha1, int reset_type, int quiet)
 
 static void print_new_head_line(struct commit *commit)
 {
-	const char *hex, *body;
+	const char *hex, *body, *msg, *encoding; 
 
 	hex = find_unique_abbrev(commit->object.sha1, DEFAULT_ABBREV);
 	printf(_("HEAD is now at %s"), hex);
-	body = strstr(commit->buffer, "\n\n");
+
+	msg = logmsg_reencode(commit, NULL, get_log_output_encoding());
+	body = strstr(msg, "\n\n");
 	if (body) {
 		const char *eol;
 		size_t len;
@@ -107,6 +109,7 @@ static void print_new_head_line(struct commit *commit)
 	}
 	else
 		printf("\n");
+	logmsg_free(msg, commit);
 }
 
 static void update_index_from_diff(struct diff_queue_struct *q,
#43 lore raw

Re: [PATCH v5 0/5] Reroll patches against v1.8.3.1

In reply to Alexey Shumkin
Quoted 7 lines · Alexey Shumkin

Alexey Shumkin (5):
t6006 (rev-list-format): don't hardcode SHA-1 in expected outputs t7102 (reset): don't hardcode SHA-1 in expected outputs t4205 (log-pretty-formats): don't hardcode SHA-1 in expected outputs
pretty: Add failing tests: user format ignores i18n.logOutputEncoding
setting
pretty: user format ignores i18n.logOutputEncoding setting

Next time, please jog readers' memory better by giving a bit more descriptive cover letter. "Reroll" is known by "v5" alrady, and "against v1.8.3.1" certainly helps, but what this series is about is unclear, especially because the end-game patch "user format ignores" is rather badly stated. It is unclear if it is a good thing that user format ignores it and the patch makes sure that is the case, if we currently ignore it in user format and the patch fixes it by making user format pay attention to it, etc.

Thanks.

Quoted 10 lines
 builtin/reset.c                  |   8 +-
 builtin/rev-list.c               |   1 +
 builtin/shortlog.c               |   1 +
 log-tree.c                       |   1 +
 submodule.c                      |   3 +
 t/t4041-diff-submodule-option.sh |  25 +++--
 t/t4205-log-pretty-formats.sh    | 179 ++++++++++++++++++++-------------
 t/t6006-rev-list-format.sh       | 209 ++++++++++++++++++++++++---------------
 t/t7102-reset.sh                 |  37 ++++++-
 9 files changed, 299 insertions(+), 165 deletions(-)
#44 lore raw

v6 cover Reroll patches against v1.8.3.1

In reply to Alexey Shumkin

It's all started here [http://thread.gmane.org/gmane.comp.version-control.git/177634]
and recently continued later [http://thread.gmane.org/gmane.comp.version-control.git/214419]

v6 of this patch series includes Junio's suggestions against v5:

1. [PATCH v6 1/5] t6006 (rev-list-format): don't hardcode SHA-1 in expected outputs using modern 'git rev-parse HEAD:' git syntax to get commit tree ID
2. [PATCH v6 2/5] t7102 (reset): don't hardcode SHA-1 in expected outputs untouched
3. [PATCH v6 3/5] t4205 (log-pretty-formats): don't hardcode SHA-1 in expected outputs

	using 'rev-parse --short' instead of 'git rev-list --max-count=1 --abbrev-commit'

4. [PATCH v6 4/5] pretty: Add failing tests: --format output should honor logOutputEncoding iso8859-5 encoding reverted back to cp1251 encoding (as it was in v4 series) reworded log message
5. [PATCH v6 5/5] pretty: --format output should honor logOutputEncoding reworded log message

Alexey Shumkin (5):
t6006 (rev-list-format): don't hardcode SHA-1 in expected outputs t7102 (reset): don't hardcode SHA-1 in expected outputs t4205 (log-pretty-formats): don't hardcode SHA-1 in expected outputs
pretty: Add failing tests: --format output should honor
logOutputEncoding
pretty: --format output should honor logOutputEncoding

 builtin/reset.c                  |   6 +-
 builtin/rev-list.c               |   1 +
 builtin/shortlog.c               |   1 +
 log-tree.c                       |   1 +
 submodule.c                      |   1 +
 t/t4041-diff-submodule-option.sh |  25 +++--
 t/t4205-log-pretty-formats.sh    | 179 ++++++++++++++++++++-------------
 t/t6006-rev-list-format.sh       | 207 ++++++++++++++++++++++++---------------
 t/t7102-reset.sh                 |  37 ++++++-
 9 files changed, 293 insertions(+), 165 deletions(-)
Signature · 1 line
1.8.3.1.15.g5c23c1e
#45 lore raw

PATCH v6 1/5 t6006 (rev-list-format): don't hardcode SHA-1 in expected outputs

The expected SHA-1 digests are always available in variables. Use them instead of hardcoding.

---
 t/t6006-rev-list-format.sh | 140 +++++++++++++++++++++++++--------------------
 1 file changed, 77 insertions(+), 63 deletions(-)
t/t6006-rev-list-format.sh +77 -63
index 0393c9f..cc1008d 100755
@@ -7,8 +7,19 @@ test_description='git rev-list --pretty=format test'
 
 test_tick
 test_expect_success 'setup' '
-touch foo && git add foo && git commit -m "added foo" &&
-  echo changed >foo && git commit -a -m "changed foo"
+	: >foo &&
+	git add foo &&
+	git commit -m "added foo" &&
+	head1=$(git rev-parse --verify HEAD) &&
+	head1_short=$(git rev-parse --verify --short $head1) &&
+	tree1=$(git rev-parse --verify HEAD:) &&
+	tree1_short=$(git rev-parse --verify --short $tree1) &&
+	echo changed >foo &&
+	git commit -a -m "changed foo" &&
+	head2=$(git rev-parse --verify HEAD) &&
+	head2_short=$(git rev-parse --verify --short $head2) &&
+	tree2=$(git rev-parse --verify HEAD:) &&
+	tree2_short=$(git rev-parse --verify --short $tree2)
 '
 
 # usage: test_format name format_string <expected_output
@@ -32,49 +43,49 @@ has_no_color () {
 	test_cmp expect "$1"
 }
 
-test_format percent %%h <<'EOF'
-commit 131a310eb913d107dd3c09a65d1651175898735d
+test_format percent %%h <<EOF
+commit $head2
 %h
-commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
+commit $head1
 %h
 EOF
 
-test_format hash %H%n%h <<'EOF'
-commit 131a310eb913d107dd3c09a65d1651175898735d
-131a310eb913d107dd3c09a65d1651175898735d
-131a310
-commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
-86c75cfd708a0e5868dc876ed5b8bb66c80b4873
-86c75cf
+test_format hash %H%n%h <<EOF
+commit $head2
+$head2
+$head2_short
+commit $head1
+$head1
+$head1_short
 EOF
 
-test_format tree %T%n%t <<'EOF'
-commit 131a310eb913d107dd3c09a65d1651175898735d
-fe722612f26da5064c32ca3843aa154bdb0b08a0
-fe72261
-commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
-4d5fcadc293a348e88f777dc0920f11e7d71441c
-4d5fcad
+test_format tree %T%n%t <<EOF
+commit $head2
+$tree2
+$tree2_short
+commit $head1
+$tree1
+$tree1_short
 EOF
 
-test_format parents %P%n%p <<'EOF'
-commit 131a310eb913d107dd3c09a65d1651175898735d
-86c75cfd708a0e5868dc876ed5b8bb66c80b4873
-86c75cf
-commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
+test_format parents %P%n%p <<EOF
+commit $head2
+$head1
+$head1_short
+commit $head1
 
 
 EOF
 
 # we don't test relative here
-test_format author %an%n%ae%n%ad%n%aD%n%at <<'EOF'
-commit 131a310eb913d107dd3c09a65d1651175898735d
+test_format author %an%n%ae%n%ad%n%aD%n%at <<EOF
+commit $head2
 A U Thor
 [email protected]
 Thu Apr 7 15:13:13 2005 -0700
 Thu, 7 Apr 2005 15:13:13 -0700
 1112911993
-commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
+commit $head1
 A U Thor
 [email protected]
 Thu Apr 7 15:13:13 2005 -0700
@@ -82,14 +93,14 @@ Thu, 7 Apr 2005 15:13:13 -0700
 1112911993
 EOF
 
-test_format committer %cn%n%ce%n%cd%n%cD%n%ct <<'EOF'
-commit 131a310eb913d107dd3c09a65d1651175898735d
+test_format committer %cn%n%ce%n%cd%n%cD%n%ct <<EOF
+commit $head2
 C O Mitter
 [email protected]
 Thu Apr 7 15:13:13 2005 -0700
 Thu, 7 Apr 2005 15:13:13 -0700
 1112911993
-commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
+commit $head1
 C O Mitter
 [email protected]
 Thu Apr 7 15:13:13 2005 -0700
@@ -97,43 +108,43 @@ Thu, 7 Apr 2005 15:13:13 -0700
 1112911993
 EOF
 
-test_format encoding %e <<'EOF'
-commit 131a310eb913d107dd3c09a65d1651175898735d
-commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
+test_format encoding %e <<EOF
+commit $head2
+commit $head1
 EOF
 
-test_format subject %s <<'EOF'
-commit 131a310eb913d107dd3c09a65d1651175898735d
+test_format subject %s <<EOF
+commit $head2
 changed foo
-commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
+commit $head1
 added foo
 EOF
 
-test_format body %b <<'EOF'
-commit 131a310eb913d107dd3c09a65d1651175898735d
-commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
+test_format body %b <<EOF
+commit $head2
+commit $head1
 EOF
 
-test_format raw-body %B <<'EOF'
-commit 131a310eb913d107dd3c09a65d1651175898735d
+test_format raw-body %B <<EOF
+commit $head2
 changed foo
 
-commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
+commit $head1
 added foo
 
 EOF
 
-test_format colors %Credfoo%Cgreenbar%Cbluebaz%Cresetxyzzy <<'EOF'
-commit 131a310eb913d107dd3c09a65d1651175898735d
+test_format colors %Credfoo%Cgreenbar%Cbluebaz%Cresetxyzzy <<EOF
+commit $head2
 foobarbazxyzzy
-commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
+commit $head1
 foobarbazxyzzy
 EOF
 
-test_format advanced-colors '%C(red yellow bold)foo%C(reset)' <<'EOF'
-commit 131a310eb913d107dd3c09a65d1651175898735d
+test_format advanced-colors '%C(red yellow bold)foo%C(reset)' <<EOF
+commit $head2
 foo
-commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
+commit $head1
 foo
 EOF
 
@@ -186,39 +197,42 @@ This commit message is much longer than the others,
 and it will be encoded in iso8859-1. We should therefore
 include an iso8859 character: �bueno!
 EOF
+
 test_expect_success 'setup complex body' '
-git config i18n.commitencoding iso8859-1 &&
-  echo change2 >foo && git commit -a -F commit-msg
+	git config i18n.commitencoding iso8859-1 &&
+	echo change2 >foo && git commit -a -F commit-msg &&
+	head3=$(git rev-parse --verify HEAD) &&
+	head3_short=$(git rev-parse --short $head3)
 '
 
-test_format complex-encoding %e <<'EOF'
-commit 1ed88da4a5b5ed8c449114ac131efc62178734c3
+test_format complex-encoding %e <<EOF
+commit $head3
 iso8859-1
-commit 131a310eb913d107dd3c09a65d1651175898735d
-commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
+commit $head2
+commit $head1
 EOF
 
-test_format complex-subject %s <<'EOF'
-commit 1ed88da4a5b5ed8c449114ac131efc62178734c3
+test_format complex-subject %s <<EOF
+commit $head3
 Test printing of complex bodies
-commit 131a310eb913d107dd3c09a65d1651175898735d
+commit $head2
 changed foo
-commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
+commit $head1
 added foo
 EOF
 
-test_format complex-body %b <<'EOF'
-commit 1ed88da4a5b5ed8c449114ac131efc62178734c3
+test_format complex-body %b <<EOF
+commit $head3
 This commit message is much longer than the others,
 and it will be encoded in iso8859-1. We should therefore
 include an iso8859 character: �bueno!
 
-commit 131a310eb913d107dd3c09a65d1651175898735d
-commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
+commit $head2
+commit $head1
 EOF
 
 test_expect_success '%x00 shows NUL' '
-	echo  >expect commit 1ed88da4a5b5ed8c449114ac131efc62178734c3 &&
+	echo  >expect commit $head3 &&
 	echo >>expect fooQbar &&
 	git rev-list -1 --format=foo%x00bar HEAD >actual.nul &&
 	nul_to_q <actual.nul >actual &&
Signature · 1 line
1.8.3.1.15.g5c23c1e
#46 lore raw

PATCH v6 2/5 t7102 (reset): don't hardcode SHA-1 in expected outputs

In reply to Alexey Shumkin

The expected SHA-1 digests are always available in variables. Use them instead of hardcoding.

---
 t/t7102-reset.sh | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
t/t7102-reset.sh +5 -3
index df82ec9..05dfb27 100755
@@ -192,7 +192,8 @@ test_expect_success \
 	'changing files and redo the last commit should succeed' '
 	echo "3rd line 2nd file" >>secondfile &&
 	git commit -a -C ORIG_HEAD &&
-	check_changes 3d3b7be011a58ca0c179ae45d94e6c83c0b0cd0d &&
+	head4=$(git rev-parse --verify HEAD) &&
+	check_changes $head4 &&
 	test "$(git rev-parse ORIG_HEAD)" = \
 			$head5
 '
@@ -211,7 +212,7 @@ test_expect_success \
 	git reset --hard HEAD~2 &&
 	check_changes ddaefe00f1da16864591c61fdc7adb5d7cd6b74e &&
 	test "$(git rev-parse ORIG_HEAD)" = \
-			3d3b7be011a58ca0c179ae45d94e6c83c0b0cd0d
+			$head4
 '
 
 >.diff_expect
@@ -326,10 +327,11 @@ test_expect_success '--hard reset to HEAD should clear a failed merge' '
 	git checkout branch2 &&
 	echo "3rd line in branch2" >>secondfile &&
 	git commit -a -m "change in branch2" &&
+	head3=$(git rev-parse --verify HEAD) &&
 
 	test_must_fail git pull . branch1 &&
 	git reset --hard &&
-	check_changes 77abb337073fb4369a7ad69ff6f5ec0e4d6b54bb
+	check_changes $head3
 '
 
 >.diff_expect
Signature · 1 line
1.8.3.1.15.g5c23c1e
#47 lore raw

PATCH v6 3/5 t4205 (log-pretty-formats): don't hardcode SHA-1 in expected outputs

In reply to Alexey Shumkin

The expected SHA-1 digests are always available in variables. Use them instead of hardcoding.

---
 t/t4205-log-pretty-formats.sh | 48 +++++++++++++++++++++++--------------------
 1 file changed, 26 insertions(+), 22 deletions(-)
t/t4205-log-pretty-formats.sh +26 -22
index 26fbfde..73ba5e8 100755
@@ -101,7 +101,11 @@ test_expect_failure 'NUL termination with --stat' '
 
 test_expect_success 'setup more commits' '
 	test_commit "message one" one one message-one &&
-	test_commit "message two" two two message-two
+	test_commit "message two" two two message-two &&
+	head1=$(git rev-parse --verify --short HEAD~0) &&
+	head2=$(git rev-parse --verify --short HEAD~1) &&
+	head3=$(git rev-parse --verify --short HEAD~2) &&
+	head4=$(git rev-parse --verify --short HEAD~3)
 '
 
 test_expect_success 'left alignment formatting' '
@@ -117,18 +121,18 @@ EOF
 	test_cmp expected actual
 '
 
-test_expect_success 'left alignment formatting at the nth column' '
-	git log --pretty="format:%h %<|(40)%s" >actual &&
+test_expect_success 'left alignment formatting at the nth column' "
+	git log --pretty='format:%h %<|(40)%s' >actual &&
 	# complete the incomplete line at the end
 	echo >>actual &&
 	qz_to_tab_space <<\EOF >expected &&
-fa33ab1 message two                    Z
-7cd6c63 message one                    Z
-1711bf9 add bar                        Z
-af20c06 initial                        Z
+$head1 message two                    Z
+$head2 message one                    Z
+$head3 add bar                        Z
+$head4 initial                        Z
 EOF
 	test_cmp expected actual
-'
+"
 
 test_expect_success 'left alignment formatting with no padding' '
 	git log --pretty="format:%<(1)%s" >actual &&
@@ -195,18 +199,18 @@ EOF
 	test_cmp expected actual
 '
 
-test_expect_success 'right alignment formatting at the nth column' '
-	git log --pretty="format:%h %>|(40)%s" >actual &&
+test_expect_success 'right alignment formatting at the nth column' "
+	git log --pretty='format:%h %>|(40)%s' >actual &&
 	# complete the incomplete line at the end
 	echo >>actual &&
 	qz_to_tab_space <<\EOF >expected &&
-fa33ab1                      message two
-7cd6c63                      message one
-1711bf9                          add bar
-af20c06                          initial
+$head1                      message two
+$head2                      message one
+$head3                          add bar
+$head4                          initial
 EOF
 	test_cmp expected actual
-'
+"
 
 test_expect_success 'right alignment formatting with no padding' '
 	git log --pretty="format:%>(1)%s" >actual &&
@@ -234,18 +238,18 @@ EOF
 	test_cmp expected actual
 '
 
-test_expect_success 'center alignment formatting at the nth column' '
-	git log --pretty="format:%h %><|(40)%s" >actual &&
+test_expect_success 'center alignment formatting at the nth column' "
+	git log --pretty='format:%h %><|(40)%s' >actual &&
 	# complete the incomplete line at the end
 	echo >>actual &&
 	qz_to_tab_space <<\EOF >expected &&
-fa33ab1           message two          Z
-7cd6c63           message one          Z
-1711bf9             add bar            Z
-af20c06             initial            Z
+$head1           message two          Z
+$head2           message one          Z
+$head3             add bar            Z
+$head4             initial            Z
 EOF
 	test_cmp expected actual
-'
+"
 
 test_expect_success 'center alignment formatting with no padding' '
 	git log --pretty="format:%><(1)%s" >actual &&
Signature · 1 line
1.8.3.1.15.g5c23c1e
#48 lore raw

Re: [PATCH v6 0/5] Reroll patches against v1.8.3.1

In reply to Alexey Shumkin
Quoted 2 lines · Alexey Shumkin

4. [PATCH v6 4/5] pretty: Add failing tests: --format output should honor logOutputEncoding iso8859-5 encoding reverted back to cp1251 encoding (as it was in v4 series)

Thanks for a reroll, but why this change?

The reason I asked you to avoid 8859-5 is because our test do not use that encoding and I do not want to add new dependency to people when they run test. cp1251 shares exactly the same issue, doesn't it? So in that sense, this change does not make anything better.

That is why I asked you if the breakage you are trying to demonstrate about non-ASCII non-UTF8 encoding was specific to Cyrillic/Russian. I do not recall seeing your answer, but what is the right thing to do depend on it.

- If the answer is yes, then we would need to add dependency either way, and 8859-5 is just as fine as cp1251.

- If the breakage is not specific to Cyrillic, it should be reproducible using 8859-1 (latin-1), and our tests already depend on 8859-1, so we wouldn't be adding new dependencies on people.

#49 lore raw

Re: [PATCH v6 0/5] Reroll patches against v1.8.3.1

Quoted 17 lines · Junio C Hamano
Quoted 2 lines · Alexey Shumkin

4. [PATCH v6 4/5] pretty: Add failing tests: --format output should honor logOutputEncoding iso8859-5 encoding reverted back to cp1251 encoding (as it was in v4 series)

Thanks for a reroll, but why this change?

The reason I asked you to avoid 8859-5 is because our test do not use that encoding and I do not want to add new dependency to people when they run test. cp1251 shares exactly the same issue, doesn't it? So in that sense, this change does not make anything better.

That is why I asked you if the breakage you are trying to demonstrate about non-ASCII non-UTF8 encoding was specific to Cyrillic/Russian. I do not recall seeing your answer, but what is the right thing to do depend on it.

Quoted 7 lines

- If the answer is yes, then we would need to add dependency either way, and 8859-5 is just as fine as cp1251.

- If the breakage is not specific to Cyrillic, it should be reproducible using 8859-1 (latin-1), and our tests already depend on 8859-1, so we wouldn't be adding new dependencies on people.

I suppose you've missed my answer somehow. It was:
---8<---

Quoted 12 lines

Review add_file () { · line 27

Quoted 7 lines · Alexey Shumkin
(quoted diff) +2 -1
@@ -19,7 +23,8 @@ add_file () {
 			echo "$name" >"$name" &&
 			git add "$name" &&
 			test_tick &&
-			git commit -m "Add $name" || exit
+			msg_added_iso88595=$(echo "Add $name ($added $name)" | iconv -f utf-8 -t iso88595) &&
+			git -c 'i18n.commitEncoding=iso88595' commit -m "$msg_added_iso88595"

Hmph. Do we know 8859-5 is available or do these need to be protected with prereq?

Opps, this encoding is absent even in my Cygwin box :) Actually, previuosly, there was a Windows-1251 encoding, you said we'd prefer to limit different encodings used in tests, And I've made an attempt to avoid this but I'm way off the mark.

Quoted 4 lines

Can these tests be done with 8859-1 i.e. something we already depend on, by changing that $added message to latin-1, or is there something very Russian specific breakage we want to test here?

Well, actually, most popular Russian 8-bit codepages are Windows-1251 (aka cp1251) and KOI8-R. Cygwin (as a "Linux box on Windows") uses cp1251.
Iconv cannot even convert Russian messages from cp1251(or UTF-8) to latin1.
It fails.

  $ echo "коммит" | LANG= iconv -t latin1 -f UTF-8 
  iconv: illegal input sequence at position 0
("коммит" is a "commit" in Russian)
Quoted 6 lines

If the former, please redo this entire patch (not just t4041) with 8859-1.

If there is some Russian specific breakage you cannot demonstrate with 8859-1, then please explain it in the log message.

Well, it's not a "Russian specific". It's "codepage conversion" specific, but I cannot use latin1 codepage because I do not know any language that uses iso8859-1/latin1 codepage (as German, Spanish, for example) to write a commit message in it.
If someone can do the same with latin1, I'd be happy.

Quoted 12 lines

t/t6006-rev-list-format.sh

Quoted 10 lines
t/t6006-rev-list-format.sh +2 -1
index d32e65e..36e4cc0 100755
...
-# usage: test_format name format_string <expected_output
+# usage: test_format [failure] name format_string <expected_output
 test_format () {
+	local must_fail=0

This breaks tests for non-bash users. "local" is not even in POSIX.

---8<---

But today I've taken a look to Cygwin's locales more closely and found out that I've used incorrect encoding name (iso88595 instead of "canonic" iso-8859-5 that Cygwin has and "understands")

Nevertheless, as I've already said that is not a Russian locale specific issue.
The problem in tests for me now is a language (that uses iso-8859-1 encoding) I do not speak or even write ;)

Signature · 1 line
Alexey Shumkin
#50 lore raw

Re: [PATCH v6 0/5] Reroll patches against v1.8.3.1

Quoted 8 lines · Alexey Shumkin

On Tue, Jun 25, 2013 at 12:28:02PM -0700, Junio C Hamano wrote:
...
If someone can do the same with latin1, I'd be happy.
...
But today I've taken a look to Cygwin's locales more closely and found out that I've used incorrect encoding name (iso88595 instead of "canonic" iso-8859-5 that Cygwin has and "understands")

Quoted 4 lines

Nevertheless, as I've already said that is not a Russian locale specific issue.
The problem in tests for me now is a language (that uses iso-8859-1 encoding) I do not speak or even write ;)

Many of the people on thee list don't, either, and that is perfectly OK.

For the purpose of the test, "áëîõù" should be sufficient. In a sense, using such an artificial string would make it even clearer than a real message that what we are testing, no?

#51 lore raw

PATCH v6 4/5 pretty: Add failing tests: --format output should honor logOutputEncoding

In reply to Alexey Shumkin

One can set an alias

	$ git config alias.lg "log --graph --pretty=format:'%Cred%h%Creset
	-%C(yellow)%d%Creset %s %Cgreen(%cd) %C(bold blue)<%an>%Creset'
	--abbrev-commit --date=local"

to see the log as a pretty tree (like *gitk* but in a terminal).

However, log messages written in an encoding i18n.commitEncoding which differs from terminal encoding are shown corrupted even when i18n.logOutputEncoding and terminal encoding are the same (e.g. log messages committed on a Cygwin box with Windows-1251 encoding seen on a Linux box with a UTF-8 encoding and vice versa).

To simplify an example we can say the following two commands are expected to give the same output to a terminal:

	$ git log --oneline --no-color
	$ git log --pretty=format:'%h %s'

However, the former pays attention to i18n.logOutputEncoding configuration, while the latter does not when it formats "%s".

The same corruption is true for

	$ git diff --submodule=log
and
	$ git rev-list --pretty=format:%s HEAD
and
	$ git reset --hard

This patch adds failing tests for the next patch that fixes them.

---
 t/t4041-diff-submodule-option.sh |  35 +++++----
 t/t4205-log-pretty-formats.sh    | 149 ++++++++++++++++++++++++---------------
 t/t6006-rev-list-format.sh       |  83 +++++++++++++++-------
 t/t7102-reset.sh                 |  29 +++++++-
 4 files changed, 199 insertions(+), 97 deletions(-)
t/t4041-diff-submodule-option.sh +20 -15
index 32d4a60..67afb86 100755
@@ -1,6 +1,7 @@
 #!/bin/sh
 #
 # Copyright (c) 2009 Jens Lehmann, based on t7401 by Ping Yin
+# Copyright (c) 2011 Alexey Shumkin (+ non-UTF-8 commit encoding tests)
 #
 
 test_description='Support for verbose submodule differences in git diff
@@ -10,6 +11,9 @@ This test tries to verify the sanity of the --submodule option of git diff.
 
 . ./test-lib.sh
 
+# String "added" in Russian, encoded in UTF-8, used in
+# sample commit log messages in add_file() function below.
+added=$(printf "\320\264\320\276\320\261\320\260\320\262\320\273\320\265\320\275")
 add_file () {
 	(
 		cd "$1" &&
@@ -19,7 +23,8 @@ add_file () {
 			echo "$name" >"$name" &&
 			git add "$name" &&
 			test_tick &&
-			git commit -m "Add $name" || exit
+			msg_added_cp1251=$(echo "Add $name ($added $name)" | iconv -f utf-8 -t cp1251) &&
+			git -c 'i18n.commitEncoding=cp1251' commit -m "$msg_added_cp1251"
 		done >/dev/null &&
 		git rev-parse --short --verify HEAD
 	)
@@ -89,29 +94,29 @@ test_expect_success 'diff.submodule does not affect plumbing' '
 commit_file sm1 &&
 head2=$(add_file sm1 foo3)
 
-test_expect_success 'modified submodule(forward)' '
+test_expect_failure 'modified submodule(forward)' '
 	git diff-index -p --submodule=log HEAD >actual &&
 	cat >expected <<-EOF &&
 	Submodule sm1 $head1..$head2:
-	  > Add foo3
+	  > Add foo3 ($added foo3)
 	EOF
 	test_cmp expected actual
 '
 
-test_expect_success 'modified submodule(forward)' '
+test_expect_failure 'modified submodule(forward)' '
 	git diff --submodule=log >actual &&
 	cat >expected <<-EOF &&
 	Submodule sm1 $head1..$head2:
-	  > Add foo3
+	  > Add foo3 ($added foo3)
 	EOF
 	test_cmp expected actual
 '
 
-test_expect_success 'modified submodule(forward) --submodule' '
+test_expect_failure 'modified submodule(forward) --submodule' '
 	git diff --submodule >actual &&
 	cat >expected <<-EOF &&
 	Submodule sm1 $head1..$head2:
-	  > Add foo3
+	  > Add foo3 ($added foo3)
 	EOF
 	test_cmp expected actual
 '
@@ -138,25 +143,25 @@ head3=$(
 	git rev-parse --short --verify HEAD
 )
 
-test_expect_success 'modified submodule(backward)' '
+test_expect_failure 'modified submodule(backward)' '
 	git diff-index -p --submodule=log HEAD >actual &&
 	cat >expected <<-EOF &&
 	Submodule sm1 $head2..$head3 (rewind):
-	  < Add foo3
-	  < Add foo2
+	  < Add foo3 ($added foo3)
+	  < Add foo2 ($added foo2)
 	EOF
 	test_cmp expected actual
 '
 
 head4=$(add_file sm1 foo4 foo5)
-test_expect_success 'modified submodule(backward and forward)' '
+test_expect_failure 'modified submodule(backward and forward)' '
 	git diff-index -p --submodule=log HEAD >actual &&
 	cat >expected <<-EOF &&
 	Submodule sm1 $head2...$head4:
-	  > Add foo5
-	  > Add foo4
-	  < Add foo3
-	  < Add foo2
+	  > Add foo5 ($added foo5)
+	  > Add foo4 ($added foo4)
+	  < Add foo3 ($added foo3)
+	  < Add foo2 ($added foo2)
 	EOF
 	test_cmp expected actual
 '
t/t4205-log-pretty-formats.sh +93 -56

319 lines not on this page · raw message

t/t6006-rev-list-format.sh +59 -24

173 lines not on this page · raw message

t/t7102-reset.sh +27 -2
index 05dfb27..19a4cf4 100755
@@ -9,6 +9,17 @@ Documented tests for git reset'
 
 . ./test-lib.sh
 
+commit_msg() {
+	# String "2nd file modified" in Russian, encoded in UTF-8,
+	# used as a commit log message below.
+	msg=$(printf "modify 2nd file (\320\270\320\267\320\274\320\265\320\275\321\221\320\275 \321\204\320\260\320\271\320\273)")
+	if test -n "$1"
+	then
+		msg=$(echo $msg | iconv -f utf-8 -t $1)
+	fi
+	echo $msg
+}
+
 test_expect_success 'creating initial files and commits' '
 	test_tick &&
 	echo "1st file" >first &&
@@ -28,7 +39,7 @@ test_expect_success 'creating initial files and commits' '
 
 	echo "1st line 2nd file" >secondfile &&
 	echo "2nd line 2nd file" >>secondfile &&
-	git commit -a -m "modify 2nd file" &&
+	git -c "i18n.commitEncoding=cp1251" commit -a -m "$(commit_msg cp1251)" &&
 	head5=$(git rev-parse --verify HEAD)
 '
 # git log --pretty=oneline # to see those SHA1 involved
@@ -44,6 +55,20 @@ check_changes () {
 	done | test_cmp .cat_expect -
 }
 
+test_expect_failure 'reset --hard message' '
+	hex=$(git log -1 --format="%h") &&
+	git reset --hard > .actual &&
+	echo HEAD is now at $hex $(commit_msg) > .expected &&
+	test_cmp .expected .actual
+'
+
+test_expect_success 'reset --hard message (cp1251 logoutencoding)' '
+	hex=$(git log -1 --format="%h") &&
+	git -c "i18n.logOutputEncoding=cp1251" reset --hard > .actual &&
+	echo HEAD is now at $hex $(commit_msg cp1251) > .expected &&
+	test_cmp .expected .actual
+'
+
 >.diff_expect
 >.cached_expect
 cat >.cat_expect <<EOF
@@ -304,7 +329,7 @@ test_expect_success 'redoing the last two commits should succeed' '
 
 	echo "1st line 2nd file" >secondfile &&
 	echo "2nd line 2nd file" >>secondfile &&
-	git commit -a -m "modify 2nd file" &&
+	git -c "i18n.commitEncoding=cp1251" commit -a -m "$(commit_msg cp1251)" &&
 	check_changes $head5
 '
 
Signature · 1 line
1.8.3.1.15.g5c23c1e
#52 lore raw

PATCH v6 5/5 pretty: --format output should honor logOutputEncoding

In reply to Alexey Shumkin

One can set an alias

	$ git config [--global] alias.lg "log --graph --pretty=format:'%Cred%h%Creset
	-%C(yellow)%d%Creset %s %Cgreen(%cd) %C(bold blue)<%an>%Creset'
	--abbrev-commit --date=local"

to see the log as a pretty tree (like *gitk* but in a terminal).

However, log messages written in an encoding i18n.commitEncoding which differs from terminal encoding are shown corrupted even when i18n.logOutputEncoding and terminal encoding are the same (e.g. log messages committed on a Cygwin box with Windows-1251 encoding seen on a Linux box with a UTF-8 encoding and vice versa).

To simplify an example we can say the following two commands are expected to give the same output to a terminal:

	$ git log --oneline --no-color
	$ git log --pretty=format:'%h %s'

However, the former pays attention to i18n.logOutputEncoding configuration, while the latter does not when it formats "%s".

The same corruption is true for

	$ git diff --submodule=log
and
	$ git rev-list --pretty=format:%s HEAD
and
	$ git reset --hard

This patch makes pretty --format honor logOutputEncoding when it formats log message.

---
 builtin/reset.c                  |  6 ++++--
 builtin/rev-list.c               |  1 +
 builtin/shortlog.c               |  1 +
 log-tree.c                       |  1 +
 submodule.c                      |  1 +
 t/t4041-diff-submodule-option.sh | 10 +++++-----
 t/t4205-log-pretty-formats.sh    | 34 +++++++++++++++++-----------------
 t/t6006-rev-list-format.sh       |  8 ++++----
 t/t7102-reset.sh                 |  2 +-
 9 files changed, 35 insertions(+), 29 deletions(-)
builtin/reset.c +4 -2
index 6032131..a6cacc6 100644
@@ -92,11 +92,12 @@ static int reset_index(const unsigned char *sha1, int reset_type, int quiet)
 
 static void print_new_head_line(struct commit *commit)
 {
-	const char *hex, *body;
+	const char *hex, *body, *msg;
 
 	hex = find_unique_abbrev(commit->object.sha1, DEFAULT_ABBREV);
 	printf(_("HEAD is now at %s"), hex);
-	body = strstr(commit->buffer, "\n\n");
+	msg = logmsg_reencode(commit, NULL, get_log_output_encoding());
+	body = strstr(msg, "\n\n");
 	if (body) {
 		const char *eol;
 		size_t len;
@@ -107,6 +108,7 @@ static void print_new_head_line(struct commit *commit)
 	}
 	else
 		printf("\n");
+	logmsg_free(msg, commit);
 }
 
 static void update_index_from_diff(struct diff_queue_struct *q,
builtin/rev-list.c +1 -0
index 67701be..a5ec30d 100644
@@ -111,6 +111,7 @@ static void show_commit(struct commit *commit, void *data)
 		ctx.date_mode = revs->date_mode;
 		ctx.date_mode_explicit = revs->date_mode_explicit;
 		ctx.fmt = revs->commit_format;
+		ctx.output_encoding = get_log_output_encoding();
 		pretty_print_commit(&ctx, commit, &buf);
 		if (revs->graph) {
 			if (buf.len) {
builtin/shortlog.c +1 -0
index 1fd6f8a..1434f8f 100644
@@ -137,6 +137,7 @@ void shortlog_add_commit(struct shortlog *log, struct commit *commit)
 		ctx.subject = "";
 		ctx.after_subject = "";
 		ctx.date_mode = DATE_NORMAL;
+		ctx.output_encoding = get_log_output_encoding();
 		pretty_print_commit(&ctx, commit, &ufbuf);
 		buffer = ufbuf.buf;
 	} else if (*buffer) {
log-tree.c +1 -0
index 1946e9c..5277d3e 100644
@@ -616,6 +616,7 @@ void show_log(struct rev_info *opt)
 	ctx.fmt = opt->commit_format;
 	ctx.mailmap = opt->mailmap;
 	ctx.color = opt->diffopt.use_color;
+	ctx.output_encoding = get_log_output_encoding();
 	pretty_print_commit(&ctx, commit, &msgbuf);
 
 	if (opt->add_signoff)
submodule.c +1 -0
index 1821a5b..78734e1 100644
@@ -226,6 +226,7 @@ static void print_submodule_summary(struct rev_info *rev, FILE *f,
 	while ((commit = get_revision(rev))) {
 		struct pretty_print_context ctx = {0};
 		ctx.date_mode = rev->date_mode;
+		ctx.output_encoding = get_log_output_encoding();
 		strbuf_setlen(&sb, 0);
 		strbuf_addstr(&sb, line_prefix);
 		if (commit->object.flags & SYMMETRIC_LEFT) {
t/t4041-diff-submodule-option.sh +5 -5
index 67afb86..9ba4b8e 100755
@@ -94,7 +94,7 @@ test_expect_success 'diff.submodule does not affect plumbing' '
 commit_file sm1 &&
 head2=$(add_file sm1 foo3)
 
-test_expect_failure 'modified submodule(forward)' '
+test_expect_success 'modified submodule(forward)' '
 	git diff-index -p --submodule=log HEAD >actual &&
 	cat >expected <<-EOF &&
 	Submodule sm1 $head1..$head2:
@@ -103,7 +103,7 @@ test_expect_failure 'modified submodule(forward)' '
 	test_cmp expected actual
 '
 
-test_expect_failure 'modified submodule(forward)' '
+test_expect_success 'modified submodule(forward)' '
 	git diff --submodule=log >actual &&
 	cat >expected <<-EOF &&
 	Submodule sm1 $head1..$head2:
@@ -112,7 +112,7 @@ test_expect_failure 'modified submodule(forward)' '
 	test_cmp expected actual
 '
 
-test_expect_failure 'modified submodule(forward) --submodule' '
+test_expect_success 'modified submodule(forward) --submodule' '
 	git diff --submodule >actual &&
 	cat >expected <<-EOF &&
 	Submodule sm1 $head1..$head2:
@@ -143,7 +143,7 @@ head3=$(
 	git rev-parse --short --verify HEAD
 )
 
-test_expect_failure 'modified submodule(backward)' '
+test_expect_success 'modified submodule(backward)' '
 	git diff-index -p --submodule=log HEAD >actual &&
 	cat >expected <<-EOF &&
 	Submodule sm1 $head2..$head3 (rewind):
@@ -154,7 +154,7 @@ test_expect_failure 'modified submodule(backward)' '
 '
 
 head4=$(add_file sm1 foo4 foo5)
-test_expect_failure 'modified submodule(backward and forward)' '
+test_expect_success 'modified submodule(backward and forward)' '
 	git diff-index -p --submodule=log HEAD >actual &&
 	cat >expected <<-EOF &&
 	Submodule sm1 $head2...$head4:
t/t4205-log-pretty-formats.sh +17 -17
index a45bb55..5a14124 100755
@@ -69,7 +69,7 @@ test_expect_success 'alias user-defined tformat with %s (cp1251 encoding)' '
 	test_cmp expected-s actual-s
 '
 
-test_expect_failure 'alias user-defined tformat with %s (utf-8 encoding)' '
+test_expect_success 'alias user-defined tformat with %s (utf-8 encoding)' '
 	git log --oneline >expected-s &&
 	git log --pretty="tformat:%h %s" >actual-s &&
 	test_cmp expected-s actual-s
@@ -108,19 +108,19 @@ test_expect_success 'alias loop' '
 	test_must_fail git log --pretty=test-foo
 '
 
-test_expect_failure 'NUL separation' '
+test_expect_success 'NUL separation' '
 	printf "add bar\0$(commit_msg)" >expected &&
 	git log -z --pretty="format:%s" >actual &&
 	test_cmp expected actual
 '
 
-test_expect_failure 'NUL termination' '
+test_expect_success 'NUL termination' '
 	printf "add bar\0$(commit_msg)\0" >expected &&
 	git log -z --pretty="tformat:%s" >actual &&
 	test_cmp expected actual
 '
 
-test_expect_failure 'NUL separation with --stat' '
+test_expect_success 'NUL separation with --stat' '
 	stat0_part=$(git diff --stat HEAD^ HEAD) &&
 	stat1_part=$(git diff-tree --no-commit-id --stat --root HEAD^) &&
 	printf "add bar\n$stat0_part\n\0$(commit_msg)\n$stat1_part\n" >expected &&
@@ -145,7 +145,7 @@ test_expect_success 'setup more commits' '
 	head4=$(git rev-parse --verify --short HEAD~3)
 '
 
-test_expect_failure 'left alignment formatting' "
+test_expect_success 'left alignment formatting' "
 	git log --pretty='format:%<(40)%s' >actual &&
 	# complete the incomplete line at the end
 	echo >>actual &&
@@ -158,7 +158,7 @@ EOF
 	test_cmp expected actual
 "
 
-test_expect_failure 'left alignment formatting at the nth column' "
+test_expect_success 'left alignment formatting at the nth column' "
 	git log --pretty='format:%h %<|(40)%s' >actual &&
 	# complete the incomplete line at the end
 	echo >>actual &&
@@ -171,7 +171,7 @@ EOF
 	test_cmp expected actual
 "
 
-test_expect_failure 'left alignment formatting with no padding' "
+test_expect_success 'left alignment formatting with no padding' "
 	git log --pretty='format:%<(1)%s' >actual &&
 	# complete the incomplete line at the end
 	echo >>actual &&
@@ -184,7 +184,7 @@ EOF
 	test_cmp expected actual
 "
 
-test_expect_failure 'left alignment formatting with trunc' "
+test_expect_success 'left alignment formatting with trunc' "
 	git log --pretty='format:%<(10,trunc)%s' >actual &&
 	# complete the incomplete line at the end
 	echo >>actual &&
@@ -197,7 +197,7 @@ EOF
 	test_cmp expected actual
 "
 
-test_expect_failure 'left alignment formatting with ltrunc' "
+test_expect_success 'left alignment formatting with ltrunc' "
 	git log --pretty='format:%<(10,ltrunc)%s' >actual &&
 	# complete the incomplete line at the end
 	echo >>actual &&
@@ -210,7 +210,7 @@ EOF
 	test_cmp expected actual
 "
 
-test_expect_failure 'left alignment formatting with mtrunc' "
+test_expect_success 'left alignment formatting with mtrunc' "
 	git log --pretty='format:%<(10,mtrunc)%s' >actual &&
 	# complete the incomplete line at the end
 	echo >>actual &&
@@ -223,7 +223,7 @@ EOF
 	test_cmp expected actual
 "
 
-test_expect_failure 'right alignment formatting' "
+test_expect_success 'right alignment formatting' "
 	git log --pretty='format:%>(40)%s' >actual &&
 	# complete the incomplete line at the end
 	echo >>actual &&
@@ -236,7 +236,7 @@ EOF
 	test_cmp expected actual
 "
 
-test_expect_failure 'right alignment formatting at the nth column' "
+test_expect_success 'right alignment formatting at the nth column' "
 	git log --pretty='format:%h %>|(40)%s' >actual &&
 	# complete the incomplete line at the end
 	echo >>actual &&
@@ -249,7 +249,7 @@ EOF
 	test_cmp expected actual
 "
 
-test_expect_failure 'right alignment formatting with no padding' "
+test_expect_success 'right alignment formatting with no padding' "
 	git log --pretty='format:%>(1)%s' >actual &&
 	# complete the incomplete line at the end
 	echo >>actual &&
@@ -262,7 +262,7 @@ EOF
 	test_cmp expected actual
 "
 
-test_expect_failure 'center alignment formatting' "
+test_expect_success 'center alignment formatting' "
 	git log --pretty='format:%><(40)%s' >actual &&
 	# complete the incomplete line at the end
 	echo >>actual &&
@@ -275,7 +275,7 @@ EOF
 	test_cmp expected actual
 "
 
-test_expect_failure 'center alignment formatting at the nth column' "
+test_expect_success 'center alignment formatting at the nth column' "
 	git log --pretty='format:%h %><|(40)%s' >actual &&
 	# complete the incomplete line at the end
 	echo >>actual &&
@@ -288,7 +288,7 @@ EOF
 	test_cmp expected actual
 "
 
-test_expect_failure 'center alignment formatting with no padding' "
+test_expect_success 'center alignment formatting with no padding' "
 	git log --pretty='format:%><(1)%s' >actual &&
 	# complete the incomplete line at the end
 	echo >>actual &&
@@ -301,7 +301,7 @@ EOF
 	test_cmp expected actual
 "
 
-test_expect_failure 'left/right alignment formatting with stealing' "
+test_expect_success 'left/right alignment formatting with stealing' "
 	git commit --amend -m short --author 'long long long <[email protected]>' &&
 	git log --pretty='format:%<(10,trunc)%s%>>(10,ltrunc)% an' >actual &&
 	# complete the incomplete line at the end
t/t6006-rev-list-format.sh +4 -4
index ce62214..6356046 100755
@@ -141,7 +141,7 @@ commit $head1
 cp1251
 EOF
 
-test_format failure subject %s <<EOF
+test_format subject %s <<EOF
 commit $head2
 $changed
 commit $head1
@@ -153,7 +153,7 @@ commit $head2
 commit $head1
 EOF
 
-test_format failure raw-body %B <<EOF
+test_format raw-body %B <<EOF
 commit $head2
 $changed
 
@@ -247,7 +247,7 @@ commit $head1
 cp1251
 EOF
 
-test_format failure complex-subject %s <<EOF
+test_format complex-subject %s <<EOF
 commit $head3
 Test printing of complex bodies
 commit $head2
@@ -256,7 +256,7 @@ commit $head1
 $added
 EOF
 
-test_format failure complex-body %b <<EOF
+test_format complex-body %b <<EOF
 commit $head3
 This commit message is much longer than the others,
 and it will be encoded in iso8859-1. We should therefore
t/t7102-reset.sh +1 -1
index 19a4cf4..ea96e43 100755
@@ -55,7 +55,7 @@ check_changes () {
 	done | test_cmp .cat_expect -
 }
 
-test_expect_failure 'reset --hard message' '
+test_expect_success 'reset --hard message' '
 	hex=$(git log -1 --format="%h") &&
 	git reset --hard > .actual &&
 	echo HEAD is now at $hex $(commit_msg) > .expected &&
Signature · 1 line
1.8.3.1.15.g5c23c1e
#53 lore raw

v7 cover Reroll patches against v1.8.3.1

In reply to Alexey Shumkin

v7 of this patch series includes the following changes against v6:
1. [PATCH v7 1/5] t6006 (rev-list-format): don't hardcode SHA-1 in expected outputs untouched
2. [PATCH v7 2/5] t7102 (reset): don't hardcode SHA-1 in expected outputs untouched
3. [PATCH v7 3/5] t4205 (log-pretty-formats): don't hardcode SHA-1 in expected outputs untouched
4. [PATCH v7 4/5] pretty: Add failing tests: --format output should honor logOutputEncoding cp1251 encoding changed to iso-8859-1 encoding already used in tests Test commit messages contain words ("changed" and "added") in German (which is covered by iso-8859-1 encoding)
They are translated from English (verified in Russian) with Google Translate
5. [PATCH v7 5/5] pretty: --format output should honor logOutputEncoding builtin/reset.c:
"const char ..., *msg;" declaration replaced with "char *msg;"
to avoid compiler warning on the line "logmsg_free(msg, commit);"

P.S.
It's all started here [http://thread.gmane.org/gmane.comp.version-control.git/177634]

Alexey Shumkin (5):
t6006 (rev-list-format): don't hardcode SHA-1 in expected outputs t7102 (reset): don't hardcode SHA-1 in expected outputs t4205 (log-pretty-formats): don't hardcode SHA-1 in expected outputs
pretty: Add failing tests: --format output should honor
logOutputEncoding
pretty: --format output should honor logOutputEncoding

 builtin/reset.c                  |   5 +-
 builtin/rev-list.c               |   1 +
 builtin/shortlog.c               |   1 +
 log-tree.c                       |   1 +
 submodule.c                      |   1 +
 t/t4041-diff-submodule-option.sh |  25 +++--
 t/t4205-log-pretty-formats.sh    | 179 ++++++++++++++++++++-------------
 t/t6006-rev-list-format.sh       | 207 ++++++++++++++++++++++++---------------
 t/t7102-reset.sh                 |  37 ++++++-
 9 files changed, 293 insertions(+), 164 deletions(-)
Signature · 1 line
1.8.3.1.15.g5c23c1e
#54 lore raw

PATCH v7 1/5 t6006 (rev-list-format): don't hardcode SHA-1 in expected outputs

The expected SHA-1 digests are always available in variables. Use them instead of hardcoding.

---
 t/t6006-rev-list-format.sh | 140 +++++++++++++++++++++++++--------------------
 1 file changed, 77 insertions(+), 63 deletions(-)
t/t6006-rev-list-format.sh +77 -63
index 0393c9f..cc1008d 100755
@@ -7,8 +7,19 @@ test_description='git rev-list --pretty=format test'
 
 test_tick
 test_expect_success 'setup' '
-touch foo && git add foo && git commit -m "added foo" &&
-  echo changed >foo && git commit -a -m "changed foo"
+	: >foo &&
+	git add foo &&
+	git commit -m "added foo" &&
+	head1=$(git rev-parse --verify HEAD) &&
+	head1_short=$(git rev-parse --verify --short $head1) &&
+	tree1=$(git rev-parse --verify HEAD:) &&
+	tree1_short=$(git rev-parse --verify --short $tree1) &&
+	echo changed >foo &&
+	git commit -a -m "changed foo" &&
+	head2=$(git rev-parse --verify HEAD) &&
+	head2_short=$(git rev-parse --verify --short $head2) &&
+	tree2=$(git rev-parse --verify HEAD:) &&
+	tree2_short=$(git rev-parse --verify --short $tree2)
 '
 
 # usage: test_format name format_string <expected_output
@@ -32,49 +43,49 @@ has_no_color () {
 	test_cmp expect "$1"
 }
 
-test_format percent %%h <<'EOF'
-commit 131a310eb913d107dd3c09a65d1651175898735d
+test_format percent %%h <<EOF
+commit $head2
 %h
-commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
+commit $head1
 %h
 EOF
 
-test_format hash %H%n%h <<'EOF'
-commit 131a310eb913d107dd3c09a65d1651175898735d
-131a310eb913d107dd3c09a65d1651175898735d
-131a310
-commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
-86c75cfd708a0e5868dc876ed5b8bb66c80b4873
-86c75cf
+test_format hash %H%n%h <<EOF
+commit $head2
+$head2
+$head2_short
+commit $head1
+$head1
+$head1_short
 EOF
 
-test_format tree %T%n%t <<'EOF'
-commit 131a310eb913d107dd3c09a65d1651175898735d
-fe722612f26da5064c32ca3843aa154bdb0b08a0
-fe72261
-commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
-4d5fcadc293a348e88f777dc0920f11e7d71441c
-4d5fcad
+test_format tree %T%n%t <<EOF
+commit $head2
+$tree2
+$tree2_short
+commit $head1
+$tree1
+$tree1_short
 EOF
 
-test_format parents %P%n%p <<'EOF'
-commit 131a310eb913d107dd3c09a65d1651175898735d
-86c75cfd708a0e5868dc876ed5b8bb66c80b4873
-86c75cf
-commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
+test_format parents %P%n%p <<EOF
+commit $head2
+$head1
+$head1_short
+commit $head1
 
 
 EOF
 
 # we don't test relative here
-test_format author %an%n%ae%n%ad%n%aD%n%at <<'EOF'
-commit 131a310eb913d107dd3c09a65d1651175898735d
+test_format author %an%n%ae%n%ad%n%aD%n%at <<EOF
+commit $head2
 A U Thor
 [email protected]
 Thu Apr 7 15:13:13 2005 -0700
 Thu, 7 Apr 2005 15:13:13 -0700
 1112911993
-commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
+commit $head1
 A U Thor
 [email protected]
 Thu Apr 7 15:13:13 2005 -0700
@@ -82,14 +93,14 @@ Thu, 7 Apr 2005 15:13:13 -0700
 1112911993
 EOF
 
-test_format committer %cn%n%ce%n%cd%n%cD%n%ct <<'EOF'
-commit 131a310eb913d107dd3c09a65d1651175898735d
+test_format committer %cn%n%ce%n%cd%n%cD%n%ct <<EOF
+commit $head2
 C O Mitter
 [email protected]
 Thu Apr 7 15:13:13 2005 -0700
 Thu, 7 Apr 2005 15:13:13 -0700
 1112911993
-commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
+commit $head1
 C O Mitter
 [email protected]
 Thu Apr 7 15:13:13 2005 -0700
@@ -97,43 +108,43 @@ Thu, 7 Apr 2005 15:13:13 -0700
 1112911993
 EOF
 
-test_format encoding %e <<'EOF'
-commit 131a310eb913d107dd3c09a65d1651175898735d
-commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
+test_format encoding %e <<EOF
+commit $head2
+commit $head1
 EOF
 
-test_format subject %s <<'EOF'
-commit 131a310eb913d107dd3c09a65d1651175898735d
+test_format subject %s <<EOF
+commit $head2
 changed foo
-commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
+commit $head1
 added foo
 EOF
 
-test_format body %b <<'EOF'
-commit 131a310eb913d107dd3c09a65d1651175898735d
-commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
+test_format body %b <<EOF
+commit $head2
+commit $head1
 EOF
 
-test_format raw-body %B <<'EOF'
-commit 131a310eb913d107dd3c09a65d1651175898735d
+test_format raw-body %B <<EOF
+commit $head2
 changed foo
 
-commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
+commit $head1
 added foo
 
 EOF
 
-test_format colors %Credfoo%Cgreenbar%Cbluebaz%Cresetxyzzy <<'EOF'
-commit 131a310eb913d107dd3c09a65d1651175898735d
+test_format colors %Credfoo%Cgreenbar%Cbluebaz%Cresetxyzzy <<EOF
+commit $head2
 foobarbazxyzzy
-commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
+commit $head1
 foobarbazxyzzy
 EOF
 
-test_format advanced-colors '%C(red yellow bold)foo%C(reset)' <<'EOF'
-commit 131a310eb913d107dd3c09a65d1651175898735d
+test_format advanced-colors '%C(red yellow bold)foo%C(reset)' <<EOF
+commit $head2
 foo
-commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
+commit $head1
 foo
 EOF
 
@@ -186,39 +197,42 @@ This commit message is much longer than the others,
 and it will be encoded in iso8859-1. We should therefore
 include an iso8859 character: �bueno!
 EOF
+
 test_expect_success 'setup complex body' '
-git config i18n.commitencoding iso8859-1 &&
-  echo change2 >foo && git commit -a -F commit-msg
+	git config i18n.commitencoding iso8859-1 &&
+	echo change2 >foo && git commit -a -F commit-msg &&
+	head3=$(git rev-parse --verify HEAD) &&
+	head3_short=$(git rev-parse --short $head3)
 '
 
-test_format complex-encoding %e <<'EOF'
-commit 1ed88da4a5b5ed8c449114ac131efc62178734c3
+test_format complex-encoding %e <<EOF
+commit $head3
 iso8859-1
-commit 131a310eb913d107dd3c09a65d1651175898735d
-commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
+commit $head2
+commit $head1
 EOF
 
-test_format complex-subject %s <<'EOF'
-commit 1ed88da4a5b5ed8c449114ac131efc62178734c3
+test_format complex-subject %s <<EOF
+commit $head3
 Test printing of complex bodies
-commit 131a310eb913d107dd3c09a65d1651175898735d
+commit $head2
 changed foo
-commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
+commit $head1
 added foo
 EOF
 
-test_format complex-body %b <<'EOF'
-commit 1ed88da4a5b5ed8c449114ac131efc62178734c3
+test_format complex-body %b <<EOF
+commit $head3
 This commit message is much longer than the others,
 and it will be encoded in iso8859-1. We should therefore
 include an iso8859 character: �bueno!
 
-commit 131a310eb913d107dd3c09a65d1651175898735d
-commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
+commit $head2
+commit $head1
 EOF
 
 test_expect_success '%x00 shows NUL' '
-	echo  >expect commit 1ed88da4a5b5ed8c449114ac131efc62178734c3 &&
+	echo  >expect commit $head3 &&
 	echo >>expect fooQbar &&
 	git rev-list -1 --format=foo%x00bar HEAD >actual.nul &&
 	nul_to_q <actual.nul >actual &&
Signature · 1 line
1.8.3.1.15.g5c23c1e
#55 lore raw

Re: [PATCH v7 0/5] Reroll patches against v1.8.3.1

In reply to Alexey Shumkin
Quoted 17 lines · Alexey Shumkin

v7 of this patch series includes the following changes against v6:
1. [PATCH v7 1/5] t6006 (rev-list-format): don't hardcode SHA-1 in expected outputs untouched
2. [PATCH v7 2/5] t7102 (reset): don't hardcode SHA-1 in expected outputs untouched
3. [PATCH v7 3/5] t4205 (log-pretty-formats): don't hardcode SHA-1 in expected outputs untouched
4. [PATCH v7 4/5] pretty: Add failing tests: --format output should honor logOutputEncoding cp1251 encoding changed to iso-8859-1 encoding already used in tests Test commit messages contain words ("changed" and "added") in German (which is covered by iso-8859-1 encoding)
They are translated from English (verified in Russian) with Google Translate
5. [PATCH v7 5/5] pretty: --format output should honor logOutputEncoding builtin/reset.c:
"const char ..., *msg;" declaration replaced with "char *msg;"
to avoid compiler warning on the line "logmsg_free(msg, commit);"

Quoted 2 lines

P.S.
It's all started here [http://thread.gmane.org/gmane.comp.version-control.git/177634]

Thanks for a quick reroll and reference to previous threads in the cover letter.

#56 lore raw

PATCH v7 2/5 t7102 (reset): don't hardcode SHA-1 in expected outputs

In reply to Alexey Shumkin

The expected SHA-1 digests are always available in variables. Use them instead of hardcoding.

---
 t/t7102-reset.sh | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
t/t7102-reset.sh +5 -3
index df82ec9..05dfb27 100755
@@ -192,7 +192,8 @@ test_expect_success \
 	'changing files and redo the last commit should succeed' '
 	echo "3rd line 2nd file" >>secondfile &&
 	git commit -a -C ORIG_HEAD &&
-	check_changes 3d3b7be011a58ca0c179ae45d94e6c83c0b0cd0d &&
+	head4=$(git rev-parse --verify HEAD) &&
+	check_changes $head4 &&
 	test "$(git rev-parse ORIG_HEAD)" = \
 			$head5
 '
@@ -211,7 +212,7 @@ test_expect_success \
 	git reset --hard HEAD~2 &&
 	check_changes ddaefe00f1da16864591c61fdc7adb5d7cd6b74e &&
 	test "$(git rev-parse ORIG_HEAD)" = \
-			3d3b7be011a58ca0c179ae45d94e6c83c0b0cd0d
+			$head4
 '
 
 >.diff_expect
@@ -326,10 +327,11 @@ test_expect_success '--hard reset to HEAD should clear a failed merge' '
 	git checkout branch2 &&
 	echo "3rd line in branch2" >>secondfile &&
 	git commit -a -m "change in branch2" &&
+	head3=$(git rev-parse --verify HEAD) &&
 
 	test_must_fail git pull . branch1 &&
 	git reset --hard &&
-	check_changes 77abb337073fb4369a7ad69ff6f5ec0e4d6b54bb
+	check_changes $head3
 '
 
 >.diff_expect
Signature · 1 line
1.8.3.1.15.g5c23c1e
#57 lore raw

PATCH v7 3/5 t4205 (log-pretty-formats): don't hardcode SHA-1 in expected outputs

In reply to Alexey Shumkin

The expected SHA-1 digests are always available in variables. Use them instead of hardcoding.

---
 t/t4205-log-pretty-formats.sh | 48 +++++++++++++++++++++++--------------------
 1 file changed, 26 insertions(+), 22 deletions(-)
t/t4205-log-pretty-formats.sh +26 -22
index 26fbfde..73ba5e8 100755
@@ -101,7 +101,11 @@ test_expect_failure 'NUL termination with --stat' '
 
 test_expect_success 'setup more commits' '
 	test_commit "message one" one one message-one &&
-	test_commit "message two" two two message-two
+	test_commit "message two" two two message-two &&
+	head1=$(git rev-parse --verify --short HEAD~0) &&
+	head2=$(git rev-parse --verify --short HEAD~1) &&
+	head3=$(git rev-parse --verify --short HEAD~2) &&
+	head4=$(git rev-parse --verify --short HEAD~3)
 '
 
 test_expect_success 'left alignment formatting' '
@@ -117,18 +121,18 @@ EOF
 	test_cmp expected actual
 '
 
-test_expect_success 'left alignment formatting at the nth column' '
-	git log --pretty="format:%h %<|(40)%s" >actual &&
+test_expect_success 'left alignment formatting at the nth column' "
+	git log --pretty='format:%h %<|(40)%s' >actual &&
 	# complete the incomplete line at the end
 	echo >>actual &&
 	qz_to_tab_space <<\EOF >expected &&
-fa33ab1 message two                    Z
-7cd6c63 message one                    Z
-1711bf9 add bar                        Z
-af20c06 initial                        Z
+$head1 message two                    Z
+$head2 message one                    Z
+$head3 add bar                        Z
+$head4 initial                        Z
 EOF
 	test_cmp expected actual
-'
+"
 
 test_expect_success 'left alignment formatting with no padding' '
 	git log --pretty="format:%<(1)%s" >actual &&
@@ -195,18 +199,18 @@ EOF
 	test_cmp expected actual
 '
 
-test_expect_success 'right alignment formatting at the nth column' '
-	git log --pretty="format:%h %>|(40)%s" >actual &&
+test_expect_success 'right alignment formatting at the nth column' "
+	git log --pretty='format:%h %>|(40)%s' >actual &&
 	# complete the incomplete line at the end
 	echo >>actual &&
 	qz_to_tab_space <<\EOF >expected &&
-fa33ab1                      message two
-7cd6c63                      message one
-1711bf9                          add bar
-af20c06                          initial
+$head1                      message two
+$head2                      message one
+$head3                          add bar
+$head4                          initial
 EOF
 	test_cmp expected actual
-'
+"
 
 test_expect_success 'right alignment formatting with no padding' '
 	git log --pretty="format:%>(1)%s" >actual &&
@@ -234,18 +238,18 @@ EOF
 	test_cmp expected actual
 '
 
-test_expect_success 'center alignment formatting at the nth column' '
-	git log --pretty="format:%h %><|(40)%s" >actual &&
+test_expect_success 'center alignment formatting at the nth column' "
+	git log --pretty='format:%h %><|(40)%s' >actual &&
 	# complete the incomplete line at the end
 	echo >>actual &&
 	qz_to_tab_space <<\EOF >expected &&
-fa33ab1           message two          Z
-7cd6c63           message one          Z
-1711bf9             add bar            Z
-af20c06             initial            Z
+$head1           message two          Z
+$head2           message one          Z
+$head3             add bar            Z
+$head4             initial            Z
 EOF
 	test_cmp expected actual
-'
+"
 
 test_expect_success 'center alignment formatting with no padding' '
 	git log --pretty="format:%><(1)%s" >actual &&
Signature · 1 line
1.8.3.1.15.g5c23c1e
#58 lore raw

PATCH v7 4/5 pretty: Add failing tests: --format output should honor logOutputEncoding

In reply to Alexey Shumkin

One can set an alias

	$ git config alias.lg "log --graph --pretty=format:'%Cred%h%Creset
	-%C(yellow)%d%Creset %s %Cgreen(%cd) %C(bold blue)<%an>%Creset'
	--abbrev-commit --date=local"

to see the log as a pretty tree (like *gitk* but in a terminal).

However, log messages written in an encoding i18n.commitEncoding which differs from terminal encoding are shown corrupted even when i18n.logOutputEncoding and terminal encoding are the same (e.g. log messages committed on a Cygwin box with Windows-1251 encoding seen on a Linux box with a UTF-8 encoding and vice versa).

To simplify an example we can say the following two commands are expected to give the same output to a terminal:

	$ git log --oneline --no-color
	$ git log --pretty=format:'%h %s'

However, the former pays attention to i18n.logOutputEncoding configuration, while the latter does not when it formats "%s".

The same corruption is true for

	$ git diff --submodule=log
and
	$ git rev-list --pretty=format:%s HEAD
and
	$ git reset --hard

This patch adds failing tests for the next patch that fixes them.

---
 t/t4041-diff-submodule-option.sh |  35 +++++----
 t/t4205-log-pretty-formats.sh    | 149 ++++++++++++++++++++++++---------------
 t/t6006-rev-list-format.sh       |  83 +++++++++++++++-------
 t/t7102-reset.sh                 |  29 +++++++-
 4 files changed, 199 insertions(+), 97 deletions(-)
t/t4041-diff-submodule-option.sh +20 -15
index 32d4a60..2a7877d 100755
@@ -1,6 +1,7 @@
 #!/bin/sh
 #
 # Copyright (c) 2009 Jens Lehmann, based on t7401 by Ping Yin
+# Copyright (c) 2011 Alexey Shumkin (+ non-UTF-8 commit encoding tests)
 #
 
 test_description='Support for verbose submodule differences in git diff
@@ -10,6 +11,9 @@ This test tries to verify the sanity of the --submodule option of git diff.
 
 . ./test-lib.sh
 
+# String "added" in German (translated with Google Translate), encoded in UTF-8,
+# used in sample commit log messages in add_file() function below.
+added=$(printf "hinzugef\303\274gt")
 add_file () {
 	(
 		cd "$1" &&
@@ -19,7 +23,8 @@ add_file () {
 			echo "$name" >"$name" &&
 			git add "$name" &&
 			test_tick &&
-			git commit -m "Add $name" || exit
+			msg_added_iso88591=$(echo "Add $name ($added $name)" | iconv -f utf-8 -t iso-8859-1) &&
+			git -c 'i18n.commitEncoding=iso-8859-1' commit -m "$msg_added_iso88591"
 		done >/dev/null &&
 		git rev-parse --short --verify HEAD
 	)
@@ -89,29 +94,29 @@ test_expect_success 'diff.submodule does not affect plumbing' '
 commit_file sm1 &&
 head2=$(add_file sm1 foo3)
 
-test_expect_success 'modified submodule(forward)' '
+test_expect_failure 'modified submodule(forward)' '
 	git diff-index -p --submodule=log HEAD >actual &&
 	cat >expected <<-EOF &&
 	Submodule sm1 $head1..$head2:
-	  > Add foo3
+	  > Add foo3 ($added foo3)
 	EOF
 	test_cmp expected actual
 '
 
-test_expect_success 'modified submodule(forward)' '
+test_expect_failure 'modified submodule(forward)' '
 	git diff --submodule=log >actual &&
 	cat >expected <<-EOF &&
 	Submodule sm1 $head1..$head2:
-	  > Add foo3
+	  > Add foo3 ($added foo3)
 	EOF
 	test_cmp expected actual
 '
 
-test_expect_success 'modified submodule(forward) --submodule' '
+test_expect_failure 'modified submodule(forward) --submodule' '
 	git diff --submodule >actual &&
 	cat >expected <<-EOF &&
 	Submodule sm1 $head1..$head2:
-	  > Add foo3
+	  > Add foo3 ($added foo3)
 	EOF
 	test_cmp expected actual
 '
@@ -138,25 +143,25 @@ head3=$(
 	git rev-parse --short --verify HEAD
 )
 
-test_expect_success 'modified submodule(backward)' '
+test_expect_failure 'modified submodule(backward)' '
 	git diff-index -p --submodule=log HEAD >actual &&
 	cat >expected <<-EOF &&
 	Submodule sm1 $head2..$head3 (rewind):
-	  < Add foo3
-	  < Add foo2
+	  < Add foo3 ($added foo3)
+	  < Add foo2 ($added foo2)
 	EOF
 	test_cmp expected actual
 '
 
 head4=$(add_file sm1 foo4 foo5)
-test_expect_success 'modified submodule(backward and forward)' '
+test_expect_failure 'modified submodule(backward and forward)' '
 	git diff-index -p --submodule=log HEAD >actual &&
 	cat >expected <<-EOF &&
 	Submodule sm1 $head2...$head4:
-	  > Add foo5
-	  > Add foo4
-	  < Add foo3
-	  < Add foo2
+	  > Add foo5 ($added foo5)
+	  > Add foo4 ($added foo4)
+	  < Add foo3 ($added foo3)
+	  < Add foo2 ($added foo2)
 	EOF
 	test_cmp expected actual
 '
t/t4205-log-pretty-formats.sh +93 -56

319 lines not on this page · raw message

t/t6006-rev-list-format.sh +59 -24

173 lines not on this page · raw message

t/t7102-reset.sh +27 -2
index 05dfb27..72e364e 100755
@@ -9,6 +9,17 @@ Documented tests for git reset'
 
 . ./test-lib.sh
 
+commit_msg() {
+	# String "modify 2nd file (changed)" partly in German(translated with Google Translate),
+	# encoded in UTF-8, used as a commit log message below.
+	msg=$(printf "modify 2nd file (ge\303\244ndert)")
+	if test -n "$1"
+	then
+		msg=$(echo $msg | iconv -f utf-8 -t $1)
+	fi
+	echo $msg
+}
+
 test_expect_success 'creating initial files and commits' '
 	test_tick &&
 	echo "1st file" >first &&
@@ -28,7 +39,7 @@ test_expect_success 'creating initial files and commits' '
 
 	echo "1st line 2nd file" >secondfile &&
 	echo "2nd line 2nd file" >>secondfile &&
-	git commit -a -m "modify 2nd file" &&
+	git -c "i18n.commitEncoding=iso-8859-1" commit -a -m "$(commit_msg iso-8859-1)" &&
 	head5=$(git rev-parse --verify HEAD)
 '
 # git log --pretty=oneline # to see those SHA1 involved
@@ -44,6 +55,20 @@ check_changes () {
 	done | test_cmp .cat_expect -
 }
 
+test_expect_failure 'reset --hard message' '
+	hex=$(git log -1 --format="%h") &&
+	git reset --hard > .actual &&
+	echo HEAD is now at $hex $(commit_msg) > .expected &&
+	test_cmp .expected .actual
+'
+
+test_expect_success 'reset --hard message (iso-8859-1 logoutencoding)' '
+	hex=$(git log -1 --format="%h") &&
+	git -c "i18n.logOutputEncoding=iso-8859-1" reset --hard > .actual &&
+	echo HEAD is now at $hex $(commit_msg iso-8859-1) > .expected &&
+	test_cmp .expected .actual
+'
+
 >.diff_expect
 >.cached_expect
 cat >.cat_expect <<EOF
@@ -304,7 +329,7 @@ test_expect_success 'redoing the last two commits should succeed' '
 
 	echo "1st line 2nd file" >secondfile &&
 	echo "2nd line 2nd file" >>secondfile &&
-	git commit -a -m "modify 2nd file" &&
+	git -c "i18n.commitEncoding=iso-8859-1" commit -a -m "$(commit_msg iso-8859-1)" &&
 	check_changes $head5
 '
 
Signature · 1 line
1.8.3.1.15.g5c23c1e
#59 lore raw

Re: [PATCH v7 4/5] pretty: Add failing tests: --format output should honor logOutputEncoding

Am 6/26/2013 12:19, schrieb Alexey Shumkin:

Quoted 36 lines

One can set an alias

	$ git config alias.lg "log --graph --pretty=format:'%Cred%h%Creset
	-%C(yellow)%d%Creset %s %Cgreen(%cd) %C(bold blue)<%an>%Creset'
	--abbrev-commit --date=local"

to see the log as a pretty tree (like *gitk* but in a terminal).

However, log messages written in an encoding i18n.commitEncoding which differs from terminal encoding are shown corrupted even when i18n.logOutputEncoding and terminal encoding are the same (e.g. log messages committed on a Cygwin box with Windows-1251 encoding seen on a Linux box with a UTF-8 encoding and vice versa).

To simplify an example we can say the following two commands are expected to give the same output to a terminal:

	$ git log --oneline --no-color
	$ git log --pretty=format:'%h %s'

However, the former pays attention to i18n.logOutputEncoding configuration, while the latter does not when it formats "%s".

The same corruption is true for

	$ git diff --submodule=log
and
	$ git rev-list --pretty=format:%s HEAD
and
	$ git reset --hard

This patch adds failing tests for the next patch that fixes them.

t/t4205-log-pretty-formats.sh +0 -0
index 73ba5e8..6b62da2 100755

...

Quoted 6 lines
t/t4205-log-pretty-formats.sh +6 -0
+commit_msg() {
+	# String "initial. initial" partly in German (translated with Google Translate),
+	# encoded in UTF-8, used as a commit log message below.
+	msg=$(printf "initial. anf\303\244nglich")
+	if test -n "$1"
+	then

t/t4205-log-pretty-formats.sh line 25

Quoted 10 lines
t/t4205-log-pretty-formats.sh +10 -0
+		msg=$(echo $msg | iconv -f utf-8 -t $1)
+	fi
+	if test -n "$2" -a -n "$3"
+	then
+		# cut string, replace cut part with two dots
+		# $2 - chars count from the beginning of the string
+		# $3 - "trailing" chars
+		# LC_ALL is set to make `sed` interpret "." as a UTF-8 char not a byte
+		# as it does with C locale
+		msg=$(echo $msg | LC_ALL=en_US.UTF-8 sed -e "s/^\(.\{$2\}\)$3/\1../")

This does not work as expected on Windows because sed ignores the .UTF-8 part of the locale specifier. (We don't even have en_US; we have de, but with de.UTF-8 this doesn't work, either.)

I don't have an idea, yet, how to work it around.

Quoted 10 lines
t/t4205-log-pretty-formats.sh +5 -2
+	fi
+	echo $msg
+}
 
-test_expect_success 'left alignment formatting with mtrunc' '
-	git log --pretty="format:%<(10,mtrunc)%s" >actual &&
+test_expect_failure 'left alignment formatting with mtrunc' "
+	git log --pretty='format:%<(10,mtrunc)%s' >actual &&
 	# complete the incomplete line at the end
 	echo >>actual &&

t/t4205-log-pretty-formats.sh test_expect_success 'left alignment formatting at the nth column' " · line 224

Quoted 10 lines
t/t4205-log-pretty-formats.sh +2 -2
 	qz_to_tab_space <<\EOF >expected &&
 mess.. two
 mess.. one
 add bar  Z
-initial  Z
+$(commit_msg "" "4" ".\{11\}")
 EOF
 	test_cmp expected actual
-'
+"

This is the failing test case.

BTW, if you re-roll, there would be fewer changes needed if you kept the test code single-quoted, but changed <<\EOF to <<EOF where needed.

Quoted 4 lines
t/t6006-rev-list-format.sh +0 -0
index cc1008d..c66a07f 100755

...

t/t6006-rev-list-format.sh line 23

Quoted 5 lines

test_expect_success 'setup' '

t/t6006-rev-list-format.sh +1 -1
 	: >foo &&
 	git add foo &&
-	git commit -m "added foo" &&
+	git config i18n.commitEncoding iso-8859-1 &&

Perhaps

	test_config i18n.commitEncoding iso-8859-1 &&

Also, it is "iso-8869-1" here, but we see "iso8859-1" already used later. It's probably wise to use that same encoding name everywhere because we can be very sure that the latter is already understood on all supported platforms.

Quoted 32 lines
t/t6006-rev-list-format.sh +13 -7
+	git commit -m "$added_iso88591" &&
 	head1=$(git rev-parse --verify HEAD) &&
 	head1_short=$(git rev-parse --verify --short $head1) &&
 	tree1=$(git rev-parse --verify HEAD:) &&
 	tree1_short=$(git rev-parse --verify --short $tree1) &&
-	echo changed >foo &&
-	git commit -a -m "changed foo" &&
+	echo "$changed" > foo &&
+	git commit -a -m "$changed_iso88591" &&
 	head2=$(git rev-parse --verify HEAD) &&
 	head2_short=$(git rev-parse --verify --short $head2) &&
 	tree2=$(git rev-parse --verify HEAD:) &&
 	tree2_short=$(git rev-parse --verify --short $tree2)
+	git config --unset i18n.commitEncoding
 '
 
-# usage: test_format name format_string <expected_output
+# usage: test_format [failure] name format_string <expected_output
 test_format () {
+	must_fail=0
+	# if parameters count is more than 2 then test must fail
+	if test $# -gt 2
+	then
+		must_fail=1
+		# remove first parameter which is flag for test failure
+		shift
+	fi
 	cat >expect.$1
-	test_expect_success "format $1" "
-		git rev-list --pretty=format:'$2' master >output.$1 &&
-		test_cmp expect.$1 output.$1
-	"

t/t6006-rev-list-format.sh line 58

Quoted 10 lines
t/t6006-rev-list-format.sh +9 -0
+	name="format $1"
+	command="git rev-list --pretty=format:'$2' master >output.$1 &&
+		test_cmp expect.$1 output.$1"
+	if test $must_fail -eq 1
+	then
+		test_expect_failure "$name" "$command"
+	else
+		test_expect_success "$name" "$command"
+	fi
 }

This function would be much shorter with the optional "failure" token as $3 (untested):

test_format () {
	cat >expect.$1
	test_expect_${3:-success} "format $1" "
		git rev-list --pretty=format:'$2' master >output.$1 &&
		test_cmp expect.$1 output.$1
	"
}

t/t6006-rev-list-format.sh test_expect_success '%C(auto) respects --color=auto (stdout not tty)' ' · line 236

Quoted 9 lines

test_expect_success 'setup complex body' '

t/t6006-rev-list-format.sh +4 -1
 	git config i18n.commitencoding iso8859-1 &&
 	echo change2 >foo && git commit -a -F commit-msg &&
 	head3=$(git rev-parse --verify HEAD) &&
-	head3_short=$(git rev-parse --short $head3)
+	head3_short=$(git rev-parse --short $head3) &&
+	# unset commit encoding config
+	# otherwise %e does not print encoding value
+	# and following test fails

I don't understand this comment. The test vector below already shows that an encoding is printed. Why would this suddenly be different with the updated tests?

Assuming that this change doesn't sweep a deeper problem under the rug, it's better to use test_config a few lines earlier.

t/t6006-rev-list-format.sh test_expect_success '%C(auto) respects --color=auto (stdout not tty)' ' · line 243

Quoted 7 lines
t/t6006-rev-list-format.sh +2 -0
+	git config --unset i18n.commitEncoding
+
 '
 
 test_format complex-encoding %e <<EOF
 commit $head3
 iso8859-1

This is the encoding that I mean.

Quoted 14 lines

commit $head2

t/t6006-rev-list-format.sh +2 -0
+iso-8859-1
 commit $head1
+iso-8859-1
 EOF
t/t7102-reset.sh +0 -0
index 05dfb27..72e364e 100755
@@ -9,6 +9,17 @@ Documented tests for git reset'
 
 . ./test-lib.sh
 

t/t7102-reset.sh Documented tests for git reset' · line 21

Quoted 10 lines
t/t7102-reset.sh +10 -0
+commit_msg() {
+	# String "modify 2nd file (changed)" partly in German(translated with Google Translate),
+	# encoded in UTF-8, used as a commit log message below.
+	msg=$(printf "modify 2nd file (ge\303\244ndert)")
+	if test -n "$1"
+	then
+		msg=$(echo $msg | iconv -f utf-8 -t $1)
+	fi
+	echo $msg
+}

If you wanted to, you could write this as

commit_msg () {
	# String "modify 2nd file (changed)" partly in German
	#(translated with Google Translate),
	# encoded in UTF-8, used as a commit log message below.
	printf "modify 2nd file (ge\303\244ndert)" |
	if test -n "$1"
	then
		iconv -f utf-8 -t $1
	else
		cat
	fi
}

but I'm not sure whether it's a lot better.

-- Hannes

#60 lore raw

Re: [PATCH v7 4/5] pretty: Add failing tests: --format output should honor logOutputEncoding

Quoted 59 lines · Johannes Sixt

Am 6/26/2013 12:19, schrieb Alexey Shumkin:

Quoted 36 lines

One can set an alias

	$ git config alias.lg "log --graph --pretty=format:'%Cred%h%Creset
	-%C(yellow)%d%Creset %s %Cgreen(%cd) %C(bold blue)<%an>%Creset'
	--abbrev-commit --date=local"

to see the log as a pretty tree (like *gitk* but in a terminal).

However, log messages written in an encoding i18n.commitEncoding which differs from terminal encoding are shown corrupted even when i18n.logOutputEncoding and terminal encoding are the same (e.g. log messages committed on a Cygwin box with Windows-1251 encoding seen on a Linux box with a UTF-8 encoding and vice versa).

To simplify an example we can say the following two commands are expected to give the same output to a terminal:

	$ git log --oneline --no-color
	$ git log --pretty=format:'%h %s'

However, the former pays attention to i18n.logOutputEncoding configuration, while the latter does not when it formats "%s".

The same corruption is true for

	$ git diff --submodule=log
and
	$ git rev-list --pretty=format:%s HEAD
and
	$ git reset --hard

This patch adds failing tests for the next patch that fixes them.

t/t4205-log-pretty-formats.sh +0 -0
index 73ba5e8..6b62da2 100755

...

Quoted 6 lines
t/t4205-log-pretty-formats.sh +6 -0
+commit_msg() {
+	# String "initial. initial" partly in German (translated with Google Translate),
+	# encoded in UTF-8, used as a commit log message below.
+	msg=$(printf "initial. anf\303\244nglich")
+	if test -n "$1"
+	then

t/t4205-log-pretty-formats.sh line 25

Quoted 10 lines
t/t4205-log-pretty-formats.sh +10 -0
+		msg=$(echo $msg | iconv -f utf-8 -t $1)
+	fi
+	if test -n "$2" -a -n "$3"
+	then
+		# cut string, replace cut part with two dots
+		# $2 - chars count from the beginning of the string
+		# $3 - "trailing" chars
+		# LC_ALL is set to make `sed` interpret "." as a UTF-8 char not a byte
+		# as it does with C locale
+		msg=$(echo $msg | LC_ALL=en_US.UTF-8 sed -e "s/^\(.\{$2\}\)$3/\1../")

This does not work as expected on Windows because sed ignores the .UTF-8 part of the locale specifier. (We don't even have en_US; we have de, but with de.UTF-8 this doesn't work, either.)

Quoted 2 lines

I don't have an idea, yet, how to work it around.

Hmm. I have Cygwin v1.7 (on Windows 7 and Windows 2003 Server R2)
with many locales installed (and with en_US.UTF-8 locale, too)
Today I could not find a way to run tests with "no en_US.UTF-8 locale installed" simulation to test your failure

Quoted 14 lines
Quoted 14 lines
t/t4205-log-pretty-formats.sh +5 -2
+	fi
+	echo $msg
+}
 
-test_expect_success 'left alignment formatting with mtrunc' '
-	git log --pretty="format:%<(10,mtrunc)%s" >actual &&
+test_expect_failure 'left alignment formatting with mtrunc' "
+	git log --pretty='format:%<(10,mtrunc)%s' >actual &&
 	# complete the incomplete line at the end
 	echo >>actual &&
 	qz_to_tab_space <<\EOF >expected &&
 mess.. two
 mess.. one
 add bar  Z
Quoted 8 lines

t/t4205-log-pretty-formats.sh test_expect_success 'left alignment formatting at the nth column' " · line 224

Quoted 6 lines
t/t4205-log-pretty-formats.sh +2 -2
-initial  Z
+$(commit_msg "" "4" ".\{11\}")
 EOF
 	test_cmp expected actual
-'
+"

This is the failing test case.

Hmm, for me all these tests pass on both Linux and Cygwin (mentioned above) boxes

Quoted 3 lines

BTW, if you re-roll, there would be fewer changes needed if you kept the test code single-quoted, but changed <<\EOF to <<EOF where needed.

Yep, thanks for your correction

Quoted 13 lines
Quoted 5 lines
t/t6006-rev-list-format.sh +0 -0
index cc1008d..c66a07f 100755

...

t/t6006-rev-list-format.sh line 23

Quoted 5 lines

test_expect_success 'setup' '

t/t6006-rev-list-format.sh +1 -1
 	: >foo &&
 	git add foo &&
-	git commit -m "added foo" &&
+	git config i18n.commitEncoding iso-8859-1 &&

Perhaps

Quoted 6 lines
	test_config i18n.commitEncoding iso-8859-1 &&

Also, it is "iso-8869-1" here, but we see "iso8859-1" already used later. It's probably wise to use that same encoding name everywhere because we can be very sure that the latter is already understood on all supported platforms.

You're right (I've looked at explanation in 3994e8a98dc7bbf67e61d23c8125f44383499a1f; I've thought ISO-8859-1 is a common name).

Quoted 47 lines
Quoted 33 lines
t/t6006-rev-list-format.sh +13 -7
+	git commit -m "$added_iso88591" &&
 	head1=$(git rev-parse --verify HEAD) &&
 	head1_short=$(git rev-parse --verify --short $head1) &&
 	tree1=$(git rev-parse --verify HEAD:) &&
 	tree1_short=$(git rev-parse --verify --short $tree1) &&
-	echo changed >foo &&
-	git commit -a -m "changed foo" &&
+	echo "$changed" > foo &&
+	git commit -a -m "$changed_iso88591" &&
 	head2=$(git rev-parse --verify HEAD) &&
 	head2_short=$(git rev-parse --verify --short $head2) &&
 	tree2=$(git rev-parse --verify HEAD:) &&
 	tree2_short=$(git rev-parse --verify --short $tree2)
+	git config --unset i18n.commitEncoding
 '
 
-# usage: test_format name format_string <expected_output
+# usage: test_format [failure] name format_string <expected_output
 test_format () {
+	must_fail=0
+	# if parameters count is more than 2 then test must fail
+	if test $# -gt 2
+	then
+		must_fail=1
+		# remove first parameter which is flag for test failure
+		shift
+	fi
 	cat >expect.$1
-	test_expect_success "format $1" "
-		git rev-list --pretty=format:'$2' master >output.$1 &&
-		test_cmp expect.$1 output.$1
-	"

t/t6006-rev-list-format.sh line 58

Quoted 10 lines
t/t6006-rev-list-format.sh +9 -0
+	name="format $1"
+	command="git rev-list --pretty=format:'$2' master >output.$1 &&
+		test_cmp expect.$1 output.$1"
+	if test $must_fail -eq 1
+	then
+		test_expect_failure "$name" "$command"
+	else
+		test_expect_success "$name" "$command"
+	fi
 }

This function would be much shorter with the optional "failure" token as $3 (untested):

Quoted 6 lines
test_format () {
	cat >expect.$1
	test_expect_${3:-success} "format $1" "
		git rev-list --pretty=format:'$2' master >output.$1 &&
		test_cmp expect.$1 output.$1
	"

Thank you for your suggesstion

Quoted 15 lines

}

t/t6006-rev-list-format.sh test_expect_success '%C(auto) respects --color=auto (stdout not tty)' ' · line 236

Quoted 9 lines

test_expect_success 'setup complex body' '

t/t6006-rev-list-format.sh +4 -1
 	git config i18n.commitencoding iso8859-1 &&
 	echo change2 >foo && git commit -a -F commit-msg &&
 	head3=$(git rev-parse --verify HEAD) &&
-	head3_short=$(git rev-parse --short $head3)
+	head3_short=$(git rev-parse --short $head3) &&
+	# unset commit encoding config
+	# otherwise %e does not print encoding value
+	# and following test fails

I don't understand this comment. The test vector below already shows that an encoding is printed. Why would this suddenly be different with the updated tests?

I've changed tests. I've reverted back these ones, and added new ones with no i18n.commitEncoding set

Quoted 8 lines

Assuming that this change doesn't sweep a deeper problem under the rug, it's better to use test_config a few lines earlier.

Quoted 4 lines
t/t6006-rev-list-format.sh +2 -0
+	git config --unset i18n.commitEncoding
+
 '
Quoted 5 lines
Quoted 3 lines

test_format complex-encoding %e <<EOF
commit $head3
iso8859-1

This is the encoding that I mean.

These encodings "have appeared" because we've changed 'setup':
we make commits with i18n.commitEncoding set

Quoted 41 lines
Quoted 15 lines

commit $head2

t/t6006-rev-list-format.sh +2 -0
+iso-8859-1
 commit $head1
+iso-8859-1
 EOF
t/t7102-reset.sh +0 -0
index 05dfb27..72e364e 100755
@@ -9,6 +9,17 @@ Documented tests for git reset'
 
 . ./test-lib.sh
 

t/t7102-reset.sh Documented tests for git reset' · line 21

Quoted 10 lines
t/t7102-reset.sh +10 -0
+commit_msg() {
+	# String "modify 2nd file (changed)" partly in German(translated with Google Translate),
+	# encoded in UTF-8, used as a commit log message below.
+	msg=$(printf "modify 2nd file (ge\303\244ndert)")
+	if test -n "$1"
+	then
+		msg=$(echo $msg | iconv -f utf-8 -t $1)
+	fi
+	echo $msg
+}

If you wanted to, you could write this as

commit_msg () {
	# String "modify 2nd file (changed)" partly in German
	#(translated with Google Translate),
	# encoded in UTF-8, used as a commit log message below.
	printf "modify 2nd file (ge\303\244ndert)" |
	if test -n "$1"
	then
		iconv -f utf-8 -t $1
	else
		cat
	fi
}
Quoted 1 line

but I'm not sure whether it's a lot better.

It looks more readable. Thank you

Quoted 2 lines

-- Hannes

Signature · 1 line
Alexey Shumkin
#61 lore raw

Re: [PATCH v7 4/5] pretty: Add failing tests: --format output should honor logOutputEncoding

Am 7/2/2013 0:50, schrieb Alexey Shumkin:

Quoted 25 lines · Johannes Sixt
Quoted 14 lines

Am 6/26/2013 12:19, schrieb Alexey Shumkin:

t/t6006-rev-list-format.sh test_expect_success '%C(auto) respects --color=auto (stdout not tty)' ' · line 236

Quoted 9 lines

test_expect_success 'setup complex body' '

t/t6006-rev-list-format.sh +4 -1
 	git config i18n.commitencoding iso8859-1 &&
 	echo change2 >foo && git commit -a -F commit-msg &&
 	head3=$(git rev-parse --verify HEAD) &&
-	head3_short=$(git rev-parse --short $head3)
+	head3_short=$(git rev-parse --short $head3) &&
+	# unset commit encoding config
+	# otherwise %e does not print encoding value
+	# and following test fails

I don't understand this comment. The test vector below already shows that an encoding is printed. Why would this suddenly be different with the updated tests?

I've changed tests. I've reverted back these ones, and added new ones with no i18n.commitEncoding set

Quoted 8 lines

Assuming that this change doesn't sweep a deeper problem under the rug, it's better to use test_config a few lines earlier.

Quoted 4 lines
t/t6006-rev-list-format.sh +2 -0
+	git config --unset i18n.commitEncoding
+
 '
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

test_format complex-encoding %e <<EOF
commit $head3
iso8859-1

This is the encoding that I mean.

These encodings "have appeared" because we've changed 'setup':
we make commits with i18n.commitEncoding set

I understand why there are additional encoding entries in the expected output, but we see one encoding entry already listed without this patch. Why do you say "does not print encoding value" in the comment above?

Quoted 6 lines
Quoted 6 lines

t/t6006-rev-list-format.sh EOF · line 142

Quoted 6 lines

commit $head2

t/t6006-rev-list-format.sh +2 -0
+iso-8859-1
 commit $head1
+iso-8859-1
 EOF

-- Hannes

#62 lore raw

Re: [PATCH v7 4/5] pretty: Add failing tests: --format output should honor logOutputEncoding

Quoted 31 lines · Johannes Sixt

Am 7/2/2013 0:50, schrieb Alexey Shumkin:

Quoted 30 lines · Johannes Sixt
Quoted 14 lines

Am 6/26/2013 12:19, schrieb Alexey Shumkin:

t/t6006-rev-list-format.sh test_expect_success '%C(auto) respects --color=auto (stdout not tty)' ' · line 236

Quoted 9 lines

test_expect_success 'setup complex body' '

t/t6006-rev-list-format.sh +4 -1
 	git config i18n.commitencoding iso8859-1 &&
 	echo change2 >foo && git commit -a -F commit-msg &&
 	head3=$(git rev-parse --verify HEAD) &&
-	head3_short=$(git rev-parse --short $head3)
+	head3_short=$(git rev-parse --short $head3) &&
+	# unset commit encoding config
+	# otherwise %e does not print encoding value
+	# and following test fails

I don't understand this comment. The test vector below already shows that an encoding is printed. Why would this suddenly be different with the updated tests?

I've changed tests. I've reverted back these ones, and added new ones with no i18n.commitEncoding set

Quoted 13 lines

Assuming that this change doesn't sweep a deeper problem under the rug, it's better to use test_config a few lines earlier.

t/t6006-rev-list-format.sh test_expect_success '%C(auto) respects --color=auto (stdout not tty)' ' · line 243

Quoted 7 lines
t/t6006-rev-list-format.sh +2 -0
+	git config --unset i18n.commitEncoding
+
 '
 
 test_format complex-encoding %e <<EOF
 commit $head3
 iso8859-1

This is the encoding that I mean.

Quoted 6 lines
Quoted 2 lines

These encodings "have appeared" because we've changed 'setup':
we make commits with i18n.commitEncoding set

I understand why there are additional encoding entries in the expected output, but we see one encoding entry already listed without this patch. Why do you say "does not print encoding value" in the comment above?

I don't even remember today. I guess (that comment initially was written loooooong time time ago), that was a "legacy" comment. Nevermind,
nowadays it's removed ;)

Quoted 9 lines
Quoted 7 lines
Quoted 7 lines

t/t6006-rev-list-format.sh EOF · line 142

Quoted 7 lines

commit $head2

t/t6006-rev-list-format.sh +2 -0
+iso-8859-1
 commit $head1
+iso-8859-1
 EOF

-- Hannes

#63 lore raw

PATCH v7 5/5 pretty: --format output should honor logOutputEncoding

In reply to Alexey Shumkin

One can set an alias

	$ git config [--global] alias.lg "log --graph --pretty=format:'%Cred%h%Creset
	-%C(yellow)%d%Creset %s %Cgreen(%cd) %C(bold blue)<%an>%Creset'
	--abbrev-commit --date=local"

to see the log as a pretty tree (like *gitk* but in a terminal).

However, log messages written in an encoding i18n.commitEncoding which differs from terminal encoding are shown corrupted even when i18n.logOutputEncoding and terminal encoding are the same (e.g. log messages committed on a Cygwin box with Windows-1251 encoding seen on a Linux box with a UTF-8 encoding and vice versa).

To simplify an example we can say the following two commands are expected to give the same output to a terminal:

	$ git log --oneline --no-color
	$ git log --pretty=format:'%h %s'

However, the former pays attention to i18n.logOutputEncoding configuration, while the latter does not when it formats "%s".

The same corruption is true for

	$ git diff --submodule=log
and
	$ git rev-list --pretty=format:%s HEAD
and
	$ git reset --hard

This patch makes pretty --format honor logOutputEncoding when it formats log message.

---
 builtin/reset.c                  |  5 ++++-
 builtin/rev-list.c               |  1 +
 builtin/shortlog.c               |  1 +
 log-tree.c                       |  1 +
 submodule.c                      |  1 +
 t/t4041-diff-submodule-option.sh | 10 +++++-----
 t/t4205-log-pretty-formats.sh    | 34 +++++++++++++++++-----------------
 t/t6006-rev-list-format.sh       |  8 ++++----
 t/t7102-reset.sh                 |  2 +-
 9 files changed, 35 insertions(+), 28 deletions(-)
builtin/reset.c +4 -1
index 6032131..afa6e02 100644
@@ -93,10 +93,12 @@ static int reset_index(const unsigned char *sha1, int reset_type, int quiet)
 static void print_new_head_line(struct commit *commit)
 {
 	const char *hex, *body;
+	char *msg;
 
 	hex = find_unique_abbrev(commit->object.sha1, DEFAULT_ABBREV);
 	printf(_("HEAD is now at %s"), hex);
-	body = strstr(commit->buffer, "\n\n");
+	msg = logmsg_reencode(commit, NULL, get_log_output_encoding());
+	body = strstr(msg, "\n\n");
 	if (body) {
 		const char *eol;
 		size_t len;
@@ -107,6 +109,7 @@ static void print_new_head_line(struct commit *commit)
 	}
 	else
 		printf("\n");
+	logmsg_free(msg, commit);
 }
 
 static void update_index_from_diff(struct diff_queue_struct *q,
builtin/rev-list.c +1 -0
index 67701be..a5ec30d 100644
@@ -111,6 +111,7 @@ static void show_commit(struct commit *commit, void *data)
 		ctx.date_mode = revs->date_mode;
 		ctx.date_mode_explicit = revs->date_mode_explicit;
 		ctx.fmt = revs->commit_format;
+		ctx.output_encoding = get_log_output_encoding();
 		pretty_print_commit(&ctx, commit, &buf);
 		if (revs->graph) {
 			if (buf.len) {
builtin/shortlog.c +1 -0
index 1fd6f8a..1434f8f 100644
@@ -137,6 +137,7 @@ void shortlog_add_commit(struct shortlog *log, struct commit *commit)
 		ctx.subject = "";
 		ctx.after_subject = "";
 		ctx.date_mode = DATE_NORMAL;
+		ctx.output_encoding = get_log_output_encoding();
 		pretty_print_commit(&ctx, commit, &ufbuf);
 		buffer = ufbuf.buf;
 	} else if (*buffer) {
log-tree.c +1 -0
index 1946e9c..5277d3e 100644
@@ -616,6 +616,7 @@ void show_log(struct rev_info *opt)
 	ctx.fmt = opt->commit_format;
 	ctx.mailmap = opt->mailmap;
 	ctx.color = opt->diffopt.use_color;
+	ctx.output_encoding = get_log_output_encoding();
 	pretty_print_commit(&ctx, commit, &msgbuf);
 
 	if (opt->add_signoff)
submodule.c +1 -0
index 1821a5b..78734e1 100644
@@ -226,6 +226,7 @@ static void print_submodule_summary(struct rev_info *rev, FILE *f,
 	while ((commit = get_revision(rev))) {
 		struct pretty_print_context ctx = {0};
 		ctx.date_mode = rev->date_mode;
+		ctx.output_encoding = get_log_output_encoding();
 		strbuf_setlen(&sb, 0);
 		strbuf_addstr(&sb, line_prefix);
 		if (commit->object.flags & SYMMETRIC_LEFT) {
t/t4041-diff-submodule-option.sh +5 -5
index 2a7877d..0a4f496 100755
@@ -94,7 +94,7 @@ test_expect_success 'diff.submodule does not affect plumbing' '
 commit_file sm1 &&
 head2=$(add_file sm1 foo3)
 
-test_expect_failure 'modified submodule(forward)' '
+test_expect_success 'modified submodule(forward)' '
 	git diff-index -p --submodule=log HEAD >actual &&
 	cat >expected <<-EOF &&
 	Submodule sm1 $head1..$head2:
@@ -103,7 +103,7 @@ test_expect_failure 'modified submodule(forward)' '
 	test_cmp expected actual
 '
 
-test_expect_failure 'modified submodule(forward)' '
+test_expect_success 'modified submodule(forward)' '
 	git diff --submodule=log >actual &&
 	cat >expected <<-EOF &&
 	Submodule sm1 $head1..$head2:
@@ -112,7 +112,7 @@ test_expect_failure 'modified submodule(forward)' '
 	test_cmp expected actual
 '
 
-test_expect_failure 'modified submodule(forward) --submodule' '
+test_expect_success 'modified submodule(forward) --submodule' '
 	git diff --submodule >actual &&
 	cat >expected <<-EOF &&
 	Submodule sm1 $head1..$head2:
@@ -143,7 +143,7 @@ head3=$(
 	git rev-parse --short --verify HEAD
 )
 
-test_expect_failure 'modified submodule(backward)' '
+test_expect_success 'modified submodule(backward)' '
 	git diff-index -p --submodule=log HEAD >actual &&
 	cat >expected <<-EOF &&
 	Submodule sm1 $head2..$head3 (rewind):
@@ -154,7 +154,7 @@ test_expect_failure 'modified submodule(backward)' '
 '
 
 head4=$(add_file sm1 foo4 foo5)
-test_expect_failure 'modified submodule(backward and forward)' '
+test_expect_success 'modified submodule(backward and forward)' '
 	git diff-index -p --submodule=log HEAD >actual &&
 	cat >expected <<-EOF &&
 	Submodule sm1 $head2...$head4:
t/t4205-log-pretty-formats.sh +17 -17
index 6b62da2..2fc9674 100755
@@ -69,7 +69,7 @@ test_expect_success 'alias user-defined tformat with %s (iso-8859-1 encoding)' '
 	test_cmp expected-s actual-s
 '
 
-test_expect_failure 'alias user-defined tformat with %s (utf-8 encoding)' '
+test_expect_success 'alias user-defined tformat with %s (utf-8 encoding)' '
 	git log --oneline >expected-s &&
 	git log --pretty="tformat:%h %s" >actual-s &&
 	test_cmp expected-s actual-s
@@ -108,19 +108,19 @@ test_expect_success 'alias loop' '
 	test_must_fail git log --pretty=test-foo
 '
 
-test_expect_failure 'NUL separation' '
+test_expect_success 'NUL separation' '
 	printf "add bar\0$(commit_msg)" >expected &&
 	git log -z --pretty="format:%s" >actual &&
 	test_cmp expected actual
 '
 
-test_expect_failure 'NUL termination' '
+test_expect_success 'NUL termination' '
 	printf "add bar\0$(commit_msg)\0" >expected &&
 	git log -z --pretty="tformat:%s" >actual &&
 	test_cmp expected actual
 '
 
-test_expect_failure 'NUL separation with --stat' '
+test_expect_success 'NUL separation with --stat' '
 	stat0_part=$(git diff --stat HEAD^ HEAD) &&
 	stat1_part=$(git diff-tree --no-commit-id --stat --root HEAD^) &&
 	printf "add bar\n$stat0_part\n\0$(commit_msg)\n$stat1_part\n" >expected &&
@@ -145,7 +145,7 @@ test_expect_success 'setup more commits' '
 	head4=$(git rev-parse --verify --short HEAD~3)
 '
 
-test_expect_failure 'left alignment formatting' "
+test_expect_success 'left alignment formatting' "
 	git log --pretty='format:%<(40)%s' >actual &&
 	# complete the incomplete line at the end
 	echo >>actual &&
@@ -158,7 +158,7 @@ EOF
 	test_cmp expected actual
 "
 
-test_expect_failure 'left alignment formatting at the nth column' "
+test_expect_success 'left alignment formatting at the nth column' "
 	git log --pretty='format:%h %<|(40)%s' >actual &&
 	# complete the incomplete line at the end
 	echo >>actual &&
@@ -171,7 +171,7 @@ EOF
 	test_cmp expected actual
 "
 
-test_expect_failure 'left alignment formatting with no padding' "
+test_expect_success 'left alignment formatting with no padding' "
 	git log --pretty='format:%<(1)%s' >actual &&
 	# complete the incomplete line at the end
 	echo >>actual &&
@@ -184,7 +184,7 @@ EOF
 	test_cmp expected actual
 "
 
-test_expect_failure 'left alignment formatting with trunc' "
+test_expect_success 'left alignment formatting with trunc' "
 	git log --pretty='format:%<(10,trunc)%s' >actual &&
 	# complete the incomplete line at the end
 	echo >>actual &&
@@ -197,7 +197,7 @@ EOF
 	test_cmp expected actual
 "
 
-test_expect_failure 'left alignment formatting with ltrunc' "
+test_expect_success 'left alignment formatting with ltrunc' "
 	git log --pretty='format:%<(10,ltrunc)%s' >actual &&
 	# complete the incomplete line at the end
 	echo >>actual &&
@@ -210,7 +210,7 @@ EOF
 	test_cmp expected actual
 "
 
-test_expect_failure 'left alignment formatting with mtrunc' "
+test_expect_success 'left alignment formatting with mtrunc' "
 	git log --pretty='format:%<(10,mtrunc)%s' >actual &&
 	# complete the incomplete line at the end
 	echo >>actual &&
@@ -223,7 +223,7 @@ EOF
 	test_cmp expected actual
 "
 
-test_expect_failure 'right alignment formatting' "
+test_expect_success 'right alignment formatting' "
 	git log --pretty='format:%>(40)%s' >actual &&
 	# complete the incomplete line at the end
 	echo >>actual &&
@@ -236,7 +236,7 @@ EOF
 	test_cmp expected actual
 "
 
-test_expect_failure 'right alignment formatting at the nth column' "
+test_expect_success 'right alignment formatting at the nth column' "
 	git log --pretty='format:%h %>|(40)%s' >actual &&
 	# complete the incomplete line at the end
 	echo >>actual &&
@@ -249,7 +249,7 @@ EOF
 	test_cmp expected actual
 "
 
-test_expect_failure 'right alignment formatting with no padding' "
+test_expect_success 'right alignment formatting with no padding' "
 	git log --pretty='format:%>(1)%s' >actual &&
 	# complete the incomplete line at the end
 	echo >>actual &&
@@ -262,7 +262,7 @@ EOF
 	test_cmp expected actual
 "
 
-test_expect_failure 'center alignment formatting' "
+test_expect_success 'center alignment formatting' "
 	git log --pretty='format:%><(40)%s' >actual &&
 	# complete the incomplete line at the end
 	echo >>actual &&
@@ -275,7 +275,7 @@ EOF
 	test_cmp expected actual
 "
 
-test_expect_failure 'center alignment formatting at the nth column' "
+test_expect_success 'center alignment formatting at the nth column' "
 	git log --pretty='format:%h %><|(40)%s' >actual &&
 	# complete the incomplete line at the end
 	echo >>actual &&
@@ -288,7 +288,7 @@ EOF
 	test_cmp expected actual
 "
 
-test_expect_failure 'center alignment formatting with no padding' "
+test_expect_success 'center alignment formatting with no padding' "
 	git log --pretty='format:%><(1)%s' >actual &&
 	# complete the incomplete line at the end
 	echo >>actual &&
@@ -301,7 +301,7 @@ EOF
 	test_cmp expected actual
 "
 
-test_expect_failure 'left/right alignment formatting with stealing' "
+test_expect_success 'left/right alignment formatting with stealing' "
 	git commit --amend -m short --author 'long long long <[email protected]>' &&
 	git log --pretty='format:%<(10,trunc)%s%>>(10,ltrunc)% an' >actual &&
 	# complete the incomplete line at the end
t/t6006-rev-list-format.sh +4 -4
index c66a07f..380c85b 100755
@@ -141,7 +141,7 @@ commit $head1
 iso-8859-1
 EOF
 
-test_format failure subject %s <<EOF
+test_format subject %s <<EOF
 commit $head2
 $changed
 commit $head1
@@ -153,7 +153,7 @@ commit $head2
 commit $head1
 EOF
 
-test_format failure raw-body %B <<EOF
+test_format raw-body %B <<EOF
 commit $head2
 $changed
 
@@ -247,7 +247,7 @@ commit $head1
 iso-8859-1
 EOF
 
-test_format failure complex-subject %s <<EOF
+test_format complex-subject %s <<EOF
 commit $head3
 Test printing of complex bodies
 commit $head2
@@ -256,7 +256,7 @@ commit $head1
 $added
 EOF
 
-test_format failure complex-body %b <<EOF
+test_format complex-body %b <<EOF
 commit $head3
 This commit message is much longer than the others,
 and it will be encoded in iso8859-1. We should therefore
t/t7102-reset.sh +1 -1
index 72e364e..27b1e93 100755
@@ -55,7 +55,7 @@ check_changes () {
 	done | test_cmp .cat_expect -
 }
 
-test_expect_failure 'reset --hard message' '
+test_expect_success 'reset --hard message' '
 	hex=$(git log -1 --format="%h") &&
 	git reset --hard > .actual &&
 	echo HEAD is now at $hex $(commit_msg) > .expected &&
Signature · 1 line
1.8.3.1.15.g5c23c1e
#64 lore raw

v8 cover Reroll patches against Git v1.8.3.2

In reply to Alexey Shumkin

v8 of this patch series includes the following changes against v7:
1. [PATCH v8 1/5] t6006 (rev-list-format): don't hardcode SHA-1 in expected outputs untouched
2. [PATCH v8 2/5] t7102 (reset): don't hardcode SHA-1 in expected outputs untouched
3. [PATCH v8 3/5] t4205 (log-pretty-formats): don't hardcode SHA-1 in expected outputs untouched
4. [PATCH v8 4/5] pretty: Add failing tests: --format output should honor logOutputEncoding Includes suggestions of Johannes Sixt:
iso-8859-1 encoding replaced with its more "ancient" synonym "iso8859-1" already used in tests t/t6006-rev-list-format.sh:
test_format function become simplier and more readable
complex body & complex subject tests are reverted back (to its "initial" state) 2 tests added to test encoding conversions with i18n.commitEncoding unset
t/t7102-reset.sh:
commit_msg function become more readable

5. [PATCH v8 5/5] pretty: --format output should honor logOutputEncoding untouched

P.S.
It's all started here [http://thread.gmane.org/gmane.comp.version-control.git/177634]

Alexey Shumkin (5):
t6006 (rev-list-format): don't hardcode SHA-1 in expected outputs t7102 (reset): don't hardcode SHA-1 in expected outputs t4205 (log-pretty-formats): don't hardcode SHA-1 in expected outputs
pretty: Add failing tests: --format output should honor
logOutputEncoding
pretty: --format output should honor logOutputEncoding

 builtin/reset.c                  |   5 +-
 builtin/rev-list.c               |   1 +
 builtin/shortlog.c               |   1 +
 log-tree.c                       |   1 +
 submodule.c                      |   1 +
 t/t4041-diff-submodule-option.sh |  25 +++--
 t/t4205-log-pretty-formats.sh    | 126 ++++++++++++++++--------
 t/t6006-rev-list-format.sh       | 204 +++++++++++++++++++++++++--------------
 t/t7102-reset.sh                 |  39 +++++++-
 9 files changed, 270 insertions(+), 133 deletions(-)
Signature · 1 line
1.8.3.1.16.gce2c52e
#65 lore raw

PATCH v8 1/5 t6006 (rev-list-format): don't hardcode SHA-1 in expected outputs

The expected SHA-1 digests are always available in variables. Use them instead of hardcoding.

---
 t/t6006-rev-list-format.sh | 140 +++++++++++++++++++++++++--------------------
 1 file changed, 77 insertions(+), 63 deletions(-)
t/t6006-rev-list-format.sh +77 -63
index 0393c9f..cc1008d 100755
@@ -7,8 +7,19 @@ test_description='git rev-list --pretty=format test'
 
 test_tick
 test_expect_success 'setup' '
-touch foo && git add foo && git commit -m "added foo" &&
-  echo changed >foo && git commit -a -m "changed foo"
+	: >foo &&
+	git add foo &&
+	git commit -m "added foo" &&
+	head1=$(git rev-parse --verify HEAD) &&
+	head1_short=$(git rev-parse --verify --short $head1) &&
+	tree1=$(git rev-parse --verify HEAD:) &&
+	tree1_short=$(git rev-parse --verify --short $tree1) &&
+	echo changed >foo &&
+	git commit -a -m "changed foo" &&
+	head2=$(git rev-parse --verify HEAD) &&
+	head2_short=$(git rev-parse --verify --short $head2) &&
+	tree2=$(git rev-parse --verify HEAD:) &&
+	tree2_short=$(git rev-parse --verify --short $tree2)
 '
 
 # usage: test_format name format_string <expected_output
@@ -32,49 +43,49 @@ has_no_color () {
 	test_cmp expect "$1"
 }
 
-test_format percent %%h <<'EOF'
-commit 131a310eb913d107dd3c09a65d1651175898735d
+test_format percent %%h <<EOF
+commit $head2
 %h
-commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
+commit $head1
 %h
 EOF
 
-test_format hash %H%n%h <<'EOF'
-commit 131a310eb913d107dd3c09a65d1651175898735d
-131a310eb913d107dd3c09a65d1651175898735d
-131a310
-commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
-86c75cfd708a0e5868dc876ed5b8bb66c80b4873
-86c75cf
+test_format hash %H%n%h <<EOF
+commit $head2
+$head2
+$head2_short
+commit $head1
+$head1
+$head1_short
 EOF
 
-test_format tree %T%n%t <<'EOF'
-commit 131a310eb913d107dd3c09a65d1651175898735d
-fe722612f26da5064c32ca3843aa154bdb0b08a0
-fe72261
-commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
-4d5fcadc293a348e88f777dc0920f11e7d71441c
-4d5fcad
+test_format tree %T%n%t <<EOF
+commit $head2
+$tree2
+$tree2_short
+commit $head1
+$tree1
+$tree1_short
 EOF
 
-test_format parents %P%n%p <<'EOF'
-commit 131a310eb913d107dd3c09a65d1651175898735d
-86c75cfd708a0e5868dc876ed5b8bb66c80b4873
-86c75cf
-commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
+test_format parents %P%n%p <<EOF
+commit $head2
+$head1
+$head1_short
+commit $head1
 
 
 EOF
 
 # we don't test relative here
-test_format author %an%n%ae%n%ad%n%aD%n%at <<'EOF'
-commit 131a310eb913d107dd3c09a65d1651175898735d
+test_format author %an%n%ae%n%ad%n%aD%n%at <<EOF
+commit $head2
 A U Thor
 [email protected]
 Thu Apr 7 15:13:13 2005 -0700
 Thu, 7 Apr 2005 15:13:13 -0700
 1112911993
-commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
+commit $head1
 A U Thor
 [email protected]
 Thu Apr 7 15:13:13 2005 -0700
@@ -82,14 +93,14 @@ Thu, 7 Apr 2005 15:13:13 -0700
 1112911993
 EOF
 
-test_format committer %cn%n%ce%n%cd%n%cD%n%ct <<'EOF'
-commit 131a310eb913d107dd3c09a65d1651175898735d
+test_format committer %cn%n%ce%n%cd%n%cD%n%ct <<EOF
+commit $head2
 C O Mitter
 [email protected]
 Thu Apr 7 15:13:13 2005 -0700
 Thu, 7 Apr 2005 15:13:13 -0700
 1112911993
-commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
+commit $head1
 C O Mitter
 [email protected]
 Thu Apr 7 15:13:13 2005 -0700
@@ -97,43 +108,43 @@ Thu, 7 Apr 2005 15:13:13 -0700
 1112911993
 EOF
 
-test_format encoding %e <<'EOF'
-commit 131a310eb913d107dd3c09a65d1651175898735d
-commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
+test_format encoding %e <<EOF
+commit $head2
+commit $head1
 EOF
 
-test_format subject %s <<'EOF'
-commit 131a310eb913d107dd3c09a65d1651175898735d
+test_format subject %s <<EOF
+commit $head2
 changed foo
-commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
+commit $head1
 added foo
 EOF
 
-test_format body %b <<'EOF'
-commit 131a310eb913d107dd3c09a65d1651175898735d
-commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
+test_format body %b <<EOF
+commit $head2
+commit $head1
 EOF
 
-test_format raw-body %B <<'EOF'
-commit 131a310eb913d107dd3c09a65d1651175898735d
+test_format raw-body %B <<EOF
+commit $head2
 changed foo
 
-commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
+commit $head1
 added foo
 
 EOF
 
-test_format colors %Credfoo%Cgreenbar%Cbluebaz%Cresetxyzzy <<'EOF'
-commit 131a310eb913d107dd3c09a65d1651175898735d
+test_format colors %Credfoo%Cgreenbar%Cbluebaz%Cresetxyzzy <<EOF
+commit $head2
 foobarbazxyzzy
-commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
+commit $head1
 foobarbazxyzzy
 EOF
 
-test_format advanced-colors '%C(red yellow bold)foo%C(reset)' <<'EOF'
-commit 131a310eb913d107dd3c09a65d1651175898735d
+test_format advanced-colors '%C(red yellow bold)foo%C(reset)' <<EOF
+commit $head2
 foo
-commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
+commit $head1
 foo
 EOF
 
@@ -186,39 +197,42 @@ This commit message is much longer than the others,
 and it will be encoded in iso8859-1. We should therefore
 include an iso8859 character: �bueno!
 EOF
+
 test_expect_success 'setup complex body' '
-git config i18n.commitencoding iso8859-1 &&
-  echo change2 >foo && git commit -a -F commit-msg
+	git config i18n.commitencoding iso8859-1 &&
+	echo change2 >foo && git commit -a -F commit-msg &&
+	head3=$(git rev-parse --verify HEAD) &&
+	head3_short=$(git rev-parse --short $head3)
 '
 
-test_format complex-encoding %e <<'EOF'
-commit 1ed88da4a5b5ed8c449114ac131efc62178734c3
+test_format complex-encoding %e <<EOF
+commit $head3
 iso8859-1
-commit 131a310eb913d107dd3c09a65d1651175898735d
-commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
+commit $head2
+commit $head1
 EOF
 
-test_format complex-subject %s <<'EOF'
-commit 1ed88da4a5b5ed8c449114ac131efc62178734c3
+test_format complex-subject %s <<EOF
+commit $head3
 Test printing of complex bodies
-commit 131a310eb913d107dd3c09a65d1651175898735d
+commit $head2
 changed foo
-commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
+commit $head1
 added foo
 EOF
 
-test_format complex-body %b <<'EOF'
-commit 1ed88da4a5b5ed8c449114ac131efc62178734c3
+test_format complex-body %b <<EOF
+commit $head3
 This commit message is much longer than the others,
 and it will be encoded in iso8859-1. We should therefore
 include an iso8859 character: �bueno!
 
-commit 131a310eb913d107dd3c09a65d1651175898735d
-commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
+commit $head2
+commit $head1
 EOF
 
 test_expect_success '%x00 shows NUL' '
-	echo  >expect commit 1ed88da4a5b5ed8c449114ac131efc62178734c3 &&
+	echo  >expect commit $head3 &&
 	echo >>expect fooQbar &&
 	git rev-list -1 --format=foo%x00bar HEAD >actual.nul &&
 	nul_to_q <actual.nul >actual &&
Signature · 1 line
1.8.3.1.16.gce2c52e
#66 lore raw

PATCH v8 2/5 t7102 (reset): don't hardcode SHA-1 in expected outputs

In reply to Alexey Shumkin

The expected SHA-1 digests are always available in variables. Use them instead of hardcoding.

---
 t/t7102-reset.sh | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
t/t7102-reset.sh +5 -3
index df82ec9..05dfb27 100755
@@ -192,7 +192,8 @@ test_expect_success \
 	'changing files and redo the last commit should succeed' '
 	echo "3rd line 2nd file" >>secondfile &&
 	git commit -a -C ORIG_HEAD &&
-	check_changes 3d3b7be011a58ca0c179ae45d94e6c83c0b0cd0d &&
+	head4=$(git rev-parse --verify HEAD) &&
+	check_changes $head4 &&
 	test "$(git rev-parse ORIG_HEAD)" = \
 			$head5
 '
@@ -211,7 +212,7 @@ test_expect_success \
 	git reset --hard HEAD~2 &&
 	check_changes ddaefe00f1da16864591c61fdc7adb5d7cd6b74e &&
 	test "$(git rev-parse ORIG_HEAD)" = \
-			3d3b7be011a58ca0c179ae45d94e6c83c0b0cd0d
+			$head4
 '
 
 >.diff_expect
@@ -326,10 +327,11 @@ test_expect_success '--hard reset to HEAD should clear a failed merge' '
 	git checkout branch2 &&
 	echo "3rd line in branch2" >>secondfile &&
 	git commit -a -m "change in branch2" &&
+	head3=$(git rev-parse --verify HEAD) &&
 
 	test_must_fail git pull . branch1 &&
 	git reset --hard &&
-	check_changes 77abb337073fb4369a7ad69ff6f5ec0e4d6b54bb
+	check_changes $head3
 '
 
 >.diff_expect
Signature · 1 line
1.8.3.1.16.gce2c52e
#67 lore raw

Re: [PATCH v8 0/5] Reroll patches against Git v1.8.3.2

In reply to Alexey Shumkin
Quoted 1 line · Alexey Shumkin

v8 of this patch series includes the following changes against v7:

Oops, isn't this already in 'next'? In that case, please feed incremental updates on top of the patches that are already queued as improvements and fixes.

Thanks.

#68 lore raw

Re: [PATCH v8 0/5] Reroll patches against Git v1.8.3.2

Quoted 7 lines · Junio C Hamano
Quoted 1 line · Alexey Shumkin

v8 of this patch series includes the following changes against v7:

Oops, isn't this already in 'next'? In that case, please feed incremental updates on top of the patches that are already queued as improvements and fixes.

Oops ;)
I'll send patches against 'next' then.

Quoted 2 lines

Thanks.

#69 lore raw

Re: [PATCH v8 0/5] Reroll patches against Git v1.8.3.2

Quoted 10 lines · Alexey Shumkin
Quoted 7 lines · Junio C Hamano
Quoted 1 line · Alexey Shumkin

v8 of this patch series includes the following changes against v7:

Oops, isn't this already in 'next'? In that case, please feed incremental updates on top of the patches that are already queued as improvements and fixes.

Oops ;)
I'll send patches against 'next' then.

Thanks; please build on top of 7c375214 (t4205: replace .\+ with ..* in sed commands, 2013-07-01).

#70 lore raw

PATCH v8 3/5 t4205 (log-pretty-formats): don't hardcode SHA-1 in expected outputs

In reply to Alexey Shumkin

The expected SHA-1 digests are always available in variables. Use them instead of hardcoding.

---
 t/t4205-log-pretty-formats.sh | 48 +++++++++++++++++++++++--------------------
 1 file changed, 26 insertions(+), 22 deletions(-)
t/t4205-log-pretty-formats.sh +26 -22
index 26fbfde..73ba5e8 100755
@@ -101,7 +101,11 @@ test_expect_failure 'NUL termination with --stat' '
 
 test_expect_success 'setup more commits' '
 	test_commit "message one" one one message-one &&
-	test_commit "message two" two two message-two
+	test_commit "message two" two two message-two &&
+	head1=$(git rev-parse --verify --short HEAD~0) &&
+	head2=$(git rev-parse --verify --short HEAD~1) &&
+	head3=$(git rev-parse --verify --short HEAD~2) &&
+	head4=$(git rev-parse --verify --short HEAD~3)
 '
 
 test_expect_success 'left alignment formatting' '
@@ -117,18 +121,18 @@ EOF
 	test_cmp expected actual
 '
 
-test_expect_success 'left alignment formatting at the nth column' '
-	git log --pretty="format:%h %<|(40)%s" >actual &&
+test_expect_success 'left alignment formatting at the nth column' "
+	git log --pretty='format:%h %<|(40)%s' >actual &&
 	# complete the incomplete line at the end
 	echo >>actual &&
 	qz_to_tab_space <<\EOF >expected &&
-fa33ab1 message two                    Z
-7cd6c63 message one                    Z
-1711bf9 add bar                        Z
-af20c06 initial                        Z
+$head1 message two                    Z
+$head2 message one                    Z
+$head3 add bar                        Z
+$head4 initial                        Z
 EOF
 	test_cmp expected actual
-'
+"
 
 test_expect_success 'left alignment formatting with no padding' '
 	git log --pretty="format:%<(1)%s" >actual &&
@@ -195,18 +199,18 @@ EOF
 	test_cmp expected actual
 '
 
-test_expect_success 'right alignment formatting at the nth column' '
-	git log --pretty="format:%h %>|(40)%s" >actual &&
+test_expect_success 'right alignment formatting at the nth column' "
+	git log --pretty='format:%h %>|(40)%s' >actual &&
 	# complete the incomplete line at the end
 	echo >>actual &&
 	qz_to_tab_space <<\EOF >expected &&
-fa33ab1                      message two
-7cd6c63                      message one
-1711bf9                          add bar
-af20c06                          initial
+$head1                      message two
+$head2                      message one
+$head3                          add bar
+$head4                          initial
 EOF
 	test_cmp expected actual
-'
+"
 
 test_expect_success 'right alignment formatting with no padding' '
 	git log --pretty="format:%>(1)%s" >actual &&
@@ -234,18 +238,18 @@ EOF
 	test_cmp expected actual
 '
 
-test_expect_success 'center alignment formatting at the nth column' '
-	git log --pretty="format:%h %><|(40)%s" >actual &&
+test_expect_success 'center alignment formatting at the nth column' "
+	git log --pretty='format:%h %><|(40)%s' >actual &&
 	# complete the incomplete line at the end
 	echo >>actual &&
 	qz_to_tab_space <<\EOF >expected &&
-fa33ab1           message two          Z
-7cd6c63           message one          Z
-1711bf9             add bar            Z
-af20c06             initial            Z
+$head1           message two          Z
+$head2           message one          Z
+$head3             add bar            Z
+$head4             initial            Z
 EOF
 	test_cmp expected actual
-'
+"
 
 test_expect_success 'center alignment formatting with no padding' '
 	git log --pretty="format:%><(1)%s" >actual &&
Signature · 1 line
1.8.3.1.16.gce2c52e
#71 lore raw

PATCH v8 4/5 pretty: Add failing tests: --format output should honor logOutputEncoding

In reply to Alexey Shumkin

One can set an alias

	$ git config alias.lg "log --graph --pretty=format:'%Cred%h%Creset
	-%C(yellow)%d%Creset %s %Cgreen(%cd) %C(bold blue)<%an>%Creset'
	--abbrev-commit --date=local"

to see the log as a pretty tree (like *gitk* but in a terminal).

However, log messages written in an encoding i18n.commitEncoding which differs from terminal encoding are shown corrupted even when i18n.logOutputEncoding and terminal encoding are the same (e.g. log messages committed on a Cygwin box with Windows-1251 encoding seen on a Linux box with a UTF-8 encoding and vice versa).

To simplify an example we can say the following two commands are expected to give the same output to a terminal:

	$ git log --oneline --no-color
	$ git log --pretty=format:'%h %s'

However, the former pays attention to i18n.logOutputEncoding configuration, while the latter does not when it formats "%s".

The same corruption is true for

	$ git diff --submodule=log
and
	$ git rev-list --pretty=format:%s HEAD
and
	$ git reset --hard

This patch adds failing tests for the next patch that fixes them.

---
 t/t4041-diff-submodule-option.sh |  35 ++++++----
 t/t4205-log-pretty-formats.sh    | 146 ++++++++++++++++++++++++---------------
 t/t6006-rev-list-format.sh       |  74 +++++++++++++++-----
 t/t7102-reset.sh                 |  31 ++++++++-
 4 files changed, 198 insertions(+), 88 deletions(-)
t/t4041-diff-submodule-option.sh +20 -15
index 32d4a60..d300d0c 100755
@@ -1,6 +1,7 @@
 #!/bin/sh
 #
 # Copyright (c) 2009 Jens Lehmann, based on t7401 by Ping Yin
+# Copyright (c) 2013 Alexey Shumkin (+ non-UTF-8 commit encoding tests)
 #
 
 test_description='Support for verbose submodule differences in git diff
@@ -10,6 +11,9 @@ This test tries to verify the sanity of the --submodule option of git diff.
 
 . ./test-lib.sh
 
+# String "added" in German (translated with Google Translate), encoded in UTF-8,
+# used in sample commit log messages in add_file() function below.
+added=$(printf "hinzugef\303\274gt")
 add_file () {
 	(
 		cd "$1" &&
@@ -19,7 +23,8 @@ add_file () {
 			echo "$name" >"$name" &&
 			git add "$name" &&
 			test_tick &&
-			git commit -m "Add $name" || exit
+			msg_added_iso88591=$(echo "Add $name ($added $name)" | iconv -f utf-8 -t iso8859-1) &&
+			git -c 'i18n.commitEncoding=iso8859-1' commit -m "$msg_added_iso88591"
 		done >/dev/null &&
 		git rev-parse --short --verify HEAD
 	)
@@ -89,29 +94,29 @@ test_expect_success 'diff.submodule does not affect plumbing' '
 commit_file sm1 &&
 head2=$(add_file sm1 foo3)
 
-test_expect_success 'modified submodule(forward)' '
+test_expect_failure 'modified submodule(forward)' '
 	git diff-index -p --submodule=log HEAD >actual &&
 	cat >expected <<-EOF &&
 	Submodule sm1 $head1..$head2:
-	  > Add foo3
+	  > Add foo3 ($added foo3)
 	EOF
 	test_cmp expected actual
 '
 
-test_expect_success 'modified submodule(forward)' '
+test_expect_failure 'modified submodule(forward)' '
 	git diff --submodule=log >actual &&
 	cat >expected <<-EOF &&
 	Submodule sm1 $head1..$head2:
-	  > Add foo3
+	  > Add foo3 ($added foo3)
 	EOF
 	test_cmp expected actual
 '
 
-test_expect_success 'modified submodule(forward) --submodule' '
+test_expect_failure 'modified submodule(forward) --submodule' '
 	git diff --submodule >actual &&
 	cat >expected <<-EOF &&
 	Submodule sm1 $head1..$head2:
-	  > Add foo3
+	  > Add foo3 ($added foo3)
 	EOF
 	test_cmp expected actual
 '
@@ -138,25 +143,25 @@ head3=$(
 	git rev-parse --short --verify HEAD
 )
 
-test_expect_success 'modified submodule(backward)' '
+test_expect_failure 'modified submodule(backward)' '
 	git diff-index -p --submodule=log HEAD >actual &&
 	cat >expected <<-EOF &&
 	Submodule sm1 $head2..$head3 (rewind):
-	  < Add foo3
-	  < Add foo2
+	  < Add foo3 ($added foo3)
+	  < Add foo2 ($added foo2)
 	EOF
 	test_cmp expected actual
 '
 
 head4=$(add_file sm1 foo4 foo5)
-test_expect_success 'modified submodule(backward and forward)' '
+test_expect_failure 'modified submodule(backward and forward)' '
 	git diff-index -p --submodule=log HEAD >actual &&
 	cat >expected <<-EOF &&
 	Submodule sm1 $head2...$head4:
-	  > Add foo5
-	  > Add foo4
-	  < Add foo3
-	  < Add foo2
+	  > Add foo5 ($added foo5)
+	  > Add foo4 ($added foo4)
+	  < Add foo3 ($added foo3)
+	  < Add foo2 ($added foo2)
 	EOF
 	test_cmp expected actual
 '
t/t4205-log-pretty-formats.sh +92 -54

319 lines not on this page · raw message

t/t6006-rev-list-format.sh +57 -17

160 lines not on this page · raw message

t/t7102-reset.sh +29 -2
index 05dfb27..6a92703 100755
@@ -9,6 +9,19 @@ Documented tests for git reset'
 
 . ./test-lib.sh
 
+commit_msg() {
+	# String "modify 2nd file (changed)" partly in German
+	# (translated with Google Translate),
+	# encoded in UTF-8, used as a commit log message below.
+	printf "modify 2nd file (ge\303\244ndert)" |
+	if test -n "$1"
+	then
+		iconv -f utf-8 -t $1
+	else
+		cat
+	fi
+}
+
 test_expect_success 'creating initial files and commits' '
 	test_tick &&
 	echo "1st file" >first &&
@@ -28,7 +41,7 @@ test_expect_success 'creating initial files and commits' '
 
 	echo "1st line 2nd file" >secondfile &&
 	echo "2nd line 2nd file" >>secondfile &&
-	git commit -a -m "modify 2nd file" &&
+	git -c "i18n.commitEncoding=iso8859-1" commit -a -m "$(commit_msg iso8859-1)" &&
 	head5=$(git rev-parse --verify HEAD)
 '
 # git log --pretty=oneline # to see those SHA1 involved
@@ -44,6 +57,20 @@ check_changes () {
 	done | test_cmp .cat_expect -
 }
 
+test_expect_failure 'reset --hard message' '
+	hex=$(git log -1 --format="%h") &&
+	git reset --hard > .actual &&
+	echo HEAD is now at $hex $(commit_msg) > .expected &&
+	test_cmp .expected .actual
+'
+
+test_expect_success 'reset --hard message (iso8859-1 logoutputencoding)' '
+	hex=$(git log -1 --format="%h") &&
+	git -c "i18n.logOutputEncoding=iso8859-1" reset --hard > .actual &&
+	echo HEAD is now at $hex $(commit_msg iso8859-1) > .expected &&
+	test_cmp .expected .actual
+'
+
 >.diff_expect
 >.cached_expect
 cat >.cat_expect <<EOF
@@ -304,7 +331,7 @@ test_expect_success 'redoing the last two commits should succeed' '
 
 	echo "1st line 2nd file" >secondfile &&
 	echo "2nd line 2nd file" >>secondfile &&
-	git commit -a -m "modify 2nd file" &&
+	git -c "i18n.commitEncoding=iso8859-1" commit -a -m "$(commit_msg iso8859-1)" &&
 	check_changes $head5
 '
 
Signature · 1 line
1.8.3.1.16.gce2c52e
#72 lore raw

Re: [PATCH v8 4/5] pretty: Add failing tests: --format output should honor logOutputEncoding

Am 7/2/2013 1:19, schrieb Alexey Shumkin:

Quoted 10 lines
(quoted diff) +10 -0
+commit_msg() {
+	# String "initial. initial" partly in German
+   # (translated with Google Translate),
+	# encoded in UTF-8, used as a commit log message below.
+	msg=$(printf "initial. anf\303\244nglich")
+	if test -n "$1"
+	then
+		msg=$(echo $msg | iconv -f utf-8 -t $1)
+	fi
+	if test -n "$2" -a -n "$3"

Review

Quoted 10 lines
(quoted diff) +10 -0
+	then
+		# cut string, replace cut part with two dots
+		# $2 - chars count from the beginning of the string
+		# $3 - "trailing" chars
+		# LC_ALL is set to make `sed` interpret "." as a UTF-8 char not a byte
+		# as it does with C locale
+		msg=$(echo $msg | LC_ALL=en_US.UTF-8 sed -e "s/^\(.\{$2\}\)$3/\1../")
+	fi
+	echo $msg
+}

Ignoring failure reports is not very helpful. Anyway, here is how I would adjust this patch. (There are trivial conflicts when 5/5 is applied on top.) Notice the comment I added in test case 'left alignment formatting with ltrunc'.

To be squashed into v8 4/5:

t/t4205-log-pretty-formats.sh +30 -42
index a23da67..ef3a226 100755
@@ -7,25 +7,13 @@
 test_description='Test pretty formats'
 . ./test-lib.sh
 
-commit_msg() {
-	# String "initial. initial" partly in German
-   # (translated with Google Translate),
-	# encoded in UTF-8, used as a commit log message below.
-	msg=$(printf "initial. anf\303\244nglich")
-	if test -n "$1"
-	then
-		msg=$(echo $msg | iconv -f utf-8 -t $1)
-	fi
-	if test -n "$2" -a -n "$3"
-	then
-		# cut string, replace cut part with two dots
-		# $2 - chars count from the beginning of the string
-		# $3 - "trailing" chars
-		# LC_ALL is set to make `sed` interpret "." as a UTF-8 char not a byte
-		# as it does with C locale
-		msg=$(echo $msg | LC_ALL=en_US.UTF-8 sed -e "s/^\(.\{$2\}\)$3/\1../")
-	fi
-	echo $msg
+# String "initial. initial" partly in German encoded in UTF-8
+initial_msg=$(printf "initial. anf\303\244nglich")
+
+# extract part of the initial commit message
+# $1 - a RE with \( \) brackets that specify which part to keep
+extract_msg() {
+	echo "$initial_msg" | sed -e "s/$1/\1/"
 }
 
 test_expect_success 'set up basic repos' '
@@ -33,12 +21,11 @@ test_expect_success 'set up basic repos' '
 	>bar &&
 	git add foo &&
 	test_tick &&
-	git config i18n.commitEncoding iso8859-1 &&
-	git commit -m "$(commit_msg iso8859-1)" &&
+	test_config i18n.commitEncoding iso8859-1 &&
+	git commit -m "$(echo "$initial_msg" | iconv -f utf-8 -t iso8859-1)" &&
 	git add bar &&
 	test_tick &&
-	git commit -m "add bar" &&
-	git config --unset i18n.commitEncoding
+	git commit -m "add bar"
 '
 
 test_expect_success 'alias builtin format' '
@@ -63,10 +50,9 @@ test_expect_success 'alias user-defined format' '
 '
 
 test_expect_success 'alias user-defined tformat with %s (iso8859-1 encoding)' '
-	git config i18n.logOutputEncoding iso8859-1 &&
+	test_config i18n.logOutputEncoding iso8859-1 &&
 	git log --oneline >expected-s &&
 	git log --pretty="tformat:%h %s" >actual-s &&
-	git config --unset i18n.logOutputEncoding &&
 	test_cmp expected-s actual-s
 '
 
@@ -110,13 +96,13 @@ test_expect_success 'alias loop' '
 '
 
 test_expect_failure 'NUL separation' '
-	printf "add bar\0$(commit_msg)" >expected &&
+	printf "add bar\0$initial_msg" >expected &&
 	git log -z --pretty="format:%s" >actual &&
 	test_cmp expected actual
 '
 
 test_expect_failure 'NUL termination' '
-	printf "add bar\0$(commit_msg)\0" >expected &&
+	printf "add bar\0$initial_msg\0" >expected &&
 	git log -z --pretty="tformat:%s" >actual &&
 	test_cmp expected actual
 '
@@ -124,7 +110,7 @@ test_expect_failure 'NUL termination' '
 test_expect_failure 'NUL separation with --stat' '
 	stat0_part=$(git diff --stat HEAD^ HEAD) &&
 	stat1_part=$(git diff-tree --no-commit-id --stat --root HEAD^) &&
-	printf "add bar\n$stat0_part\n\0$(commit_msg)\n$stat1_part\n" >expected &&
+	printf "add bar\n$stat0_part\n\0$initial_msg\n$stat1_part\n" >expected &&
 	git log -z --stat --pretty="format:%s" >actual &&
 	test_i18ncmp expected actual
 '
@@ -132,7 +118,7 @@ test_expect_failure 'NUL separation with --stat' '
 test_expect_failure 'NUL termination with --stat' '
 	stat0_part=$(git diff --stat HEAD^ HEAD) &&
 	stat1_part=$(git diff-tree --no-commit-id --stat --root HEAD^) &&
-	printf "add bar\n$stat0_part\n\0$(commit_msg)\n$stat1_part\n0" >expected &&
+	printf "add bar\n$stat0_part\n\0$initial_msg\n$stat1_part\n0" >expected &&
 	git log -z --stat --pretty="tformat:%s" >actual &&
 	test_i18ncmp expected actual
 '
@@ -154,7 +140,7 @@ test_expect_failure 'left alignment formatting' '
 message two                            Z
 message one                            Z
 add bar                                Z
-$(commit_msg)                    Z
+$initial_msg                    Z
 EOF
 	test_cmp expected actual
 '
@@ -167,7 +153,7 @@ test_expect_failure 'left alignment formatting at the nth column' '
 $head1 message two                    Z
 $head2 message one                    Z
 $head3 add bar                        Z
-$head4 $(commit_msg)            Z
+$head4 $initial_msg            Z
 EOF
 	test_cmp expected actual
 '
@@ -180,7 +166,7 @@ test_expect_failure 'left alignment formatting with no padding' '
 message two
 message one
 add bar
-$(commit_msg)
+$initial_msg
 EOF
 	test_cmp expected actual
 '
@@ -193,7 +179,7 @@ test_expect_failure 'left alignment formatting with trunc' '
 message ..
 message ..
 add bar  Z
-$(commit_msg "" "8" ".\+$")
+$(extract_msg "^\(........\).*")..
 EOF
 	test_cmp expected actual
 '
@@ -206,8 +192,10 @@ test_expect_failure 'left alignment formatting with ltrunc' '
 ..sage two
 ..sage one
 add bar  Z
-$(commit_msg "" "0" ".\{11\}")
+..$(extract_msg ".*\(.........\)$")
 EOF
+	# the RE above covers 9 bytes because there is one UTF-8 character
+	# where two bytes occupy only one character position
 	test_cmp expected actual
 '
 
@@ -219,7 +207,7 @@ test_expect_failure 'left alignment formatting with mtrunc' '
 mess.. two
 mess.. one
 add bar  Z
-$(commit_msg "" "4" ".\{11\}")
+$(extract_msg "^\(....\).*")..$(extract_msg ".*\(....\)$")
 EOF
 	test_cmp expected actual
 '
@@ -232,7 +220,7 @@ test_expect_failure 'right alignment formatting' '
 Z                            message two
 Z                            message one
 Z                                add bar
-Z                    $(commit_msg)
+Z                    $initial_msg
 EOF
 	test_cmp expected actual
 '
@@ -245,7 +233,7 @@ test_expect_failure 'right alignment formatting at the nth column' '
 $head1                      message two
 $head2                      message one
 $head3                          add bar
-$head4              $(commit_msg)
+$head4              $initial_msg
 EOF
 	test_cmp expected actual
 '
@@ -258,7 +246,7 @@ test_expect_failure 'right alignment formatting with no padding' '
 message two
 message one
 add bar
-$(commit_msg)
+$initial_msg
 EOF
 	test_cmp expected actual
 '
@@ -271,7 +259,7 @@ test_expect_failure 'center alignment formatting' '
 Z             message two              Z
 Z             message one              Z
 Z               add bar                Z
-Z         $(commit_msg)          Z
+Z         $initial_msg          Z
 EOF
 	test_cmp expected actual
 '
@@ -284,7 +272,7 @@ test_expect_failure 'center alignment formatting at the nth column' '
 $head1           message two          Z
 $head2           message one          Z
 $head3             add bar            Z
-$head4       $(commit_msg)      Z
+$head4       $initial_msg      Z
 EOF
 	test_cmp expected actual
 '
@@ -297,7 +285,7 @@ test_expect_failure 'center alignment formatting with no padding' '
 message two
 message one
 add bar
-$(commit_msg)
+$initial_msg
 EOF
 	test_cmp expected actual
 '
@@ -311,7 +299,7 @@ test_expect_failure 'left/right alignment formatting with stealing' '
 short long  long long
 message ..   A U Thor
 add bar      A U Thor
-$(commit_msg "" "8" ".\+$")   A U Thor
+$(extract_msg "^\(........\).*")..   A U Thor
 EOF
 	test_cmp expected actual
 '
#73 lore raw

PATCH v8 5/5 pretty: --format output should honor logOutputEncoding

In reply to Alexey Shumkin

One can set an alias

	$ git config [--global] alias.lg "log --graph --pretty=format:'%Cred%h%Creset
	-%C(yellow)%d%Creset %s %Cgreen(%cd) %C(bold blue)<%an>%Creset'
	--abbrev-commit --date=local"

to see the log as a pretty tree (like *gitk* but in a terminal).

However, log messages written in an encoding i18n.commitEncoding which differs from terminal encoding are shown corrupted even when i18n.logOutputEncoding and terminal encoding are the same (e.g. log messages committed on a Cygwin box with Windows-1251 encoding seen on a Linux box with a UTF-8 encoding and vice versa).

To simplify an example we can say the following two commands are expected to give the same output to a terminal:

	$ git log --oneline --no-color
	$ git log --pretty=format:'%h %s'

However, the former pays attention to i18n.logOutputEncoding configuration, while the latter does not when it formats "%s".

The same corruption is true for

	$ git diff --submodule=log
and
	$ git rev-list --pretty=format:%s HEAD
and
	$ git reset --hard

This patch makes pretty --format honor logOutputEncoding when it formats log message.

---
 builtin/reset.c                  |  5 ++++-
 builtin/rev-list.c               |  1 +
 builtin/shortlog.c               |  1 +
 log-tree.c                       |  1 +
 submodule.c                      |  1 +
 t/t4041-diff-submodule-option.sh | 10 +++++-----
 t/t4205-log-pretty-formats.sh    | 34 +++++++++++++++++-----------------
 t/t6006-rev-list-format.sh       |  8 ++++----
 t/t7102-reset.sh                 |  2 +-
 9 files changed, 35 insertions(+), 28 deletions(-)
builtin/reset.c +4 -1
index 6032131..afa6e02 100644
@@ -93,10 +93,12 @@ static int reset_index(const unsigned char *sha1, int reset_type, int quiet)
 static void print_new_head_line(struct commit *commit)
 {
 	const char *hex, *body;
+	char *msg;
 
 	hex = find_unique_abbrev(commit->object.sha1, DEFAULT_ABBREV);
 	printf(_("HEAD is now at %s"), hex);
-	body = strstr(commit->buffer, "\n\n");
+	msg = logmsg_reencode(commit, NULL, get_log_output_encoding());
+	body = strstr(msg, "\n\n");
 	if (body) {
 		const char *eol;
 		size_t len;
@@ -107,6 +109,7 @@ static void print_new_head_line(struct commit *commit)
 	}
 	else
 		printf("\n");
+	logmsg_free(msg, commit);
 }
 
 static void update_index_from_diff(struct diff_queue_struct *q,
builtin/rev-list.c +1 -0
index 67701be..a5ec30d 100644
@@ -111,6 +111,7 @@ static void show_commit(struct commit *commit, void *data)
 		ctx.date_mode = revs->date_mode;
 		ctx.date_mode_explicit = revs->date_mode_explicit;
 		ctx.fmt = revs->commit_format;
+		ctx.output_encoding = get_log_output_encoding();
 		pretty_print_commit(&ctx, commit, &buf);
 		if (revs->graph) {
 			if (buf.len) {
builtin/shortlog.c +1 -0
index 1fd6f8a..1434f8f 100644
@@ -137,6 +137,7 @@ void shortlog_add_commit(struct shortlog *log, struct commit *commit)
 		ctx.subject = "";
 		ctx.after_subject = "";
 		ctx.date_mode = DATE_NORMAL;
+		ctx.output_encoding = get_log_output_encoding();
 		pretty_print_commit(&ctx, commit, &ufbuf);
 		buffer = ufbuf.buf;
 	} else if (*buffer) {
log-tree.c +1 -0
index 1946e9c..5277d3e 100644
@@ -616,6 +616,7 @@ void show_log(struct rev_info *opt)
 	ctx.fmt = opt->commit_format;
 	ctx.mailmap = opt->mailmap;
 	ctx.color = opt->diffopt.use_color;
+	ctx.output_encoding = get_log_output_encoding();
 	pretty_print_commit(&ctx, commit, &msgbuf);
 
 	if (opt->add_signoff)
submodule.c +1 -0
index 1821a5b..78734e1 100644
@@ -226,6 +226,7 @@ static void print_submodule_summary(struct rev_info *rev, FILE *f,
 	while ((commit = get_revision(rev))) {
 		struct pretty_print_context ctx = {0};
 		ctx.date_mode = rev->date_mode;
+		ctx.output_encoding = get_log_output_encoding();
 		strbuf_setlen(&sb, 0);
 		strbuf_addstr(&sb, line_prefix);
 		if (commit->object.flags & SYMMETRIC_LEFT) {
t/t4041-diff-submodule-option.sh +5 -5
index d300d0c..04348ea 100755
@@ -94,7 +94,7 @@ test_expect_success 'diff.submodule does not affect plumbing' '
 commit_file sm1 &&
 head2=$(add_file sm1 foo3)
 
-test_expect_failure 'modified submodule(forward)' '
+test_expect_success 'modified submodule(forward)' '
 	git diff-index -p --submodule=log HEAD >actual &&
 	cat >expected <<-EOF &&
 	Submodule sm1 $head1..$head2:
@@ -103,7 +103,7 @@ test_expect_failure 'modified submodule(forward)' '
 	test_cmp expected actual
 '
 
-test_expect_failure 'modified submodule(forward)' '
+test_expect_success 'modified submodule(forward)' '
 	git diff --submodule=log >actual &&
 	cat >expected <<-EOF &&
 	Submodule sm1 $head1..$head2:
@@ -112,7 +112,7 @@ test_expect_failure 'modified submodule(forward)' '
 	test_cmp expected actual
 '
 
-test_expect_failure 'modified submodule(forward) --submodule' '
+test_expect_success 'modified submodule(forward) --submodule' '
 	git diff --submodule >actual &&
 	cat >expected <<-EOF &&
 	Submodule sm1 $head1..$head2:
@@ -143,7 +143,7 @@ head3=$(
 	git rev-parse --short --verify HEAD
 )
 
-test_expect_failure 'modified submodule(backward)' '
+test_expect_success 'modified submodule(backward)' '
 	git diff-index -p --submodule=log HEAD >actual &&
 	cat >expected <<-EOF &&
 	Submodule sm1 $head2..$head3 (rewind):
@@ -154,7 +154,7 @@ test_expect_failure 'modified submodule(backward)' '
 '
 
 head4=$(add_file sm1 foo4 foo5)
-test_expect_failure 'modified submodule(backward and forward)' '
+test_expect_success 'modified submodule(backward and forward)' '
 	git diff-index -p --submodule=log HEAD >actual &&
 	cat >expected <<-EOF &&
 	Submodule sm1 $head2...$head4:
t/t4205-log-pretty-formats.sh +17 -17
index a23da67..5e13000 100755
@@ -70,7 +70,7 @@ test_expect_success 'alias user-defined tformat with %s (iso8859-1 encoding)' '
 	test_cmp expected-s actual-s
 '
 
-test_expect_failure 'alias user-defined tformat with %s (utf-8 encoding)' '
+test_expect_success 'alias user-defined tformat with %s (utf-8 encoding)' '
 	git log --oneline >expected-s &&
 	git log --pretty="tformat:%h %s" >actual-s &&
 	test_cmp expected-s actual-s
@@ -109,19 +109,19 @@ test_expect_success 'alias loop' '
 	test_must_fail git log --pretty=test-foo
 '
 
-test_expect_failure 'NUL separation' '
+test_expect_success 'NUL separation' '
 	printf "add bar\0$(commit_msg)" >expected &&
 	git log -z --pretty="format:%s" >actual &&
 	test_cmp expected actual
 '
 
-test_expect_failure 'NUL termination' '
+test_expect_success 'NUL termination' '
 	printf "add bar\0$(commit_msg)\0" >expected &&
 	git log -z --pretty="tformat:%s" >actual &&
 	test_cmp expected actual
 '
 
-test_expect_failure 'NUL separation with --stat' '
+test_expect_success 'NUL separation with --stat' '
 	stat0_part=$(git diff --stat HEAD^ HEAD) &&
 	stat1_part=$(git diff-tree --no-commit-id --stat --root HEAD^) &&
 	printf "add bar\n$stat0_part\n\0$(commit_msg)\n$stat1_part\n" >expected &&
@@ -146,7 +146,7 @@ test_expect_success 'setup more commits' '
 	head4=$(git rev-parse --verify --short HEAD~3)
 '
 
-test_expect_failure 'left alignment formatting' '
+test_expect_success 'left alignment formatting' '
 	git log --pretty="format:%<(40)%s" >actual &&
 	# complete the incomplete line at the end
 	echo >>actual &&
@@ -159,7 +159,7 @@ EOF
 	test_cmp expected actual
 '
 
-test_expect_failure 'left alignment formatting at the nth column' '
+test_expect_success 'left alignment formatting at the nth column' '
 	git log --pretty="format:%h %<|(40)%s" >actual &&
 	# complete the incomplete line at the end
 	echo >>actual &&
@@ -172,7 +172,7 @@ EOF
 	test_cmp expected actual
 '
 
-test_expect_failure 'left alignment formatting with no padding' '
+test_expect_success 'left alignment formatting with no padding' '
 	git log --pretty="format:%<(1)%s" >actual &&
 	# complete the incomplete line at the end
 	echo >>actual &&
@@ -185,7 +185,7 @@ EOF
 	test_cmp expected actual
 '
 
-test_expect_failure 'left alignment formatting with trunc' '
+test_expect_success 'left alignment formatting with trunc' '
 	git log --pretty="format:%<(10,trunc)%s" >actual &&
 	# complete the incomplete line at the end
 	echo >>actual &&
@@ -198,7 +198,7 @@ EOF
 	test_cmp expected actual
 '
 
-test_expect_failure 'left alignment formatting with ltrunc' '
+test_expect_success 'left alignment formatting with ltrunc' '
 	git log --pretty="format:%<(10,ltrunc)%s" >actual &&
 	# complete the incomplete line at the end
 	echo >>actual &&
@@ -211,7 +211,7 @@ EOF
 	test_cmp expected actual
 '
 
-test_expect_failure 'left alignment formatting with mtrunc' '
+test_expect_success 'left alignment formatting with mtrunc' '
 	git log --pretty="format:%<(10,mtrunc)%s" >actual &&
 	# complete the incomplete line at the end
 	echo >>actual &&
@@ -224,7 +224,7 @@ EOF
 	test_cmp expected actual
 '
 
-test_expect_failure 'right alignment formatting' '
+test_expect_success 'right alignment formatting' '
 	git log --pretty="format:%>(40)%s" >actual &&
 	# complete the incomplete line at the end
 	echo >>actual &&
@@ -237,7 +237,7 @@ EOF
 	test_cmp expected actual
 '
 
-test_expect_failure 'right alignment formatting at the nth column' '
+test_expect_success 'right alignment formatting at the nth column' '
 	git log --pretty="format:%h %>|(40)%s" >actual &&
 	# complete the incomplete line at the end
 	echo >>actual &&
@@ -250,7 +250,7 @@ EOF
 	test_cmp expected actual
 '
 
-test_expect_failure 'right alignment formatting with no padding' '
+test_expect_success 'right alignment formatting with no padding' '
 	git log --pretty="format:%>(1)%s" >actual &&
 	# complete the incomplete line at the end
 	echo >>actual &&
@@ -263,7 +263,7 @@ EOF
 	test_cmp expected actual
 '
 
-test_expect_failure 'center alignment formatting' '
+test_expect_success 'center alignment formatting' '
 	git log --pretty="format:%><(40)%s" >actual &&
 	# complete the incomplete line at the end
 	echo >>actual &&
@@ -276,7 +276,7 @@ EOF
 	test_cmp expected actual
 '
 
-test_expect_failure 'center alignment formatting at the nth column' '
+test_expect_success 'center alignment formatting at the nth column' '
 	git log --pretty="format:%h %><|(40)%s" >actual &&
 	# complete the incomplete line at the end
 	echo >>actual &&
@@ -289,7 +289,7 @@ EOF
 	test_cmp expected actual
 '
 
-test_expect_failure 'center alignment formatting with no padding' '
+test_expect_success 'center alignment formatting with no padding' '
 	git log --pretty="format:%><(1)%s" >actual &&
 	# complete the incomplete line at the end
 	echo >>actual &&
@@ -302,7 +302,7 @@ EOF
 	test_cmp expected actual
 '
 
-test_expect_failure 'left/right alignment formatting with stealing' '
+test_expect_success 'left/right alignment formatting with stealing' '
 	git commit --amend -m short --author "long long long <[email protected]>" &&
 	git log --pretty="format:%<(10,trunc)%s%>>(10,ltrunc)% an" >actual &&
 	# complete the incomplete line at the end
t/t6006-rev-list-format.sh +4 -4
index e4b50ed..18d7909 100755
@@ -128,7 +128,7 @@ commit $head1
 iso8859-1
 EOF
 
-test_format subject %s failure <<EOF
+test_format subject %s <<EOF
 commit $head2
 $changed
 commit $head1
@@ -140,7 +140,7 @@ commit $head2
 commit $head1
 EOF
 
-test_format raw-body %B failure <<EOF
+test_format raw-body %B <<EOF
 commit $head2
 $changed
 
@@ -252,7 +252,7 @@ EOF
 # so unset i18n.commitEncoding to test encoding conversion
 git config --unset i18n.commitEncoding
 
-test_format complex-subject-commitencoding-unset %s failure <<EOF
+test_format complex-subject-commitencoding-unset %s <<EOF
 commit $head3
 Test printing of complex bodies
 commit $head2
@@ -261,7 +261,7 @@ commit $head1
 $added
 EOF
 
-test_format complex-body-commitencoding-unset %b failure <<EOF
+test_format complex-body-commitencoding-unset %b <<EOF
 commit $head3
 This commit message is much longer than the others,
 and it will be encoded in iso8859-1. We should therefore
t/t7102-reset.sh +1 -1
index 6a92703..73a1bdb 100755
@@ -57,7 +57,7 @@ check_changes () {
 	done | test_cmp .cat_expect -
 }
 
-test_expect_failure 'reset --hard message' '
+test_expect_success 'reset --hard message' '
 	hex=$(git log -1 --format="%h") &&
 	git reset --hard > .actual &&
 	echo HEAD is now at $hex $(commit_msg) > .expected &&
Signature · 1 line
1.8.3.1.16.gce2c52e
#74 lore raw

v9 cover Incremental updates against 'next' branch

In reply to Alexey Shumkin

This patch series is an incremental updates on top of (7c375214 t4205:
replace .\+ with ..* in sed commands, 2013-07-01) as far as v7 patches were applied to the 'next' branch but there were more improvements made in v8.

Alexey Shumkin (5):
t4041, t4205, t6006, t7102: use iso8859-1 rather than iso-8859-1
t4205: revert back single quotes
t4205, t6006, t7102: make functions more readable
t6006: add two more tests for the case i18n.commitEncoding is not set
t4205: avoid using sed

 t/t4041-diff-submodule-option.sh |   4 +-
 t/t4205-log-pretty-formats.sh    | 145 +++++++++++++++++++--------------------
 t/t6006-rev-list-format.sh       |  69 ++++++++++---------
 t/t7102-reset.sh                 |  22 +++---
 4 files changed, 121 insertions(+), 119 deletions(-)
Signature · 1 line
1.8.3.1.15.g5c23c1e
#75 lore raw

PATCH v9 1/5 t4041, t4205, t6006, t7102: use iso8859-1 rather than iso-8859-1

This is actually a fixup of de6029a2d7734a93a9e27b9c4471862a47dd8123, which was applied before final patch series was sent.

Also, see 3994e8a98dc7bbf67e61d23c8125f44383499a1f for the explanation of such a replacement.

---
 t/t4041-diff-submodule-option.sh |  4 ++--
 t/t4205-log-pretty-formats.sh    |  8 ++++----
 t/t6006-rev-list-format.sh       | 14 +++++++-------
 t/t7102-reset.sh                 | 10 +++++-----
 4 files changed, 18 insertions(+), 18 deletions(-)
t/t4041-diff-submodule-option.sh +2 -2
index 0a4f496..1751c83 100755
@@ -23,8 +23,8 @@ add_file () {
 			echo "$name" >"$name" &&
 			git add "$name" &&
 			test_tick &&
-			msg_added_iso88591=$(echo "Add $name ($added $name)" | iconv -f utf-8 -t iso-8859-1) &&
-			git -c 'i18n.commitEncoding=iso-8859-1' commit -m "$msg_added_iso88591"
+			msg_added_iso88591=$(echo "Add $name ($added $name)" | iconv -f utf-8 -t iso8859-1) &&
+			git -c 'i18n.commitEncoding=iso8859-1' commit -m "$msg_added_iso88591"
 		done >/dev/null &&
 		git rev-parse --short --verify HEAD
 	)
t/t4205-log-pretty-formats.sh +4 -4
index 3cfb744..c283842 100755
@@ -32,8 +32,8 @@ test_expect_success 'set up basic repos' '
 	>bar &&
 	git add foo &&
 	test_tick &&
-	git config i18n.commitEncoding iso-8859-1 &&
-	git commit -m "$(commit_msg iso-8859-1)" &&
+	git config i18n.commitEncoding iso8859-1 &&
+	git commit -m "$(commit_msg iso8859-1)" &&
 	git add bar &&
 	test_tick &&
 	git commit -m "add bar" &&
@@ -61,8 +61,8 @@ test_expect_success 'alias user-defined format' '
 	test_cmp expected actual
 '
 
-test_expect_success 'alias user-defined tformat with %s (iso-8859-1 encoding)' '
-	git config i18n.logOutputEncoding iso-8859-1 &&
+test_expect_success 'alias user-defined tformat with %s (iso8859-1 encoding)' '
+	git config i18n.logOutputEncoding iso8859-1 &&
 	git log --oneline >expected-s &&
 	git log --pretty="tformat:%h %s" >actual-s &&
 	git config --unset i18n.logOutputEncoding &&
t/t6006-rev-list-format.sh +7 -7
index 380c85b..4751d22 100755
@@ -12,15 +12,15 @@ test_tick
 # String "added" in German (translated with Google Translate), encoded in UTF-8,
 # used as a commit log message below.
 added=$(printf "added (hinzugef\303\274gt) foo")
-added_iso88591=$(echo "$added" | iconv -f utf-8 -t iso-8859-1)
+added_iso88591=$(echo "$added" | iconv -f utf-8 -t iso8859-1)
 # same but "changed"
 changed=$(printf "changed (ge\303\244ndert) foo")
-changed_iso88591=$(echo "$changed" | iconv -f utf-8 -t iso-8859-1)
+changed_iso88591=$(echo "$changed" | iconv -f utf-8 -t iso8859-1)
 
 test_expect_success 'setup' '
 	: >foo &&
 	git add foo &&
-	git config i18n.commitEncoding iso-8859-1 &&
+	git config i18n.commitEncoding iso8859-1 &&
 	git commit -m "$added_iso88591" &&
 	head1=$(git rev-parse --verify HEAD) &&
 	head1_short=$(git rev-parse --verify --short $head1) &&
@@ -136,9 +136,9 @@ EOF
 
 test_format encoding %e <<EOF
 commit $head2
-iso-8859-1
+iso8859-1
 commit $head1
-iso-8859-1
+iso8859-1
 EOF
 
 test_format subject %s <<EOF
@@ -242,9 +242,9 @@ test_format complex-encoding %e <<EOF
 commit $head3
 iso8859-1
 commit $head2
-iso-8859-1
+iso8859-1
 commit $head1
-iso-8859-1
+iso8859-1
 EOF
 
 test_format complex-subject %s <<EOF
t/t7102-reset.sh +5 -5
index 9132dd9..2ef96e9 100755
@@ -39,7 +39,7 @@ test_expect_success 'creating initial files and commits' '
 
 	echo "1st line 2nd file" >secondfile &&
 	echo "2nd line 2nd file" >>secondfile &&
-	git -c "i18n.commitEncoding=iso-8859-1" commit -a -m "$(commit_msg iso-8859-1)" &&
+	git -c "i18n.commitEncoding=iso8859-1" commit -a -m "$(commit_msg iso8859-1)" &&
 	head5=$(git rev-parse --verify HEAD)
 '
 # git log --pretty=oneline # to see those SHA1 involved
@@ -62,10 +62,10 @@ test_expect_success 'reset --hard message' '
 	test_cmp .expected .actual
 '
 
-test_expect_success 'reset --hard message (iso-8859-1 logoutencoding)' '
+test_expect_success 'reset --hard message (iso8859-1 logoutputencoding)' '
 	hex=$(git log -1 --format="%h") &&
-	git -c "i18n.logOutputEncoding=iso-8859-1" reset --hard > .actual &&
-	echo HEAD is now at $hex $(commit_msg iso-8859-1) > .expected &&
+	git -c "i18n.logOutputEncoding=iso8859-1" reset --hard > .actual &&
+	echo HEAD is now at $hex $(commit_msg iso8859-1) > .expected &&
 	test_cmp .expected .actual
 '
 
@@ -329,7 +329,7 @@ test_expect_success 'redoing the last two commits should succeed' '
 
 	echo "1st line 2nd file" >secondfile &&
 	echo "2nd line 2nd file" >>secondfile &&
-	git -c "i18n.commitEncoding=iso-8859-1" commit -a -m "$(commit_msg iso-8859-1)" &&
+	git -c "i18n.commitEncoding=iso8859-1" commit -a -m "$(commit_msg iso8859-1)" &&
 	check_changes $head5
 '
 
Signature · 1 line
1.8.3.1.15.g5c23c1e
#76 lore raw

Re: [PATCH v9 1/5] t4041, t4205, t6006, t7102: use iso8859-1 rather than iso-8859-1

Quoted 5 lines · Alexey Shumkin

This is actually a fixup of de6029a2d7734a93a9e27b9c4471862a47dd8123, which was applied before final patch series was sent.

Also, see 3994e8a98dc7bbf67e61d23c8125f44383499a1f for the explanation of such a replacement.

These are not very useful in a log message. People who read the history 6 months down the road would want to see why we want to use iso8859-1 not iso-8859-1 explained.

	Both "iso8859-1" and "iso-8859-1" are understood as latin-1
	by modern platforms, but the latter is not understood by
	older platforms;update tests to use the former.

        This is in line with 3994e8a9 (t4201: use ISO8859-1 rather
	than ISO-8859-1, 2009-12-03), which did the same.
Quoted 2 lines

I do not recall this exact patch reviewed by J6t, but perhaps I missed a message on the list?

#77 lore raw

Re: [PATCH v9 1/5] t4041, t4205, t6006, t7102: use iso8859-1 rather than iso-8859-1

Quoted 12 lines · Junio C Hamano
Quoted 5 lines · Alexey Shumkin

This is actually a fixup of de6029a2d7734a93a9e27b9c4471862a47dd8123, which was applied before final patch series was sent.

Also, see 3994e8a98dc7bbf67e61d23c8125f44383499a1f for the explanation of such a replacement.

These are not very useful in a log message. People who read the history 6 months down the road would want to see why we want to use iso8859-1 not iso-8859-1 explained.

Quoted 6 lines
	Both "iso8859-1" and "iso-8859-1" are understood as latin-1
	by modern platforms, but the latter is not understood by
	older platforms;update tests to use the former.

        This is in line with 3994e8a9 (t4201: use ISO8859-1 rather
	than ISO-8859-1, 2009-12-03), which did the same.

Yep, it whould be better, I thought to do like this but I didn't )

Quoted 6 lines
Quoted 3 lines

I do not recall this exact patch reviewed by J6t, but perhaps I missed a message on the list?

I've reread 'SubmittingPatches' doc, and I can say I used "Reviewed-by" incorrectly. Sorry for this. It must be "Suggested-by" there, I guess.

Signature · 1 line
Alexey Shumkin
#78 lore raw

Re: [PATCH v9 1/5] t4041, t4205, t6006, t7102: use iso8859-1 rather than iso-8859-1

Quoted 8 lines · Alexey Shumkin
Quoted 6 lines
	Both "iso8859-1" and "iso-8859-1" are understood as latin-1
	by modern platforms, but the latter is not understood by
	older platforms;update tests to use the former.

        This is in line with 3994e8a9 (t4201: use ISO8859-1 rather
	than ISO-8859-1, 2009-12-03), which did the same.

Yep, it whould be better, I thought to do like this but I didn't )

Quoted 1 line
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

I do not recall this exact patch reviewed by J6t, but perhaps I missed a message on the list?

I've reread 'SubmittingPatches' doc, and I can say I used "Reviewed-by" incorrectly. Sorry for this. It must be "Suggested-by" there, I guess.

OK, then I'll queue this patch (but not 2-4/5 yet) with log message amended.

Thanks.

#79 lore raw

Re: [PATCH v9 1/5] t4041, t4205, t6006, t7102: use iso8859-1 rather than iso-8859-1

Quoted 13 lines · Junio C Hamano
Quoted 11 lines · Alexey Shumkin
Quoted 6 lines
	Both "iso8859-1" and "iso-8859-1" are understood as latin-1
	by modern platforms, but the latter is not understood by
	older platforms;update tests to use the former.

        This is in line with 3994e8a9 (t4201: use ISO8859-1 rather
	than ISO-8859-1, 2009-12-03), which did the same.

Yep, it whould be better, I thought to do like this but I didn't )

Quoted 4 lines
Quoted 3 lines
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

I do not recall this exact patch reviewed by J6t, but perhaps I missed a message on the list?

I've reread 'SubmittingPatches' doc, and I can say I used "Reviewed-by" incorrectly. Sorry for this. It must be "Suggested-by" there, I guess.

OK, then I'll queue this patch (but not 2-4/5 yet) with log message amended.

Excuse me, you've said "Ok" for 2/5 message, and then explained (as I understood) then "subtle difference" between EOF and \EOF. Should I change the message somehow?

Quoted 2 lines

Thanks.

Signature · 1 line
Alexey Shumkin
#80 lore raw

Re: [PATCH v9 1/5] t4041, t4205, t6006, t7102: use iso8859-1 rather than iso-8859-1

Quoted 5 lines · Alexey Shumkin
Quoted 2 lines

OK, then I'll queue this patch (but not 2-4/5 yet) with log message amended.

Excuse me, you've said "Ok" for 2/5 message, and then explained (as I understood) then "subtle difference" between EOF and \EOF. Should I change the message somehow?

I left it up to you. If I queued without waiting, it wouldn't have been up-to-you, so...

#81 lore raw

PATCH v9 2/5 t4205: revert back single quotes

In reply to Alexey Shumkin

In previuos commit de6029a2d7734a93a9e27b9c4471862a47dd8123 single quotes were replaced with double quotes to make "$(commit_msg)" expression in heredoc to work. The same effect can be achieved by using "EOF" as a heredoc delimiter instead of "\EOF".

---
 t/t4205-log-pretty-formats.sh | 106 +++++++++++++++++++++---------------------
 1 file changed, 53 insertions(+), 53 deletions(-)
t/t4205-log-pretty-formats.sh +53 -53
index c283842..ef9770a 100755
@@ -145,174 +145,174 @@ test_expect_success 'setup more commits' '
 	head4=$(git rev-parse --verify --short HEAD~3)
 '
 
-test_expect_success 'left alignment formatting' "
-	git log --pretty='format:%<(40)%s' >actual &&
+test_expect_success 'left alignment formatting' '
+	git log --pretty="format:%<(40)%s" >actual &&
 	# complete the incomplete line at the end
 	echo >>actual &&
-	qz_to_tab_space <<\EOF >expected &&
+	qz_to_tab_space <<EOF >expected &&
 message two                            Z
 message one                            Z
 add bar                                Z
 $(commit_msg)                    Z
 EOF
 	test_cmp expected actual
-"
+'
 
-test_expect_success 'left alignment formatting at the nth column' "
-	git log --pretty='format:%h %<|(40)%s' >actual &&
+test_expect_success 'left alignment formatting at the nth column' '
+	git log --pretty="format:%h %<|(40)%s" >actual &&
 	# complete the incomplete line at the end
 	echo >>actual &&
-	qz_to_tab_space <<\EOF >expected &&
+	qz_to_tab_space <<EOF >expected &&
 $head1 message two                    Z
 $head2 message one                    Z
 $head3 add bar                        Z
 $head4 $(commit_msg)            Z
 EOF
 	test_cmp expected actual
-"
+'
 
-test_expect_success 'left alignment formatting with no padding' "
-	git log --pretty='format:%<(1)%s' >actual &&
+test_expect_success 'left alignment formatting with no padding' '
+	git log --pretty="format:%<(1)%s" >actual &&
 	# complete the incomplete line at the end
 	echo >>actual &&
-	cat <<\EOF >expected &&
+	cat <<EOF >expected &&
 message two
 message one
 add bar
 $(commit_msg)
 EOF
 	test_cmp expected actual
-"
+'
 
-test_expect_success 'left alignment formatting with trunc' "
-	git log --pretty='format:%<(10,trunc)%s' >actual &&
+test_expect_success 'left alignment formatting with trunc' '
+	git log --pretty="format:%<(10,trunc)%s" >actual &&
 	# complete the incomplete line at the end
 	echo >>actual &&
-	qz_to_tab_space <<\EOF >expected &&
+	qz_to_tab_space <<EOF >expected &&
 message ..
 message ..
 add bar  Z
 $(commit_msg "" "8" "..*$")
 EOF
 	test_cmp expected actual
-"
+'
 
-test_expect_success 'left alignment formatting with ltrunc' "
-	git log --pretty='format:%<(10,ltrunc)%s' >actual &&
+test_expect_success 'left alignment formatting with ltrunc' '
+	git log --pretty="format:%<(10,ltrunc)%s" >actual &&
 	# complete the incomplete line at the end
 	echo >>actual &&
-	qz_to_tab_space <<\EOF >expected &&
+	qz_to_tab_space <<EOF >expected &&
 ..sage two
 ..sage one
 add bar  Z
 $(commit_msg "" "0" ".\{11\}")
 EOF
 	test_cmp expected actual
-"
+'
 
-test_expect_success 'left alignment formatting with mtrunc' "
-	git log --pretty='format:%<(10,mtrunc)%s' >actual &&
+test_expect_success 'left alignment formatting with mtrunc' '
+	git log --pretty="format:%<(10,mtrunc)%s" >actual &&
 	# complete the incomplete line at the end
 	echo >>actual &&
-	qz_to_tab_space <<\EOF >expected &&
+	qz_to_tab_space <<EOF >expected &&
 mess.. two
 mess.. one
 add bar  Z
 $(commit_msg "" "4" ".\{11\}")
 EOF
 	test_cmp expected actual
-"
+'
 
-test_expect_success 'right alignment formatting' "
-	git log --pretty='format:%>(40)%s' >actual &&
+test_expect_success 'right alignment formatting' '
+	git log --pretty="format:%>(40)%s" >actual &&
 	# complete the incomplete line at the end
 	echo >>actual &&
-	qz_to_tab_space <<\EOF >expected &&
+	qz_to_tab_space <<EOF >expected &&
 Z                            message two
 Z                            message one
 Z                                add bar
 Z                    $(commit_msg)
 EOF
 	test_cmp expected actual
-"
+'
 
-test_expect_success 'right alignment formatting at the nth column' "
-	git log --pretty='format:%h %>|(40)%s' >actual &&
+test_expect_success 'right alignment formatting at the nth column' '
+	git log --pretty="format:%h %>|(40)%s" >actual &&
 	# complete the incomplete line at the end
 	echo >>actual &&
-	qz_to_tab_space <<\EOF >expected &&
+	qz_to_tab_space <<EOF >expected &&
 $head1                      message two
 $head2                      message one
 $head3                          add bar
 $head4              $(commit_msg)
 EOF
 	test_cmp expected actual
-"
+'
 
-test_expect_success 'right alignment formatting with no padding' "
-	git log --pretty='format:%>(1)%s' >actual &&
+test_expect_success 'right alignment formatting with no padding' '
+	git log --pretty="format:%>(1)%s" >actual &&
 	# complete the incomplete line at the end
 	echo >>actual &&
-	cat <<\EOF >expected &&
+	cat <<EOF >expected &&
 message two
 message one
 add bar
 $(commit_msg)
 EOF
 	test_cmp expected actual
-"
+'
 
-test_expect_success 'center alignment formatting' "
-	git log --pretty='format:%><(40)%s' >actual &&
+test_expect_success 'center alignment formatting' '
+	git log --pretty="format:%><(40)%s" >actual &&
 	# complete the incomplete line at the end
 	echo >>actual &&
-	qz_to_tab_space <<\EOF >expected &&
+	qz_to_tab_space <<EOF >expected &&
 Z             message two              Z
 Z             message one              Z
 Z               add bar                Z
 Z         $(commit_msg)          Z
 EOF
 	test_cmp expected actual
-"
+'
 
-test_expect_success 'center alignment formatting at the nth column' "
-	git log --pretty='format:%h %><|(40)%s' >actual &&
+test_expect_success 'center alignment formatting at the nth column' '
+	git log --pretty="format:%h %><|(40)%s" >actual &&
 	# complete the incomplete line at the end
 	echo >>actual &&
-	qz_to_tab_space <<\EOF >expected &&
+	qz_to_tab_space <<EOF >expected &&
 $head1           message two          Z
 $head2           message one          Z
 $head3             add bar            Z
 $head4       $(commit_msg)      Z
 EOF
 	test_cmp expected actual
-"
+'
 
-test_expect_success 'center alignment formatting with no padding' "
-	git log --pretty='format:%><(1)%s' >actual &&
+test_expect_success 'center alignment formatting with no padding' '
+	git log --pretty="format:%><(1)%s" >actual &&
 	# complete the incomplete line at the end
 	echo >>actual &&
-	cat <<\EOF >expected &&
+	cat <<EOF >expected &&
 message two
 message one
 add bar
 $(commit_msg)
 EOF
 	test_cmp expected actual
-"
+'
 
-test_expect_success 'left/right alignment formatting with stealing' "
-	git commit --amend -m short --author 'long long long <[email protected]>' &&
-	git log --pretty='format:%<(10,trunc)%s%>>(10,ltrunc)% an' >actual &&
+test_expect_success 'left/right alignment formatting with stealing' '
+	git commit --amend -m short --author "long long long <[email protected]>" &&
+	git log --pretty="format:%<(10,trunc)%s%>>(10,ltrunc)% an" >actual &&
 	# complete the incomplete line at the end
 	echo >>actual &&
-	cat <<\EOF >expected &&
+	cat <<EOF >expected &&
 short long  long long
 message ..   A U Thor
 add bar      A U Thor
 $(commit_msg "" "8" "..*$")   A U Thor
 EOF
 	test_cmp expected actual
-"
+'
 
 test_done
Signature · 1 line
1.8.3.1.15.g5c23c1e
#82 lore raw

Re: [PATCH v9 2/5] t4205: revert back single quotes

Quoted 4 lines · Alexey Shumkin

In previuos commit de6029a2d7734a93a9e27b9c4471862a47dd8123 single quotes were replaced with double quotes to make "$(commit_msg)" expression in heredoc to work. The same effect can be achieved by using "EOF" as a heredoc delimiter instead of "\EOF".

OK.

Quoted 6 lines
t/t4205-log-pretty-formats.sh +2 -2
-test_expect_success 'left alignment formatting' "
-	git log --pretty='format:%<(40)%s' >actual &&
+test_expect_success 'left alignment formatting' '
+	git log --pretty="format:%<(40)%s" >actual &&
 	# complete the incomplete line at the end
 	echo >>actual &&

t/t4205-log-pretty-formats.sh test_expect_success 'setup more commits' ' · line 159

Quoted 10 lines
t/t4205-log-pretty-formats.sh +2 -2
-	qz_to_tab_space <<\EOF >expected &&
+	qz_to_tab_space <<EOF >expected &&
 message two                            Z
 message one                            Z
 add bar                                Z
 $(commit_msg)                    Z
 EOF
 	test_cmp expected actual
-"
+'

A subtle difference is that a call to commit_msg is made when the test is actually run, not when the test script is prepared to be passed (as a parameter) to test_expect_success helper. I think the result of applying this patch, i.e. running $(commit_msg) inside the test, is easier to read and understand.

#83 lore raw

PATCH v9 3/5 t4205, t6006, t7102: make functions more readable

In reply to Alexey Shumkin

Function 'test_format' is become hard to read after its change in de6029a2d7734a93a9e27b9c4471862a47dd8123. So, make it more elegant. Also, change 'commit_msg' function to make it more pretty.

---
 t/t4205-log-pretty-formats.sh |  5 +++--
 t/t6006-rev-list-format.sh    | 23 +++++------------------
 t/t7102-reset.sh              | 12 +++++++-----
 3 files changed, 15 insertions(+), 25 deletions(-)
t/t4205-log-pretty-formats.sh +3 -2
index ef9770a..bb87f02 100755
@@ -7,8 +7,9 @@
 test_description='Test pretty formats'
 . ./test-lib.sh
 
-commit_msg () {
-	# String "initial. initial" partly in German (translated with Google Translate),
+commit_msg() {
+	# String "initial. initial" partly in German
+	# (translated with Google Translate),
 	# encoded in UTF-8, used as a commit log message below.
 	msg=$(printf "initial. anf\303\244nglich")
 	if test -n "$1"
t/t6006-rev-list-format.sh +5 -18
index 4751d22..e069263 100755
@@ -35,26 +35,13 @@ test_expect_success 'setup' '
 	git config --unset i18n.commitEncoding
 '
 
-# usage: test_format [failure] name format_string <expected_output
+# usage: test_format name format_string [failure] <expected_output
 test_format () {
-	must_fail=0
-	# if parameters count is more than 2 then test must fail
-	if test $# -gt 2
-	then
-		must_fail=1
-		# remove first parameter which is flag for test failure
-		shift
-	fi
 	cat >expect.$1
-	name="format $1"
-	command="git rev-list --pretty=format:'$2' master >output.$1 &&
-		test_cmp expect.$1 output.$1"
-	if test $must_fail -eq 1
-	then
-		test_expect_failure "$name" "$command"
-	else
-		test_expect_success "$name" "$command"
-	fi
+	test_expect_${3:-success} "format $1" "
+		git rev-list --pretty=format:'$2' master >output.$1 &&
+		test_cmp expect.$1 output.$1
+	"
 }
 
 # Feed to --format to provide predictable colored sequences.
t/t7102-reset.sh +7 -5
index 2ef96e9..73a1bdb 100755
@@ -9,15 +9,17 @@ Documented tests for git reset'
 
 . ./test-lib.sh
 
-commit_msg () {
-	# String "modify 2nd file (changed)" partly in German(translated with Google Translate),
+commit_msg() {
+	# String "modify 2nd file (changed)" partly in German
+	# (translated with Google Translate),
 	# encoded in UTF-8, used as a commit log message below.
-	msg=$(printf "modify 2nd file (ge\303\244ndert)")
+	printf "modify 2nd file (ge\303\244ndert)" |
 	if test -n "$1"
 	then
-		msg=$(echo $msg | iconv -f utf-8 -t $1)
+		iconv -f utf-8 -t $1
+	else
+		cat
 	fi
-	echo $msg
 }
 
 test_expect_success 'creating initial files and commits' '
Signature · 1 line
1.8.3.1.15.g5c23c1e
#84 lore raw

Re: [PATCH v9 3/5] t4205, t6006, t7102: make functions more readable

Quoted 3 lines · Alexey Shumkin

Function 'test_format' is become hard to read after its change in de6029a2d7734a93a9e27b9c4471862a47dd8123. So, make it more elegant. Also, change 'commit_msg' function to make it more pretty.

I do not know where you pick up these "more elegant" and "more pretty" from, but please refrain from using _only_ such vague and subjective phrases to describe the change in the log message. Saying "make it <<better>> by doing X" (with various subjective adjectives to say "better") is fine, but make sure you have "doing X" part in the explanation.

Perhaps like this.

Function 'test_format' has become harder to read after its change in de6029a2 (pretty: Add failing tests: --format output should honor logOutputEncoding, 2013-06-26). Simplify it by moving its "should we expect it to fail?" parameter to the end.

I cannot read why you think the updated commit_msg is "more pretty" in the message or in the patch.

t/t4205-log-pretty-formats.sh line 10

Quoted 3 lines
t/t4205-log-pretty-formats.sh +1 -2
-commit_msg () {
-	# String "initial. initial" partly in German (translated with Google Translate),
+commit_msg() {

Style. Have SP on both sides of () in a shell function definition.

t/t4205-log-pretty-formats.sh line 15

Quoted 5 lines
t/t4205-log-pretty-formats.sh +2 -0
+	# String "initial. initial" partly in German
+	# (translated with Google Translate),
 	# encoded in UTF-8, used as a commit log message below.
 	msg=$(printf "initial. anf\303\244nglich")
 	if test -n "$1"

This is not "more pretty" but "better commented".

Quoted 14 lines
t/t7102-reset.sh +3 -2
index 2ef96e9..73a1bdb 100755
@@ -9,15 +9,17 @@ Documented tests for git reset'
 
 . ./test-lib.sh
 
-commit_msg () {
-	# String "modify 2nd file (changed)" partly in German(translated with Google Translate),
+commit_msg() {
+	# String "modify 2nd file (changed)" partly in German
+	# (translated with Google Translate),
 	# encoded in UTF-8, used as a commit log message below.

t/t7102-reset.sh Documented tests for git reset' · line 20

Quoted 10 lines
t/t7102-reset.sh +4 -3
-	msg=$(printf "modify 2nd file (ge\303\244ndert)")
+	printf "modify 2nd file (ge\303\244ndert)" |
 	if test -n "$1"
 	then
-		msg=$(echo $msg | iconv -f utf-8 -t $1)
+		iconv -f utf-8 -t $1
+	else
+		cat
 	fi
-	echo $msg

Is it "more pretty"? The "we have to have cat only because we want to pipe into a conditional" look somewhat ugly.

	msg="modify 2nd file (ge\303\244ndert)"
        if test -n "$1"
	then
		printf "$msg" | iconv -f utf-8 -t "$1"
	else
		printf "$msg"
	fi
Quoted 3 lines
t/t7102-reset.sh +0 -0
 }
 
 test_expect_success 'creating initial files and commits' '
#85 lore raw

Re: [PATCH v9 3/5] t4205, t6006, t7102: make functions more readable

Quoted 13 lines · Junio C Hamano
Quoted 3 lines · Alexey Shumkin

Function 'test_format' is become hard to read after its change in de6029a2d7734a93a9e27b9c4471862a47dd8123. So, make it more elegant. Also, change 'commit_msg' function to make it more pretty.

I do not know where you pick up these "more elegant" and "more pretty" from, but please refrain from using _only_ such vague and subjective phrases to describe the change in the log message. Saying "make it <<better>> by doing X" (with various subjective adjectives to say "better") is fine, but make sure you have "doing X" part in the explanation.

Quoted 6 lines

Perhaps like this.

Function 'test_format' has become harder to read after its change in de6029a2 (pretty: Add failing tests: --format output should honor logOutputEncoding, 2013-06-26). Simplify it by moving its "should we expect it to fail?" parameter to the end.

I'm not sure whether this "last parameter" is needed in that code as far as we already removed expected to fail tests

Quoted 9 lines

I cannot read why you think the updated commit_msg is "more pretty" in the message or in the patch.

t/t4205-log-pretty-formats.sh line 10

Quoted 3 lines
t/t4205-log-pretty-formats.sh +1 -2
-commit_msg () {
-	# String "initial. initial" partly in German (translated with Google Translate),
+commit_msg() {

Style. Have SP on both sides of () in a shell function definition.

Could you point me to the coding style guide, please?

Quoted 8 lines

t/t4205-log-pretty-formats.sh line 15

Quoted 6 lines
t/t4205-log-pretty-formats.sh +2 -0
+	# String "initial. initial" partly in German
+	# (translated with Google Translate),
 	# encoded in UTF-8, used as a commit log message below.
 	msg=$(printf "initial. anf\303\244nglich")
 	if test -n "$1"

This is not "more pretty" but "better commented".

Well, this is "better formatted comment", I guess :)

Quoted 20 lines
Quoted 20 lines
t/t7102-reset.sh +4 -4
index 2ef96e9..73a1bdb 100755
@@ -9,15 +9,17 @@ Documented tests for git reset'
 
 . ./test-lib.sh
 
-commit_msg () {
-	# String "modify 2nd file (changed)" partly in German(translated with Google Translate),
+commit_msg() {
+	# String "modify 2nd file (changed)" partly in German
+	# (translated with Google Translate),
 	# encoded in UTF-8, used as a commit log message below.
-	msg=$(printf "modify 2nd file (ge\303\244ndert)")
+	printf "modify 2nd file (ge\303\244ndert)" |
 	if test -n "$1"
 	then
-		msg=$(echo $msg | iconv -f utf-8 -t $1)
Quoted 8 lines

t/t7102-reset.sh Documented tests for git reset' · line 20

Quoted 5 lines
t/t7102-reset.sh +3 -1
+		iconv -f utf-8 -t $1
+	else
+		cat
 	fi
-	echo $msg

Is it "more pretty"? The "we have to have cat only because we want to pipe into a conditional" look somewhat ugly.

That was a proposition of J6t :-D
(see http://article.gmane.org/gmane.comp.version-control.git/229291):

Quoted 15 lines

If you wanted to, you could write this as

commit_msg () {
# String "modify 2nd file (changed)" partly in German #(translated with Google Translate),

   # encoded in UTF-8, used as a commit log message below.
   printf "modify 2nd file (ge\303\244ndert)" |
   if test -n "$1"
   then
       iconv -f utf-8 -t $1
   else
       cat
   fi
}
Quoted 1 line

but I'm not sure whether it's a lot better.

Last sentence has apperared to be a key

Quoted 12 lines
	msg="modify 2nd file (ge\303\244ndert)"
        if test -n "$1"
	then
		printf "$msg" | iconv -f utf-8 -t "$1"
	else
		printf "$msg"
	fi
Quoted 3 lines
t/t7102-reset.sh +0 -0
 }
 
 test_expect_success 'creating initial files and commits' '
Signature · 1 line
Alexey Shumkin
#86 lore raw

Re: [PATCH v9 3/5] t4205, t6006, t7102: make functions more readable

Quoted 8 lines · Alexey Shumkin
Quoted 6 lines

Perhaps like this.

Function 'test_format' has become harder to read after its change in de6029a2 (pretty: Add failing tests: --format output should honor logOutputEncoding, 2013-06-26). Simplify it by moving its "should we expect it to fail?" parameter to the end.

I'm not sure whether this "last parameter" is needed in that code as far as we already removed expected to fail tests

Whatever.

The above is an example of justifying a more vague "simple" ("is better" is implied) with a concrete point (i.e. By moving that to the end, you removed the need to conditionally shift $@ in the function to simplify the codepath), based on my _guess_ of what you possibly meant to say, from reading your description that did not give much clue for me to guess why you thought the result was "more elegant". If my guess missed what your true justification was, please replace it with the more correct one ;-)

Quoted 9 lines
Quoted 8 lines

I cannot read why you think the updated commit_msg is "more pretty" in the message or in the patch.

t/t4205-log-pretty-formats.sh line 10

Quoted 3 lines
t/t4205-log-pretty-formats.sh +1 -2
-commit_msg () {
-	# String "initial. initial" partly in German (translated with Google Translate),
+commit_msg() {

Style. Have SP on both sides of () in a shell function definition.

Could you point me to the coding style guide, please?

Documentation/CodingGuidelines::

- We prefer a space between the function name and the parentheses. The opening "{" should also be on the same line.
E.g.: my_function () {

#87 lore raw

Re: [PATCH v9 3/5] t4205, t6006, t7102: make functions more readable

Quoted 13 lines · Junio C Hamano
Quoted 8 lines · Alexey Shumkin
Quoted 6 lines

Perhaps like this.

Function 'test_format' has become harder to read after its change in de6029a2 (pretty: Add failing tests: --format output should honor logOutputEncoding, 2013-06-26). Simplify it by moving its "should we expect it to fail?" parameter to the end.

I'm not sure whether this "last parameter" is needed in that code as far as we already removed expected to fail tests

Whatever.

Quoted 8 lines

The above is an example of justifying a more vague "simple" ("is better" is implied) with a concrete point (i.e. By moving that to the end, you removed the need to conditionally shift $@ in the function to simplify the codepath), based on my _guess_ of what you possibly meant to say, from reading your description that did not give much clue for me to guess why you thought the result was "more elegant". If my guess missed what your true justification was, please replace it with the more correct one ;-)

Ok

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

I cannot read why you think the updated commit_msg is "more pretty" in the message or in the patch.

Quoted 8 lines
Quoted 6 lines
Quoted 5 lines

t/t4205-log-pretty-formats.sh line 10

Quoted 3 lines
t/t4205-log-pretty-formats.sh +1 -2
-commit_msg () {
-	# String "initial. initial" partly in German (translated with Google Translate),
+commit_msg() {

Style. Have SP on both sides of () in a shell function definition.

Could you point me to the coding style guide, please?

Documentation/CodingGuidelines::

Oh! :)
thank you

Quoted 4 lines

- We prefer a space between the function name and the parentheses. The opening "{" should also be on the same line.
E.g.: my_function () {

Aha

Signature · 1 line
Alexey Shumkin
#88 lore raw

Re: [PATCH v9 3/5] t4205, t6006, t7102: make functions more readable

Quoted 5 lines · Alexey Shumkin
Quoted 3 lines
Quoted 1 line

Could you point me to the coding style guide, please?

Documentation/CodingGuidelines::

Oh! :)
thank you

The most important part of the coding guidelines is to match the style to existing code when writing a new one:

    $ git grep '^[a-z_]* ()' -- *.sh | wc -l
    132
    $ git grep '^[a-z_]*()' -- *.sh | wc -l
    55

We have acquired quite a few violators, but that is no reason to add more.

#89 lore raw

PATCH v9 4/5 t6006: add two more tests for the case i18n.commitEncoding is not set

In reply to Alexey Shumkin

In de6029a2d7734a93a9e27b9c4471862a47dd8123 'complex-subject' test was changed. Revert it back, and add two more tests to test encoding conversions with no i18n.commitEncoding set.

---
 t/t6006-rev-list-format.sh | 32 +++++++++++++++++++++++++-------
 1 file changed, 25 insertions(+), 7 deletions(-)
t/t6006-rev-list-format.sh +25 -7
index e069263..843134f 100755
@@ -217,12 +217,7 @@ test_expect_success 'setup complex body' '
 	git config i18n.commitencoding iso8859-1 &&
 	echo change2 >foo && git commit -a -F commit-msg &&
 	head3=$(git rev-parse --verify HEAD) &&
-	head3_short=$(git rev-parse --short $head3) &&
-	# unset commit encoding config
-	# otherwise %e does not print encoding value
-	# and following test fails
-	git config --unset i18n.commitEncoding
-
+	head3_short=$(git rev-parse --short $head3)
 '
 
 test_format complex-encoding %e <<EOF
@@ -238,12 +233,35 @@ test_format complex-subject %s <<EOF
 commit $head3
 Test printing of complex bodies
 commit $head2
+$changed_iso88591
+commit $head1
+$added_iso88591
+EOF
+
+test_format complex-body %b <<EOF
+commit $head3
+This commit message is much longer than the others,
+and it will be encoded in iso8859-1. We should therefore
+include an iso8859 character: ¡bueno!
+
+commit $head2
+commit $head1
+EOF
+
+# Git uses i18n.commitEncoding if no i18n.logOutputEncoding set
+# so unset i18n.commitEncoding to test encoding conversion
+git config --unset i18n.commitEncoding
+
+test_format complex-subject-commitencoding-unset %s <<EOF
+commit $head3
+Test printing of complex bodies
+commit $head2
 $changed
 commit $head1
 $added
 EOF
 
-test_format complex-body %b <<EOF
+test_format complex-body-commitencoding-unset %b <<EOF
 commit $head3
 This commit message is much longer than the others,
 and it will be encoded in iso8859-1. We should therefore
Signature · 1 line
1.8.3.1.15.g5c23c1e
#90 lore raw

Re: [PATCH v9 4/5] t6006: add two more tests for the case i18n.commitEncoding is not set

t/t6006-rev-list-format.sh test_format complex-subject %s <<EOF · line 245

Quoted 5 lines · Alexey Shumkin
t/t6006-rev-list-format.sh +5 -0
+test_format complex-body %b <<EOF
+commit $head3
+This commit message is much longer than the others,
+and it will be encoded in iso8859-1. We should therefore
+include an iso8859 character: ¡bueno!

This is not such a good idea, as the resulting file will be in mixed encoding (it already has a line with non-ascii that is in UTF-8), and many editors would not like such a file.

Perhaps we should update test_format so that we can feed a quoted input, e.g.

    +include an iso8859-1 character: <A1>bueno!

or something?

Quoted 22 lines
t/t6006-rev-list-format.sh +13 -1
+commit $head2
+commit $head1
+EOF
+
+# Git uses i18n.commitEncoding if no i18n.logOutputEncoding set
+# so unset i18n.commitEncoding to test encoding conversion
+git config --unset i18n.commitEncoding
+
+test_format complex-subject-commitencoding-unset %s <<EOF
+commit $head3
+Test printing of complex bodies
+commit $head2
 $changed
 commit $head1
 $added
 EOF
 
-test_format complex-body %b <<EOF
+test_format complex-body-commitencoding-unset %b <<EOF
 commit $head3
 This commit message is much longer than the others,
 and it will be encoded in iso8859-1. We should therefore
#91 lore raw

Re: [PATCH v9 4/5] t6006: add two more tests for the case i18n.commitEncoding is not set

Quoted 11 lines · Junio C Hamano

t/t6006-rev-list-format.sh test_format complex-subject %s <<EOF · line 245

Quoted 5 lines · Alexey Shumkin
t/t6006-rev-list-format.sh +5 -0
+test_format complex-body %b <<EOF
+commit $head3
+This commit message is much longer than the others,
+and it will be encoded in iso8859-1. We should therefore
+include an iso8859 character: ¡bueno!

This is not such a good idea, as the resulting file will be in mixed encoding (it already has a line with non-ascii that is in UTF-8), and many editors would not like such a file.

I agree, there was issues when I edited that file

Quoted 7 lines

Perhaps we should update test_format so that we can feed a quoted input, e.g.

    +include an iso8859-1 character: <A1>bueno!

or something?

We could use this file whole in UTF-8 but just make a conversion of expected output as it's done a few lines above with a commit message (stored to a file 'commit-msg' before the test 'setup complex body').
+iconv -f utf-8 -t iso8859-1 > commit-msg <<EOF
+Test printing of complex bodies
We can even use content of that file (as far as it's kept untouched between that tests)

Quoted 23 lines
Quoted 23 lines
t/t6006-rev-list-format.sh +13 -1
+commit $head2
+commit $head1
+EOF
+
+# Git uses i18n.commitEncoding if no i18n.logOutputEncoding set
+# so unset i18n.commitEncoding to test encoding conversion
+git config --unset i18n.commitEncoding
+
+test_format complex-subject-commitencoding-unset %s <<EOF
+commit $head3
+Test printing of complex bodies
+commit $head2
 $changed
 commit $head1
 $added
 EOF
 
-test_format complex-body %b <<EOF
+test_format complex-body-commitencoding-unset %b <<EOF
 commit $head3
 This commit message is much longer than the others,
 and it will be encoded in iso8859-1. We should therefore
Signature · 1 line
Alexey Shumkin
#92 lore raw

Re: [PATCH v9 4/5] t6006: add two more tests for the case i18n.commitEncoding is not set

Quoted 11 lines · Alexey Shumkin
Quoted 6 lines

Perhaps we should update test_format so that we can feed a quoted input, e.g.

    +include an iso8859-1 character: <A1>bueno!

or something?

We could use this file whole in UTF-8 but just make a conversion of expected output as it's done a few lines above with a commit message (stored to a file 'commit-msg' before the test 'setup complex body').
+iconv -f utf-8 -t iso8859-1 > commit-msg <<EOF
+Test printing of complex bodies

That is way better than my <A1>bueno!.

Thanks.

#93 lore raw

Re: [PATCH v9 4/5] t6006: add two more tests for the case i18n.commitEncoding is not set

In reply to Alexey Shumkin
Quoted 2 lines · Alexey Shumkin

In de6029a2d7734a93a9e27b9c4471862a47dd8123 'complex-subject' test was changed. Revert it back,...

... "because changing it was bad for such and such reasons"?

#94 lore raw

v10 cover Incremental updates against 'next' branch

In reply to Alexey Shumkin

This patches series includes following changes against v9
1. [PATCH v10 1/5] t4041, t4205, t6006, t7102: use iso8859-1 rather than iso-8859-1
reworded. reasons of renaming explained "here and now" but not only
redirects to an older commit which did the same.
2. [PATCH v10 2/5] t4205 (log-pretty-formats): revert back single quotes
little change to commit message (added "(log-pretty-formats)" after
"t4205")
3. [PATCH v10 3/5] t4205, t6006, t7102: make functions better readable
reworded. comments reformatted. function 'test_format' refactored.
4. [PATCH v10 4/5] t6006 (rev-list-format): add tests for "%b" and "%s" for the case i18n.commitEncoding is not set reworded. Now whole file is in utf-8. Tested output messages are
converted from utf-8 to iso8859-1 "on the fly" and written fo files.
5. [PATCH v10 5/5] t4205 (log-pretty-formats): avoid using sed
little change to commit message (added "(log-pretty-formats)" after
"t4205")

And references to "de6029a2d7734a93a9e27b9c4471862a47dd8123" commit in all patch messages replaced with "de6029a (pretty: Add failing
tests: --format output should honor logOutputEncoding, 2013-06-26)"

P.S. This patch series is an incremental updates on top of (7c375214 t4205:
replace .\+ with ..* in sed commands, 2013-07-01) as far as v7 patches were applied to the 'next' branch but there were more improvements made in v8.

Alexey Shumkin (5):
t4041, t4205, t6006, t7102: use iso8859-1 rather than iso-8859-1 t4205 (log-pretty-formats): revert back single quotes t4205, t6006, t7102: make functions better readable t6006 (rev-list-format): add tests for "%b" and "%s" for the case
i18n.commitEncoding is not set
t4205 (log-pretty-formats): avoid using sed

 t/t4041-diff-submodule-option.sh |   4 +-
 t/t4205-log-pretty-formats.sh    | 143 +++++++++++++++++++--------------------
 t/t6006-rev-list-format.sh       |  83 ++++++++++++-----------
 t/t7102-reset.sh                 |  20 +++---
 4 files changed, 125 insertions(+), 125 deletions(-)
Signature · 1 line
1.8.3.2.16.gb1f0d63
#95 lore raw

PATCH v10 1/5 t4041, t4205, t6006, t7102: use iso8859-1 rather than iso-8859-1

Both "iso8859-1" and "iso-8859-1" are understood as latin-1 by modern platforms, but the latter is not understood by older platforms; update tests to use the former.

This is in line with 3994e8a9 (t4201: use ISO8859-1 rather than ISO-8859-1, 2009-12-03), which did the same.

---
 t/t4041-diff-submodule-option.sh |  4 ++--
 t/t4205-log-pretty-formats.sh    |  8 ++++----
 t/t6006-rev-list-format.sh       | 14 +++++++-------
 t/t7102-reset.sh                 | 10 +++++-----
 4 files changed, 18 insertions(+), 18 deletions(-)
t/t4041-diff-submodule-option.sh +2 -2
index 0a4f496..1751c83 100755
@@ -23,8 +23,8 @@ add_file () {
 			echo "$name" >"$name" &&
 			git add "$name" &&
 			test_tick &&
-			msg_added_iso88591=$(echo "Add $name ($added $name)" | iconv -f utf-8 -t iso-8859-1) &&
-			git -c 'i18n.commitEncoding=iso-8859-1' commit -m "$msg_added_iso88591"
+			msg_added_iso88591=$(echo "Add $name ($added $name)" | iconv -f utf-8 -t iso8859-1) &&
+			git -c 'i18n.commitEncoding=iso8859-1' commit -m "$msg_added_iso88591"
 		done >/dev/null &&
 		git rev-parse --short --verify HEAD
 	)
t/t4205-log-pretty-formats.sh +4 -4
index 3cfb744..c283842 100755
@@ -32,8 +32,8 @@ test_expect_success 'set up basic repos' '
 	>bar &&
 	git add foo &&
 	test_tick &&
-	git config i18n.commitEncoding iso-8859-1 &&
-	git commit -m "$(commit_msg iso-8859-1)" &&
+	git config i18n.commitEncoding iso8859-1 &&
+	git commit -m "$(commit_msg iso8859-1)" &&
 	git add bar &&
 	test_tick &&
 	git commit -m "add bar" &&
@@ -61,8 +61,8 @@ test_expect_success 'alias user-defined format' '
 	test_cmp expected actual
 '
 
-test_expect_success 'alias user-defined tformat with %s (iso-8859-1 encoding)' '
-	git config i18n.logOutputEncoding iso-8859-1 &&
+test_expect_success 'alias user-defined tformat with %s (iso8859-1 encoding)' '
+	git config i18n.logOutputEncoding iso8859-1 &&
 	git log --oneline >expected-s &&
 	git log --pretty="tformat:%h %s" >actual-s &&
 	git config --unset i18n.logOutputEncoding &&
t/t6006-rev-list-format.sh +7 -7
index 380c85b..4751d22 100755
@@ -12,15 +12,15 @@ test_tick
 # String "added" in German (translated with Google Translate), encoded in UTF-8,
 # used as a commit log message below.
 added=$(printf "added (hinzugef\303\274gt) foo")
-added_iso88591=$(echo "$added" | iconv -f utf-8 -t iso-8859-1)
+added_iso88591=$(echo "$added" | iconv -f utf-8 -t iso8859-1)
 # same but "changed"
 changed=$(printf "changed (ge\303\244ndert) foo")
-changed_iso88591=$(echo "$changed" | iconv -f utf-8 -t iso-8859-1)
+changed_iso88591=$(echo "$changed" | iconv -f utf-8 -t iso8859-1)
 
 test_expect_success 'setup' '
 	: >foo &&
 	git add foo &&
-	git config i18n.commitEncoding iso-8859-1 &&
+	git config i18n.commitEncoding iso8859-1 &&
 	git commit -m "$added_iso88591" &&
 	head1=$(git rev-parse --verify HEAD) &&
 	head1_short=$(git rev-parse --verify --short $head1) &&
@@ -136,9 +136,9 @@ EOF
 
 test_format encoding %e <<EOF
 commit $head2
-iso-8859-1
+iso8859-1
 commit $head1
-iso-8859-1
+iso8859-1
 EOF
 
 test_format subject %s <<EOF
@@ -242,9 +242,9 @@ test_format complex-encoding %e <<EOF
 commit $head3
 iso8859-1
 commit $head2
-iso-8859-1
+iso8859-1
 commit $head1
-iso-8859-1
+iso8859-1
 EOF
 
 test_format complex-subject %s <<EOF
t/t7102-reset.sh +5 -5
index 9132dd9..2ef96e9 100755
@@ -39,7 +39,7 @@ test_expect_success 'creating initial files and commits' '
 
 	echo "1st line 2nd file" >secondfile &&
 	echo "2nd line 2nd file" >>secondfile &&
-	git -c "i18n.commitEncoding=iso-8859-1" commit -a -m "$(commit_msg iso-8859-1)" &&
+	git -c "i18n.commitEncoding=iso8859-1" commit -a -m "$(commit_msg iso8859-1)" &&
 	head5=$(git rev-parse --verify HEAD)
 '
 # git log --pretty=oneline # to see those SHA1 involved
@@ -62,10 +62,10 @@ test_expect_success 'reset --hard message' '
 	test_cmp .expected .actual
 '
 
-test_expect_success 'reset --hard message (iso-8859-1 logoutencoding)' '
+test_expect_success 'reset --hard message (iso8859-1 logoutputencoding)' '
 	hex=$(git log -1 --format="%h") &&
-	git -c "i18n.logOutputEncoding=iso-8859-1" reset --hard > .actual &&
-	echo HEAD is now at $hex $(commit_msg iso-8859-1) > .expected &&
+	git -c "i18n.logOutputEncoding=iso8859-1" reset --hard > .actual &&
+	echo HEAD is now at $hex $(commit_msg iso8859-1) > .expected &&
 	test_cmp .expected .actual
 '
 
@@ -329,7 +329,7 @@ test_expect_success 'redoing the last two commits should succeed' '
 
 	echo "1st line 2nd file" >secondfile &&
 	echo "2nd line 2nd file" >>secondfile &&
-	git -c "i18n.commitEncoding=iso-8859-1" commit -a -m "$(commit_msg iso-8859-1)" &&
+	git -c "i18n.commitEncoding=iso8859-1" commit -a -m "$(commit_msg iso8859-1)" &&
 	check_changes $head5
 '
 
Signature · 1 line
1.8.3.2.16.gb1f0d63
#96 lore raw

PATCH v10 2/5 t4205 (log-pretty-formats): revert back single quotes

In reply to Alexey Shumkin

In previuos commit de6029a (pretty: Add failing tests: --format output should honor logOutputEncoding, 2013-06-26) single quotes were replaced with double quotes to make "$(commit_msg)" expression in heredoc to work. The same effect can be achieved by using "EOF" as a heredoc delimiter instead of "\EOF".

---
 t/t4205-log-pretty-formats.sh | 106 +++++++++++++++++++++---------------------
 1 file changed, 53 insertions(+), 53 deletions(-)
t/t4205-log-pretty-formats.sh +53 -53
index c283842..ef9770a 100755
@@ -145,174 +145,174 @@ test_expect_success 'setup more commits' '
 	head4=$(git rev-parse --verify --short HEAD~3)
 '
 
-test_expect_success 'left alignment formatting' "
-	git log --pretty='format:%<(40)%s' >actual &&
+test_expect_success 'left alignment formatting' '
+	git log --pretty="format:%<(40)%s" >actual &&
 	# complete the incomplete line at the end
 	echo >>actual &&
-	qz_to_tab_space <<\EOF >expected &&
+	qz_to_tab_space <<EOF >expected &&
 message two                            Z
 message one                            Z
 add bar                                Z
 $(commit_msg)                    Z
 EOF
 	test_cmp expected actual
-"
+'
 
-test_expect_success 'left alignment formatting at the nth column' "
-	git log --pretty='format:%h %<|(40)%s' >actual &&
+test_expect_success 'left alignment formatting at the nth column' '
+	git log --pretty="format:%h %<|(40)%s" >actual &&
 	# complete the incomplete line at the end
 	echo >>actual &&
-	qz_to_tab_space <<\EOF >expected &&
+	qz_to_tab_space <<EOF >expected &&
 $head1 message two                    Z
 $head2 message one                    Z
 $head3 add bar                        Z
 $head4 $(commit_msg)            Z
 EOF
 	test_cmp expected actual
-"
+'
 
-test_expect_success 'left alignment formatting with no padding' "
-	git log --pretty='format:%<(1)%s' >actual &&
+test_expect_success 'left alignment formatting with no padding' '
+	git log --pretty="format:%<(1)%s" >actual &&
 	# complete the incomplete line at the end
 	echo >>actual &&
-	cat <<\EOF >expected &&
+	cat <<EOF >expected &&
 message two
 message one
 add bar
 $(commit_msg)
 EOF
 	test_cmp expected actual
-"
+'
 
-test_expect_success 'left alignment formatting with trunc' "
-	git log --pretty='format:%<(10,trunc)%s' >actual &&
+test_expect_success 'left alignment formatting with trunc' '
+	git log --pretty="format:%<(10,trunc)%s" >actual &&
 	# complete the incomplete line at the end
 	echo >>actual &&
-	qz_to_tab_space <<\EOF >expected &&
+	qz_to_tab_space <<EOF >expected &&
 message ..
 message ..
 add bar  Z
 $(commit_msg "" "8" "..*$")
 EOF
 	test_cmp expected actual
-"
+'
 
-test_expect_success 'left alignment formatting with ltrunc' "
-	git log --pretty='format:%<(10,ltrunc)%s' >actual &&
+test_expect_success 'left alignment formatting with ltrunc' '
+	git log --pretty="format:%<(10,ltrunc)%s" >actual &&
 	# complete the incomplete line at the end
 	echo >>actual &&
-	qz_to_tab_space <<\EOF >expected &&
+	qz_to_tab_space <<EOF >expected &&
 ..sage two
 ..sage one
 add bar  Z
 $(commit_msg "" "0" ".\{11\}")
 EOF
 	test_cmp expected actual
-"
+'
 
-test_expect_success 'left alignment formatting with mtrunc' "
-	git log --pretty='format:%<(10,mtrunc)%s' >actual &&
+test_expect_success 'left alignment formatting with mtrunc' '
+	git log --pretty="format:%<(10,mtrunc)%s" >actual &&
 	# complete the incomplete line at the end
 	echo >>actual &&
-	qz_to_tab_space <<\EOF >expected &&
+	qz_to_tab_space <<EOF >expected &&
 mess.. two
 mess.. one
 add bar  Z
 $(commit_msg "" "4" ".\{11\}")
 EOF
 	test_cmp expected actual
-"
+'
 
-test_expect_success 'right alignment formatting' "
-	git log --pretty='format:%>(40)%s' >actual &&
+test_expect_success 'right alignment formatting' '
+	git log --pretty="format:%>(40)%s" >actual &&
 	# complete the incomplete line at the end
 	echo >>actual &&
-	qz_to_tab_space <<\EOF >expected &&
+	qz_to_tab_space <<EOF >expected &&
 Z                            message two
 Z                            message one
 Z                                add bar
 Z                    $(commit_msg)
 EOF
 	test_cmp expected actual
-"
+'
 
-test_expect_success 'right alignment formatting at the nth column' "
-	git log --pretty='format:%h %>|(40)%s' >actual &&
+test_expect_success 'right alignment formatting at the nth column' '
+	git log --pretty="format:%h %>|(40)%s" >actual &&
 	# complete the incomplete line at the end
 	echo >>actual &&
-	qz_to_tab_space <<\EOF >expected &&
+	qz_to_tab_space <<EOF >expected &&
 $head1                      message two
 $head2                      message one
 $head3                          add bar
 $head4              $(commit_msg)
 EOF
 	test_cmp expected actual
-"
+'
 
-test_expect_success 'right alignment formatting with no padding' "
-	git log --pretty='format:%>(1)%s' >actual &&
+test_expect_success 'right alignment formatting with no padding' '
+	git log --pretty="format:%>(1)%s" >actual &&
 	# complete the incomplete line at the end
 	echo >>actual &&
-	cat <<\EOF >expected &&
+	cat <<EOF >expected &&
 message two
 message one
 add bar
 $(commit_msg)
 EOF
 	test_cmp expected actual
-"
+'
 
-test_expect_success 'center alignment formatting' "
-	git log --pretty='format:%><(40)%s' >actual &&
+test_expect_success 'center alignment formatting' '
+	git log --pretty="format:%><(40)%s" >actual &&
 	# complete the incomplete line at the end
 	echo >>actual &&
-	qz_to_tab_space <<\EOF >expected &&
+	qz_to_tab_space <<EOF >expected &&
 Z             message two              Z
 Z             message one              Z
 Z               add bar                Z
 Z         $(commit_msg)          Z
 EOF
 	test_cmp expected actual
-"
+'
 
-test_expect_success 'center alignment formatting at the nth column' "
-	git log --pretty='format:%h %><|(40)%s' >actual &&
+test_expect_success 'center alignment formatting at the nth column' '
+	git log --pretty="format:%h %><|(40)%s" >actual &&
 	# complete the incomplete line at the end
 	echo >>actual &&
-	qz_to_tab_space <<\EOF >expected &&
+	qz_to_tab_space <<EOF >expected &&
 $head1           message two          Z
 $head2           message one          Z
 $head3             add bar            Z
 $head4       $(commit_msg)      Z
 EOF
 	test_cmp expected actual
-"
+'
 
-test_expect_success 'center alignment formatting with no padding' "
-	git log --pretty='format:%><(1)%s' >actual &&
+test_expect_success 'center alignment formatting with no padding' '
+	git log --pretty="format:%><(1)%s" >actual &&
 	# complete the incomplete line at the end
 	echo >>actual &&
-	cat <<\EOF >expected &&
+	cat <<EOF >expected &&
 message two
 message one
 add bar
 $(commit_msg)
 EOF
 	test_cmp expected actual
-"
+'
 
-test_expect_success 'left/right alignment formatting with stealing' "
-	git commit --amend -m short --author 'long long long <[email protected]>' &&
-	git log --pretty='format:%<(10,trunc)%s%>>(10,ltrunc)% an' >actual &&
+test_expect_success 'left/right alignment formatting with stealing' '
+	git commit --amend -m short --author "long long long <[email protected]>" &&
+	git log --pretty="format:%<(10,trunc)%s%>>(10,ltrunc)% an" >actual &&
 	# complete the incomplete line at the end
 	echo >>actual &&
-	cat <<\EOF >expected &&
+	cat <<EOF >expected &&
 short long  long long
 message ..   A U Thor
 add bar      A U Thor
 $(commit_msg "" "8" "..*$")   A U Thor
 EOF
 	test_cmp expected actual
-"
+'
 
 test_done
Signature · 1 line
1.8.3.2.16.gb1f0d63
#97 lore raw

PATCH v10 3/5 t4205, t6006, t7102: make functions better readable

In reply to Alexey Shumkin

Function 'test_format' has become harder to read after its change in de6029a2 (pretty: Add failing tests: --format output should honor logOutputEncoding, 2013-06-26). Simplify it by moving its "should we expect it to fail?" parameter to the end.

Note, current code does not use this last parameter as far as there are no tests expected to fail. We can keep that for future use.

Also, reformat comments

---
 t/t4205-log-pretty-formats.sh |  3 ++-
 t/t6006-rev-list-format.sh    | 28 ++++++++--------------------
 t/t7102-reset.sh              | 10 ++++++----
 3 files changed, 16 insertions(+), 25 deletions(-)
t/t4205-log-pretty-formats.sh +2 -1
index ef9770a..2933c63 100755
@@ -8,7 +8,8 @@ test_description='Test pretty formats'
 . ./test-lib.sh
 
 commit_msg () {
-	# String "initial. initial" partly in German (translated with Google Translate),
+	# String "initial. initial" partly in German
+	# (translated with Google Translate),
 	# encoded in UTF-8, used as a commit log message below.
 	msg=$(printf "initial. anf\303\244nglich")
 	if test -n "$1"
t/t6006-rev-list-format.sh +8 -20
index 4751d22..b32405a 100755
@@ -9,8 +9,9 @@ test_description='git rev-list --pretty=format test'
 . "$TEST_DIRECTORY"/lib-terminal.sh
 
 test_tick
-# String "added" in German (translated with Google Translate), encoded in UTF-8,
-# used as a commit log message below.
+# String "added" in German
+# (translated with Google Translate),
+# encoded in UTF-8, used as a commit log message below.
 added=$(printf "added (hinzugef\303\274gt) foo")
 added_iso88591=$(echo "$added" | iconv -f utf-8 -t iso8859-1)
 # same but "changed"
@@ -35,26 +36,13 @@ test_expect_success 'setup' '
 	git config --unset i18n.commitEncoding
 '
 
-# usage: test_format [failure] name format_string <expected_output
+# usage: test_format name format_string [failure] <expected_output
 test_format () {
-	must_fail=0
-	# if parameters count is more than 2 then test must fail
-	if test $# -gt 2
-	then
-		must_fail=1
-		# remove first parameter which is flag for test failure
-		shift
-	fi
 	cat >expect.$1
-	name="format $1"
-	command="git rev-list --pretty=format:'$2' master >output.$1 &&
-		test_cmp expect.$1 output.$1"
-	if test $must_fail -eq 1
-	then
-		test_expect_failure "$name" "$command"
-	else
-		test_expect_success "$name" "$command"
-	fi
+	test_expect_${3:-success} "format $1" "
+		git rev-list --pretty=format:'$2' master >output.$1 &&
+		test_cmp expect.$1 output.$1
+	"
 }
 
 # Feed to --format to provide predictable colored sequences.
t/t7102-reset.sh +6 -4
index 2ef96e9..535e609 100755
@@ -10,14 +10,16 @@ Documented tests for git reset'
 . ./test-lib.sh
 
 commit_msg () {
-	# String "modify 2nd file (changed)" partly in German(translated with Google Translate),
+	# String "modify 2nd file (changed)" partly in German
+	# (translated with Google Translate),
 	# encoded in UTF-8, used as a commit log message below.
-	msg=$(printf "modify 2nd file (ge\303\244ndert)")
+	msg="modify 2nd file (ge\303\244ndert)"
 	if test -n "$1"
 	then
-		msg=$(echo $msg | iconv -f utf-8 -t $1)
+		print "$msg" | iconv -f utf-8 -t "$1"
+	else
+		print "$msg"
 	fi
-	echo $msg
 }
 
 test_expect_success 'creating initial files and commits' '
Signature · 1 line
1.8.3.2.16.gb1f0d63
#98 lore raw

Re: [PATCH v10 3/5] t4205, t6006, t7102: make functions better readable

t/t7102-reset.sh Documented tests for git reset' · line 23

Quoted 11 lines · Alexey Shumkin
t/t7102-reset.sh +4 -3
-	msg=$(printf "modify 2nd file (ge\303\244ndert)")
+	msg="modify 2nd file (ge\303\244ndert)"
 	if test -n "$1"
 	then
-		msg=$(echo $msg | iconv -f utf-8 -t $1)
+		print "$msg" | iconv -f utf-8 -t "$1"
+	else
+		print "$msg"
 	fi
-	echo $msg
 }

I think I'll do s/print/&f/ before queuing this.

Thanks.

#99 lore raw

Re: [PATCH v10 3/5] t4205, t6006, t7102: make functions better readable

Quoted 15 lines · Junio C Hamano

t/t7102-reset.sh Documented tests for git reset' · line 23

Quoted 11 lines · Alexey Shumkin
t/t7102-reset.sh +4 -3
-	msg=$(printf "modify 2nd file (ge\303\244ndert)")
+	msg="modify 2nd file (ge\303\244ndert)"
 	if test -n "$1"
 	then
-		msg=$(echo $msg | iconv -f utf-8 -t $1)
+		print "$msg" | iconv -f utf-8 -t "$1"
+	else
+		print "$msg"
 	fi
-	echo $msg
 }

I think I'll do s/print/&f/ before queuing this.

Also, I'll change the $msg constant to have \n at the end, as we are losing it by bypassing "echo".

#100 lore raw

PATCH v10 4/5 t6006 (rev-list-format): add tests for "%b" and "%s" for the case i18n.commitEncoding is not set

In reply to Alexey Shumkin

In de6029a (pretty: Add failing tests: --format output should honor logOutputEncoding, 2013-06-26) 'complex-subject' test was changed. Revert it back, because that change actually removed tests for "%b" and "%s" with i18n.commitEncoding set.
Also, add two more tests for mentioned above "%b" and "%s" to test encoding conversions with no i18n.commitEncoding set.

---
 t/t6006-rev-list-format.sh | 41 ++++++++++++++++++++++++++++-------------
 1 file changed, 28 insertions(+), 13 deletions(-)
t/t6006-rev-list-format.sh +28 -13
index b32405a..e51d0f0 100755
@@ -218,12 +218,7 @@ test_expect_success 'setup complex body' '
 	git config i18n.commitencoding iso8859-1 &&
 	echo change2 >foo && git commit -a -F commit-msg &&
 	head3=$(git rev-parse --verify HEAD) &&
-	head3_short=$(git rev-parse --short $head3) &&
-	# unset commit encoding config
-	# otherwise %e does not print encoding value
-	# and following test fails
-	git config --unset i18n.commitEncoding
-
+	head3_short=$(git rev-parse --short $head3)
 '
 
 test_format complex-encoding %e <<EOF
@@ -239,21 +234,41 @@ test_format complex-subject %s <<EOF
 commit $head3
 Test printing of complex bodies
 commit $head2
-$changed
+$changed_iso88591
 commit $head1
-$added
+$added_iso88591
 EOF
 
-test_format complex-body %b <<EOF
-commit $head3
-This commit message is much longer than the others,
-and it will be encoded in iso8859-1. We should therefore
-include an iso8859 character: ¡bueno!
+test_expect_success 'prepare expected messages (for test %b)' '
+    cat <<-EOF >expected.utf-8 &&
+	commit $head3
+	This commit message is much longer than the others,
+	and it will be encoded in iso8859-1. We should therefore
+	include an iso8859 character: ¡bueno!
+
+	commit $head2
+	commit $head1
+EOF
+	iconv -f utf-8 -t iso8859-1 expected.utf-8 >expected.iso8859-1
+'
+
+test_format complex-body %b <expected.iso8859-1
 
+# Git uses i18n.commitEncoding if no i18n.logOutputEncoding set
+# so unset i18n.commitEncoding to test encoding conversion
+git config --unset i18n.commitEncoding
+
+test_format complex-subject-commitencoding-unset %s <<EOF
+commit $head3
+Test printing of complex bodies
 commit $head2
+$changed
 commit $head1
+$added
 EOF
 
+test_format complex-body-commitencoding-unset %b <expected.utf-8
+
 test_expect_success '%x00 shows NUL' '
 	echo  >expect commit $head3 &&
 	echo >>expect fooQbar &&
Signature · 1 line
1.8.3.2.16.gb1f0d63
#101 lore raw

PATCH v10 5/5 t4205 (log-pretty-formats): avoid using `sed`

In reply to Alexey Shumkin

For testing truncated log messages 'commit_msg' function uses sed to cut a message. On various platforms sed behaves differently and results of its work depend on locales installed. So, avoid using sed. Use predefined expected outputs instead of calculated ones.

---
 t/t4205-log-pretty-formats.sh | 26 ++++++++++----------------
 1 file changed, 10 insertions(+), 16 deletions(-)
t/t4205-log-pretty-formats.sh +10 -16
index 2933c63..73fd236 100755
@@ -7,25 +7,19 @@
 test_description='Test pretty formats'
 . ./test-lib.sh
 
+sample_utf8_part=$(printf "f\303\244ng")
+
 commit_msg () {
 	# String "initial. initial" partly in German
 	# (translated with Google Translate),
 	# encoded in UTF-8, used as a commit log message below.
-	msg=$(printf "initial. anf\303\244nglich")
+	msg="initial. an${sample_utf8_part}lich"
 	if test -n "$1"
 	then
-		msg=$(echo $msg | iconv -f utf-8 -t $1)
-	fi
-	if test -n "$2" -a -n "$3"
-	then
-		# cut string, replace cut part with two dots
-		# $2 - chars count from the beginning of the string
-		# $3 - "trailing" chars
-		# LC_ALL is set to make `sed` interpret "." as a UTF-8 char not a byte
-		# as it does with C locale
-		msg=$(echo $msg | LC_ALL=en_US.UTF-8 sed -e "s/^\(.\{$2\}\)$3/\1../")
+		print $msg | iconv -f utf-8 -t "$1"
+	else
+		print $msg
 	fi
-	echo $msg
 }
 
 test_expect_success 'set up basic repos' '
@@ -193,7 +187,7 @@ test_expect_success 'left alignment formatting with trunc' '
 message ..
 message ..
 add bar  Z
-$(commit_msg "" "8" "..*$")
+initial...
 EOF
 	test_cmp expected actual
 '
@@ -206,7 +200,7 @@ test_expect_success 'left alignment formatting with ltrunc' '
 ..sage two
 ..sage one
 add bar  Z
-$(commit_msg "" "0" ".\{11\}")
+..${sample_utf8_part}lich
 EOF
 	test_cmp expected actual
 '
@@ -219,7 +213,7 @@ test_expect_success 'left alignment formatting with mtrunc' '
 mess.. two
 mess.. one
 add bar  Z
-$(commit_msg "" "4" ".\{11\}")
+init..lich
 EOF
 	test_cmp expected actual
 '
@@ -311,7 +305,7 @@ test_expect_success 'left/right alignment formatting with stealing' '
 short long  long long
 message ..   A U Thor
 add bar      A U Thor
-$(commit_msg "" "8" "..*$")   A U Thor
+initial...   A U Thor
 EOF
 	test_cmp expected actual
 '
Signature · 1 line
1.8.3.2.16.gb1f0d63
#102 lore raw

PATCH v9 5/5 t4205: avoid using `sed`

In reply to Alexey Shumkin

For testing truncated log messages 'commit_msg' function uses sed to cut a message. On various platforms sed behaves differently and results of its work depend on locales installed. So, avoid using sed. Use predefined expected outputs instead of calculated ones.

---
 t/t4205-log-pretty-formats.sh | 26 ++++++++++----------------
 1 file changed, 10 insertions(+), 16 deletions(-)
t/t4205-log-pretty-formats.sh +10 -16
index bb87f02..8504b13 100755
@@ -7,25 +7,19 @@
 test_description='Test pretty formats'
 . ./test-lib.sh
 
+sample_utf8_part=$(printf "f\303\244ng")
+
 commit_msg() {
 	# String "initial. initial" partly in German
 	# (translated with Google Translate),
 	# encoded in UTF-8, used as a commit log message below.
-	msg=$(printf "initial. anf\303\244nglich")
+	msg="initial. an${sample_utf8_part}lich"
 	if test -n "$1"
 	then
-		msg=$(echo $msg | iconv -f utf-8 -t $1)
-	fi
-	if test -n "$2" -a -n "$3"
-	then
-		# cut string, replace cut part with two dots
-		# $2 - chars count from the beginning of the string
-		# $3 - "trailing" chars
-		# LC_ALL is set to make `sed` interpret "." as a UTF-8 char not a byte
-		# as it does with C locale
-		msg=$(echo $msg | LC_ALL=en_US.UTF-8 sed -e "s/^\(.\{$2\}\)$3/\1../")
+		echo $msg | iconv -f utf-8 -t $1
+	else
+		echo $msg
 	fi
-	echo $msg
 }
 
 test_expect_success 'set up basic repos' '
@@ -193,7 +187,7 @@ test_expect_success 'left alignment formatting with trunc' '
 message ..
 message ..
 add bar  Z
-$(commit_msg "" "8" "..*$")
+initial...
 EOF
 	test_cmp expected actual
 '
@@ -206,7 +200,7 @@ test_expect_success 'left alignment formatting with ltrunc' '
 ..sage two
 ..sage one
 add bar  Z
-$(commit_msg "" "0" ".\{11\}")
+..${sample_utf8_part}lich
 EOF
 	test_cmp expected actual
 '
@@ -219,7 +213,7 @@ test_expect_success 'left alignment formatting with mtrunc' '
 mess.. two
 mess.. one
 add bar  Z
-$(commit_msg "" "4" ".\{11\}")
+init..lich
 EOF
 	test_cmp expected actual
 '
@@ -311,7 +305,7 @@ test_expect_success 'left/right alignment formatting with stealing' '
 short long  long long
 message ..   A U Thor
 add bar      A U Thor
-$(commit_msg "" "8" "..*$")   A U Thor
+initial...   A U Thor
 EOF
 	test_cmp expected actual
 '
Signature · 1 line
1.8.3.1.15.g5c23c1e
#103 lore raw

PATCH v3 2/2 pretty: user format ignores i18n.logOutputEncoding setting

In reply to Alexey Shumkin

The following two ought to give the same output to a terminal:

	$ git log --oneline --no-color
	$ git log --pretty=format:'%h %s'

However, the former pays attention to i18n.logOutputEncoding configuration, while the latter does not when it format "%s". A log messages written in an encoding i18n.commitEncoding that differs from terminal encoding are shown corrupted with the latter even when i18n.logOutputEncoding and terminal encoding are the same.

The same corruption is true for

	$ git diff --submodule=log
and
	$ git rev-list --pretty=format:%s HEAD
---
 builtin/rev-list.c |    1 +
 builtin/shortlog.c |    1 +
 log-tree.c         |    1 +
 submodule.c        |    3 +++
 4 files changed, 6 insertions(+), 0 deletions(-)
builtin/rev-list.c +1 -0
index 56727e8..831077d 100644
@@ -105,6 +105,7 @@ static void show_commit(struct commit *commit, void *data)
 		ctx.abbrev = revs->abbrev;
 		ctx.date_mode = revs->date_mode;
 		ctx.fmt = revs->commit_format;
+		ctx.output_encoding = get_log_output_encoding();
 		pretty_print_commit(&ctx, commit, &buf);
 		if (revs->graph) {
 			if (buf.len) {
builtin/shortlog.c +1 -0
index 37f3193..eba4086 100644
@@ -163,6 +163,7 @@ void shortlog_add_commit(struct shortlog *log, struct commit *commit)
 		ctx.subject = "";
 		ctx.after_subject = "";
 		ctx.date_mode = DATE_NORMAL;
+		ctx.output_encoding = get_log_output_encoding();
 		pretty_print_commit(&ctx, commit, &ufbuf);
 		buffer = ufbuf.buf;
 	} else if (*buffer) {
log-tree.c +1 -0
index e945701..39913d7 100644
@@ -488,6 +488,7 @@ void show_log(struct rev_info *opt)
 	ctx.preserve_subject = opt->preserve_subject;
 	ctx.reflog_info = opt->reflog_info;
 	ctx.fmt = opt->commit_format;
+	ctx.output_encoding = get_log_output_encoding();
 	pretty_print_commit(&ctx, commit, &msgbuf);
 
 	if (opt->add_signoff)
submodule.c +3 -0
index b6dec70..26efef4 100644
@@ -213,10 +213,13 @@ static void print_submodule_summary(struct rev_info *rev, FILE *f,
 	static const char format[] = "  %m %s";
 	struct strbuf sb = STRBUF_INIT;
 	struct commit *commit;
+	const char *log_output_encoding;
 
+	log_output_encoding = get_log_output_encoding();
 	while ((commit = get_revision(rev))) {
 		struct pretty_print_context ctx = {0};
 		ctx.date_mode = rev->date_mode;
+		ctx.output_encoding = log_output_encoding;
 		strbuf_setlen(&sb, 0);
 		if (commit->object.flags & SYMMETRIC_LEFT) {
 			if (del)
Signature · 1 line
1.7.6.1.g8f21c