From mboxrd@z Thu Jan 1 00:00:00 1970 From: Alexey Shumkin Subject: [PATCH v8 5/5] pretty: --format output should honor logOutputEncoding Date: Tue, 2 Jul 2013 03:19:04 +0400 Message-ID: References: Cc: Johannes Sixt , Alexey Shumkin , git@vger.kernel.org To: Junio C Hamano X-From: git-owner@vger.kernel.org Tue Jul 02 01:19:45 2013 Return-path: Envelope-to: gcvg-git-2@plane.gmane.org Received: from vger.kernel.org ([209.132.180.67]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1UtnNo-0007Lt-Bg for gcvg-git-2@plane.gmane.org; Tue, 02 Jul 2013 01:19:44 +0200 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755688Ab3GAXTc (ORCPT ); Mon, 1 Jul 2013 19:19:32 -0400 Received: from mail-la0-f47.google.com ([209.85.215.47]:53461 "EHLO mail-la0-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755603Ab3GAXT1 (ORCPT ); Mon, 1 Jul 2013 19:19:27 -0400 Received: by mail-la0-f47.google.com with SMTP id fe20so4980869lab.34 for ; Mon, 01 Jul 2013 16:19:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rarus.ru; s=google; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references:in-reply-to:references; bh=MN7lk/R0/qCZ6EYGlQe0zvWiWJbCKfnqGe9nFVkGcd4=; b=cofUvQlQF1chfFa7TvFZqgtPy6dK4XAQP3f/nIkU/nH9Hz2kahGiyNaq7dxZBoi8ZH utCOJ8oUg8kccpRGlCNM0BYWumFCTBqDAjks5kIEInlqsi0ucH4XTLQv8EDxOABSzmCb 2GIQs+rrj+mlN7xf0t2FLwNpVhUGQzm9/SN3o= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references:in-reply-to:references; bh=MN7lk/R0/qCZ6EYGlQe0zvWiWJbCKfnqGe9nFVkGcd4=; b=u2e+JX1bZu/I2Kx8HjfP3EpeqR6FDQVcliIycYU/7R8lbfENIMmQ3tIHu75yRfa5QQ 1mUH66uWqgDFY7YR1tPM86xp2TWtUn29lqbiB3dy8MnFE3bJAwK0Zs5zdknRoC0jQ2qt RkG2woXugpcD/Y/7vHWnclCx6Jt4dql9GLJ4okVbCG3X2SwqhhcEbEz0Lp1LHUYfHq6p lwzizyhZmi/uVcEwawBmf7c/X7jd7RHBcZth5oxMWMXHn461+3QzH6Upzu/Y4cc976YA ZQkU+jybmHKta+MD5NLOhMdJcpNJp7Q8G80M2rgXmjeGUc8mBebOo2XV579WYh266lmS goLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references:in-reply-to:references:x-gm-message-state; bh=MN7lk/R0/qCZ6EYGlQe0zvWiWJbCKfnqGe9nFVkGcd4=; b=Lx8O35ZzXQ3pEgovo95g4ita5tQSRC51VXksIA4FUQh0YkqEZLq+cmINO+wvOX7HWM P2U8JkqprLUc0iCwrpApbRp6hf28CsiJcfoJ8YBGFK28ixc/tpi1PTn9x3BLWG4HmHZi 9zkcgTvxyO/eNa0ncQdDhklBL5G1Vj7+M+7TgP2cVekZpwFAF/7yGG8OIl40PB8MbZW1 EXkjxd6pBEp1bun2kr+ocr8szM0zgu/4KmMcRNVI6b3yF50xXAOWx+NhDUzyXEw7M/wT ZV6xZPBcT2Ln1My0Vy0fjTQOnvVsw9R5eT4ugQLqHDD8Ctax7djF0teC63e6IXEXkC+x 9qGw== X-Received: by 10.152.4.163 with SMTP id l3mr13020616lal.60.1372720765857; Mon, 01 Jul 2013 16:19:25 -0700 (PDT) Received: from localhost (ppp91-77-20-158.pppoe.mtu-net.ru. [91.77.20.158]) by mx.google.com with ESMTPSA id b8sm7863361lbr.12.2013.07.01.16.19.23 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Mon, 01 Jul 2013 16:19:24 -0700 (PDT) X-Mailer: git-send-email 1.8.3.1.16.gce2c52e In-Reply-To: In-Reply-To: References: X-Gm-Message-State: ALoCoQn4YtuEvRYoVb12KQ22WcEvY9VLBIPjYsapR8yYChzKanrAJL3lpOvCMMs8Htu3JhlyDdQU Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Archived-At: 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. Signed-off-by: Alexey Shumkin --- 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(-) diff --git a/builtin/reset.c b/builtin/reset.c index 6032131..afa6e02 100644 --- a/builtin/reset.c +++ b/builtin/reset.c @@ -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, diff --git a/builtin/rev-list.c b/builtin/rev-list.c index 67701be..a5ec30d 100644 --- a/builtin/rev-list.c +++ b/builtin/rev-list.c @@ -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) { diff --git a/builtin/shortlog.c b/builtin/shortlog.c index 1fd6f8a..1434f8f 100644 --- a/builtin/shortlog.c +++ b/builtin/shortlog.c @@ -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) { diff --git a/log-tree.c b/log-tree.c index 1946e9c..5277d3e 100644 --- a/log-tree.c +++ b/log-tree.c @@ -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) diff --git a/submodule.c b/submodule.c index 1821a5b..78734e1 100644 --- a/submodule.c +++ b/submodule.c @@ -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) { diff --git a/t/t4041-diff-submodule-option.sh b/t/t4041-diff-submodule-option.sh index d300d0c..04348ea 100755 --- a/t/t4041-diff-submodule-option.sh +++ b/t/t4041-diff-submodule-option.sh @@ -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: diff --git a/t/t4205-log-pretty-formats.sh b/t/t4205-log-pretty-formats.sh index a23da67..5e13000 100755 --- a/t/t4205-log-pretty-formats.sh +++ b/t/t4205-log-pretty-formats.sh @@ -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 " && git log --pretty="format:%<(10,trunc)%s%>>(10,ltrunc)% an" >actual && # complete the incomplete line at the end diff --git a/t/t6006-rev-list-format.sh b/t/t6006-rev-list-format.sh index e4b50ed..18d7909 100755 --- a/t/t6006-rev-list-format.sh +++ b/t/t6006-rev-list-format.sh @@ -128,7 +128,7 @@ commit $head1 iso8859-1 EOF -test_format subject %s failure < .actual && echo HEAD is now at $hex $(commit_msg) > .expected && -- 1.8.3.1.16.gce2c52e