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

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

From
Alexey Shumkin <alex.crezoff@gmail.com>
Date
Jul 1, 2013, 22:50 UTC
Message-ID
<20130701225013.GA17377@ashu.dyn1.rarus.ru>
In-Reply-To
<51D12927.5050000@viscovery.net>
On Mon, Jul 01, 2013 at 09:00:55AM +0200, Johannes Sixt wrote:
Show 61 quoted lines
> Am 6/26/2013 12:19, schrieb 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.
> > 
> > Signed-off-by: Alexey Shumkin <Alex.Crezoff@gmail.com>
> 
> > diff --git a/t/t4205-log-pretty-formats.sh b/t/t4205-log-pretty-formats.sh
> > index 73ba5e8..6b62da2 100755
> > --- a/t/t4205-log-pretty-formats.sh
> > +++ b/t/t4205-log-pretty-formats.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../")
> 
> 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.
> 

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

Show 22 quoted lines
> > +	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
> > -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

> 
> 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
Show 19 quoted lines
> 
> > diff --git a/t/t6006-rev-list-format.sh b/t/t6006-rev-list-format.sh
> > index cc1008d..c66a07f 100755
> > --- a/t/t6006-rev-list-format.sh
> > +++ b/t/t6006-rev-list-format.sh
> ...
> >  test_expect_success 'setup' '
> >  	: >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.

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

Show 53 quoted lines
> 
> > +	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
> > -	"
> > +	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
> 	"
Thank you for your suggesstion
Show 15 quoted lines
> }
> 
> >  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)
> > +	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

Show 13 quoted 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.
> 
> > +	git config --unset i18n.commitEncoding
> > +
> >  '
> >  
> >  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

