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

4 messages, 2 authors, 2016-06-15 · open the first message on its own page

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

From: Shumkin Alexey <hidden>
Date: 2016-06-15 22:51:38

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

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

From: Alexey Shumkin <hidden>
Date: 2016-06-15 22:51:38

Oh! I've fixed it!
A patch I'll provide soon

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

From: Alexey Shumkin <hidden>
Date: 2016-06-15 22:51:39

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.

Signed-off-by: Alexey Shumkin <redacted>
---
 log-tree.c                    |    1 +
 t/t4205-log-pretty-formats.sh |   20 ++++++++++++++++++--
 2 files changed, 19 insertions(+), 2 deletions(-)
diff --git a/log-tree.c b/log-tree.c
index e945701..39913d7 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -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)
diff --git a/t/t4205-log-pretty-formats.sh b/t/t4205-log-pretty-formats.sh
index 2ae9faa..24e787a 100755
--- a/t/t4205-log-pretty-formats.sh
+++ b/t/t4205-log-pretty-formats.sh
@@ -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" &&
-- 
1.7.6.dirty

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

From: Alexey Shumkin <hidden>
Date: 2016-06-15 22:51:39

Started here http://thread.gmane.org/gmane.comp.version-control.git/177634
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help