Merge branch 'as/log-output-encoding-in-user-format'
authorJunio C Hamano <gitster@pobox.com>
Fri, 12 Jul 2013 19:04:01 +0000 (12:04 -0700)
committerJunio C Hamano <gitster@pobox.com>
Fri, 12 Jul 2013 19:04:01 +0000 (12:04 -0700)
"log --format=" did not honor i18n.logoutputencoding configuration
and this attempts to fix it.

* as/log-output-encoding-in-user-format:
t4205 (log-pretty-formats): avoid using `sed`
t6006 (rev-list-format): add tests for "%b" and "%s" for the case i18n.commitEncoding is not set
t4205, t6006, t7102: make functions better readable
t4205 (log-pretty-formats): revert back single quotes
t4041, t4205, t6006, t7102: use iso8859-1 rather than iso-8859-1
t4205: replace .\+ with ..* in sed commands
pretty: --format output should honor logOutputEncoding
pretty: Add failing tests: --format output should honor logOutputEncoding
t4205 (log-pretty-formats): don't hardcode SHA-1 in expected outputs
t7102 (reset): don't hardcode SHA-1 in expected outputs
t6006 (rev-list-format): don't hardcode SHA-1 in expected outputs

1  2 
log-tree.c
submodule.c
t/t7102-reset.sh
diff --combined log-tree.c
index 2eb69bcfed096d28bff736deca715458605d902a,5277d3e8d08f492f0bbc1f68fcc39f77106867ad..60f32a3965feeba30bd7ba7ba724c5d7dfd52be8
@@@ -10,7 -10,6 +10,7 @@@
  #include "color.h"
  #include "gpg-interface.h"
  #include "sequencer.h"
 +#include "line-log.h"
  
  struct decoration name_decoration = { "object names" };
  
@@@ -617,6 -616,7 +617,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)
@@@ -797,9 -797,6 +798,9 @@@ int log_tree_commit(struct rev_info *op
        log.parent = NULL;
        opt->loginfo = &log;
  
 +      if (opt->line_level_traverse)
 +              return line_log_print(opt, commit);
 +
        shown = log_tree_diff(opt, commit, &log);
        if (!shown && opt->loginfo && opt->always_show_header) {
                log.parent = NULL;
diff --combined submodule.c
index 86854248983be78b3702f5045a659dfe83bf4446,78734e148699fcd5d9755fe4baf3a11c6e022c8e..85415d0057402d40c4c9e98e3c94c41eb8dd940f
@@@ -226,6 -226,7 +226,7 @@@ static void print_submodule_summary(str
        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) {
@@@ -845,7 -846,7 +846,7 @@@ static int find_first_merges(struct obj
                struct commit *a, struct commit *b)
  {
        int i, j;
 -      struct object_array merges;
 +      struct object_array merges = OBJECT_ARRAY_INIT;
        struct commit *commit;
        int contains_another;
  
        struct rev_info revs;
        struct setup_revision_opt rev_opts;
  
 -      memset(&merges, 0, sizeof(merges));
        memset(result, 0, sizeof(struct object_array));
        memset(&rev_opts, 0, sizeof(rev_opts));
  
                }
  
                if (!contains_another)
 -                      add_object_array(merges.objects[i].item,
 -                                       merges.objects[i].name, result);
 +                      add_object_array(merges.objects[i].item, NULL, result);
        }
  
        free(merges.objects);
diff --combined t/t7102-reset.sh
index 300be86c385a93588e987f591357c57421b9cbae,4f1c9f9c7f8ad5aa25f6581815140598d1d6d45f..8d4b50d1b5816d69ab165119773a7ffc0c360c0a
@@@ -9,6 -9,19 +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.
+       msg="modify 2nd file (ge\303\244ndert)\n"
+       if test -n "$1"
+       then
+               printf "$msg" | iconv -f utf-8 -t "$1"
+       else
+               printf "$msg"
+       fi
+ }
  test_expect_success 'creating initial files and commits' '
        test_tick &&
        echo "1st file" >first &&
@@@ -28,7 -41,7 +41,7 @@@
  
        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 +57,20 @@@ check_changes () 
        done | test_cmp .cat_expect -
  }
  
+ 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 &&
+       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
@@@ -192,7 -219,8 +219,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 -239,7 +239,7 @@@ test_expect_success 
        git reset --hard HEAD~2 &&
        check_changes ddaefe00f1da16864591c61fdc7adb5d7cd6b74e &&
        test "$(git rev-parse ORIG_HEAD)" = \
-                       3d3b7be011a58ca0c179ae45d94e6c83c0b0cd0d
+                       $head4
  '
  
  >.diff_expect
@@@ -303,7 -331,7 +331,7 @@@ test_expect_success 'redoing the last t
  
        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
  '
  
@@@ -326,10 -354,11 +354,11 @@@ test_expect_success '--hard reset to HE
        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
@@@ -457,7 -486,7 +486,7 @@@ test_expect_success 'disambiguation (1)
        test_must_fail git diff --quiet -- secondfile &&
        test -z "$(git diff --cached --name-only)" &&
        test -f secondfile &&
 -      test ! -s secondfile
 +      test_must_be_empty secondfile
  
  '