Show 42 quoted lines
> 
> >  commit $head2
> > +iso-8859-1
> >  commit $head1
> > +iso-8859-1
> >  EOF
> 
> > diff --git a/t/t7102-reset.sh b/t/t7102-reset.sh
> > index 05dfb27..72e364e 100755
> > --- a/t/t7102-reset.sh
> > +++ b/t/t7102-reset.sh
> > @@ -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
> > +}
> 
> 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.
It looks more readable. Thank you
> 
> -- Hannes
-- 
Alexey Shumkin
Previous: Johannes SixtNext: Johannes Sixt
Message 47 of 82 in “pretty: Add failing tests: user format ignores i18n.logOutputEncoding setting”
  1. 1/2 pretty: Add failing tests: user format ignores i18n.logOutputEncoding settingAlexey Shumkin, Sep 20, 2011
  2. 2/2 pretty: user format ignores i18n.logOutputEncoding settingAlexey Shumkin, Sep 20, 2011
  3. Junio C HamanoSep 20, 2011
  4. Alexey ShumkinSep 20, 2011
  5. 0/4 Reroll patches against v1.8.1.1Alexey Shumkin, Jan 24, 2013
  6. 1/4 t6006 (rev-list-format): don't hardcode SHA-1 in expected outputsAlexey Shumkin, Jan 24, 2013
  7. Junio C HamanoJan 24, 2013
  8. Alexey ShumkinJan 25, 2013
  9. Alexey ShumkinJan 25, 2013
  10. Junio C HamanoJan 25, 2013
  11. Alexey ShumkinJan 25, 2013
  12. 2/4 t7102 (reset): refactoring: don't hardcode SHA-1 in expected outputsAlexey Shumkin, Jan 24, 2013
  13. Junio C HamanoJan 24, 2013
  14. Alexey ShumkinJan 25, 2013
  15. 3/4 pretty: Add failing tests: user format ignores i18n.logOutputEncoding settingAlexey Shumkin, Jan 24, 2013
  16. Junio C HamanoJan 24, 2013
  17. Alexey ShumkinJan 25, 2013
  18. Junio C HamanoJan 24, 2013
  19. Alexey ShumkinJan 25, 2013
  20. 4/4 pretty: user format ignores i18n.logOutputEncoding settingAlexey Shumkin, Jan 24, 2013
  21. 0/5 Reroll patches against v1.8.3.1Alexey Shumkin, Jun 20, 2013
  22. 1/5 t6006 (rev-list-format): don't hardcode SHA-1 in expected outputsAlexey Shumkin, Jun 20, 2013
  23. Junio C HamanoJun 20, 2013
  24. 2/5 t7102 (reset): don't hardcode SHA-1 in expected outputsAlexey Shumkin, Jun 20, 2013
  25. 3/5 t4205 (log-pretty-formats): don't hardcode SHA-1 in expected outputsAlexey Shumkin, Jun 20, 2013
  26. Junio C HamanoJun 20, 2013
  27. 4/5 pretty: Add failing tests: user format ignores i18n.logOutputEncoding settingAlexey Shumkin, Jun 20, 2013
  28. Junio C HamanoJun 20, 2013
  29. 5/5 pretty: user format ignores i18n.logOutputEncoding settingAlexey Shumkin, Jun 20, 2013
  30. Junio C HamanoJun 20, 2013
  31. Junio C HamanoJun 20, 2013
  32. 0/5 Reroll patches against v1.8.3.1Alexey Shumkin, Jun 25, 2013
  33. 1/5 t6006 (rev-list-format): don't hardcode SHA-1 in expected outputsAlexey Shumkin, Jun 25, 2013
  34. 2/5 t7102 (reset): don't hardcode SHA-1 in expected outputsAlexey Shumkin, Jun 25, 2013
  35. 3/5 t4205 (log-pretty-formats): don't hardcode SHA-1 in expected outputsAlexey Shumkin, Jun 25, 2013
  36. 4/5 pretty: Add failing tests: --format output should honor logOutputEncodingAlexey Shumkin, Jun 25, 2013
  37. 5/5 pretty: --format output should honor logOutputEncodingAlexey Shumkin, Jun 25, 2013
  38. Junio C HamanoJun 25, 2013
  39. Alexey ShumkinJun 26, 2013
  40. Junio C HamanoJun 26, 2013
  41. 0/5 Reroll patches against v1.8.3.1Alexey Shumkin, Jun 26, 2013
  42. 1/5 t6006 (rev-list-format): don't hardcode SHA-1 in expected outputsAlexey Shumkin, Jun 26, 2013
  43. 2/5 t7102 (reset): don't hardcode SHA-1 in expected outputsAlexey Shumkin, Jun 26, 2013
  44. 3/5 t4205 (log-pretty-formats): don't hardcode SHA-1 in expected outputsAlexey Shumkin, Jun 26, 2013
  45. 4/5 pretty: Add failing tests: --format output should honor logOutputEncodingAlexey Shumkin, Jun 26, 2013
  46. Johannes SixtJul 1, 2013
  47. Alexey ShumkinJul 1, 2013
  48. Johannes SixtJul 2, 2013
  49. Alexey ShumkinJul 3, 2013
  50. 5/5 pretty: --format output should honor logOutputEncodingAlexey Shumkin, Jun 26, 2013
  51. Junio C HamanoJun 26, 2013
  52. 0/5 Reroll patches against Git v1.8.3.2Alexey Shumkin, Jul 1, 2013
  53. 1/5 t6006 (rev-list-format): don't hardcode SHA-1 in expected outputsAlexey Shumkin, Jul 1, 2013
  54. 2/5 t7102 (reset): don't hardcode SHA-1 in expected outputsAlexey Shumkin, Jul 1, 2013
  55. 3/5 t4205 (log-pretty-formats): don't hardcode SHA-1 in expected outputsAlexey Shumkin, Jul 1, 2013
  56. 4/5 pretty: Add failing tests: --format output should honor logOutputEncodingAlexey Shumkin, Jul 1, 2013
  57. Johannes SixtJul 2, 2013
  58. 5/5 pretty: --format output should honor logOutputEncodingAlexey Shumkin, Jul 1, 2013
  59. Junio C HamanoJul 2, 2013
  60. Alexey ShumkinJul 3, 2013
  61. Junio C HamanoJul 3, 2013
  62. 0/5 Incremental updates against 'next' branchAlexey Shumkin, Jul 4, 2013
  63. 1/5 t4041, t4205, t6006, t7102: use iso8859-1 rather than iso-8859-1Alexey Shumkin, Jul 4, 2013
  64. Junio C HamanoJul 5, 2013
  65. Alexey ShumkinJul 5, 2013
  66. Junio C HamanoJul 5, 2013
  67. Alexey ShumkinJul 5, 2013
  68. Junio C HamanoJul 5, 2013
  69. 2/5 t4205: revert back single quotesAlexey Shumkin, Jul 4, 2013
  70. Junio C HamanoJul 5, 2013
  71. 3/5 t4205, t6006, t7102: make functions more readableAlexey Shumkin, Jul 4, 2013
  72. Junio C HamanoJul 5, 2013
  73. Alexey ShumkinJul 5, 2013
  74. Junio C HamanoJul 5, 2013
  75. Alexey ShumkinJul 5, 2013
  76. Junio C HamanoJul 5, 2013
  77. 4/5 t6006: add two more tests for the case i18n.commitEncoding is not setAlexey Shumkin, Jul 4, 2013
  78. Junio C HamanoJul 5, 2013
  79. Junio C HamanoJul 5, 2013
  80. Alexey ShumkinJul 5, 2013
  81. Junio C HamanoJul 5, 2013
  82. 5/5 t4205: avoid using `sed`Alexey Shumkin, Jul 4, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.