Merge branch 'maint'
authorJunio C Hamano <gitster@pobox.com>
Wed, 26 Nov 2008 19:57:31 +0000 (11:57 -0800)
committerJunio C Hamano <gitster@pobox.com>
Wed, 26 Nov 2008 19:57:31 +0000 (11:57 -0800)
* maint:
Teach "git diff" to honour --[no-]ext-diff

1  2 
builtin-diff.c
t/t4020-diff-external.sh
diff --combined builtin-diff.c
index 7ceceeb6ff49d60468293941b5f37141e8fc01b9,26cf6785918300f3a0998a1811adb71ec6ec7b73..b90d8bcdb6e732729432d8764b429304474bb3e8
@@@ -74,8 -74,6 +74,8 @@@ static int builtin_diff_b_f(struct rev_
        if (!(S_ISREG(st.st_mode) || S_ISLNK(st.st_mode)))
                die("'%s': not a regular file or symlink", path);
  
 +      diff_set_mnemonic_prefix(&revs->diffopt, "o/", "w/");
 +
        if (blob[0].mode == S_IFINVALID)
                blob[0].mode = canon_mode(st.st_mode);
  
@@@ -118,7 -116,7 +118,7 @@@ static int builtin_diff_index(struct re
        int cached = 0;
        while (1 < argc) {
                const char *arg = argv[1];
 -              if (!strcmp(arg, "--cached"))
 +              if (!strcmp(arg, "--cached") || !strcmp(arg, "--staged"))
                        cached = 1;
                else
                        usage(builtin_diff_usage);
@@@ -177,8 -175,10 +177,8 @@@ static int builtin_diff_combined(struc
        if (!revs->dense_combined_merges && !revs->combine_merges)
                revs->dense_combined_merges = revs->combine_merges = 1;
        parent = xmalloc(ents * sizeof(*parent));
 -      /* Again, the revs are all reverse */
        for (i = 0; i < ents; i++)
 -              hashcpy((unsigned char *)(parent + i),
 -                      ent[ents - 1 - i].item->sha1);
 +              hashcpy((unsigned char *)(parent + i), ent[i].item->sha1);
        diff_tree_combined(parent[0], parent + 1, ents - 1,
                           revs->dense_combined_merges, revs);
        return 0;
@@@ -290,6 -290,9 +290,9 @@@ int cmd_diff(int argc, const char **arg
        /* Otherwise, we are doing the usual "git" diff */
        rev.diffopt.skip_stat_unmatch = !!diff_auto_refresh_index;
  
+       /* Default to let external be used */
+       DIFF_OPT_SET(&rev.diffopt, ALLOW_EXTERNAL);
        if (nongit)
                die("Not a git repository");
        argc = setup_revisions(argc, argv, &rev, NULL);
                if (diff_setup_done(&rev.diffopt) < 0)
                        die("diff_setup_done failed");
        }
-       DIFF_OPT_SET(&rev.diffopt, ALLOW_EXTERNAL);
        DIFF_OPT_SET(&rev.diffopt, RECURSIVE);
 +      DIFF_OPT_SET(&rev.diffopt, ALLOW_TEXTCONV);
  
        /*
         * If the user asked for our exit code then don't start a
                        const char *arg = argv[i];
                        if (!strcmp(arg, "--"))
                                break;
 -                      else if (!strcmp(arg, "--cached")) {
 +                      else if (!strcmp(arg, "--cached") ||
 +                               !strcmp(arg, "--staged")) {
                                add_head_to_pending(&rev);
                                if (!rev.pending.nr)
                                        die("No HEAD commit to compare with (yet)");
diff --combined t/t4020-diff-external.sh
index dfe3fbc74b96fff50160c032f0a65ba54f9ad1b2,22ef7d44b08ac7ec20e799a194e27205c794c290..caea292f15437f50fd324496ff511971cc9d1d0c
@@@ -43,6 -43,13 +43,13 @@@ test_expect_success 'GIT_EXTERNAL_DIFF 
  
  '
  
+ test_expect_success 'GIT_EXTERNAL_DIFF environment and --no-ext-diff' '
+       GIT_EXTERNAL_DIFF=echo git diff --no-ext-diff |
+       grep "^diff --git a/file b/file"
+ '
  test_expect_success 'diff attribute' '
  
        git config diff.parrot.command echo &&
@@@ -68,6 -75,13 +75,13 @@@ test_expect_success 'diff attribute sho
  
  '
  
+ test_expect_success 'diff attribute and --no-ext-diff' '
+       git diff --no-ext-diff |
+       grep "^diff --git a/file b/file"
+ '
  test_expect_success 'diff attribute' '
  
        git config --unset diff.parrot.command &&
@@@ -94,6 -108,13 +108,13 @@@ test_expect_success 'diff attribute sho
  
  '
  
+ test_expect_success 'diff attribute and --no-ext-diff' '
+       git diff --no-ext-diff |
+       grep "^diff --git a/file b/file"
+ '
  test_expect_success 'no diff with -diff' '
        echo >.gitattributes "file -diff" &&
        git diff | grep Binary
@@@ -104,7 -125,7 +125,7 @@@ echo NULZbetweenZwords | perl -pe 'y/Z/
  test_expect_success 'force diff with "diff"' '
        echo >.gitattributes "file diff" &&
        git diff >actual &&
 -      test_cmp ../t4020/diff.NUL actual
 +      test_cmp "$TEST_DIRECTORY"/t4020/diff.NUL actual
  '
  
  test_done