]> git.ipfire.org Git - thirdparty/git.git/commitdiff
show: honor --textconv for blobs
authorMichael J Gruber <git@drmicha.warpmail.net>
Fri, 10 May 2013 15:10:12 +0000 (17:10 +0200)
committerJunio C Hamano <gitster@pobox.com>
Fri, 10 May 2013 17:25:43 +0000 (10:25 -0700)
Currently, "diff" and "cat-file" for blobs honor "--textconv" options
(with the former defaulting to "--textconv" and the latter to
"--no-textconv") whereas "show" does not honor this option, even though
it takes diff options.

Make "show" on blobs honor "--textconv" when it is asked.  The default
is not to apply textconv, which is in line with what "cat-file" does.

Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/log.c
t/t4030-diff-textconv.sh

index 3abbc668a7ccd8525c6b7e18d337ed499caf57dc..815c5b84eda26a960924e9090b21afbdd771d249 100644 (file)
@@ -406,10 +406,29 @@ static void show_tagger(char *buf, int len, struct rev_info *rev)
        strbuf_release(&out);
 }
 
-static int show_blob_object(const unsigned char *sha1, struct rev_info *rev)
+static int show_blob_object(const unsigned char *sha1, struct rev_info *rev, const char *obj_name)
 {
+       unsigned char sha1c[20];
+       struct object_context obj_context;
+       char *buf;
+       unsigned long size;
+
        fflush(stdout);
-       return stream_blob_to_fd(1, sha1, NULL, 0);
+       if (!DIFF_OPT_TOUCHED(&rev->diffopt, ALLOW_TEXTCONV) ||
+           !DIFF_OPT_TST(&rev->diffopt, ALLOW_TEXTCONV))
+               return stream_blob_to_fd(1, sha1, NULL, 0);
+
+       if (get_sha1_with_context(obj_name, 0, sha1c, &obj_context))
+               die("Not a valid object name %s", obj_name);
+       if (!obj_context.path[0] ||
+           !textconv_object(obj_context.path, obj_context.mode, sha1c, 1, &buf, &size))
+               return stream_blob_to_fd(1, sha1, NULL, 0);
+
+       if (!buf)
+               die("git show %s: bad file", obj_name);
+
+       write_or_die(1, buf, size);
+       return 0;
 }
 
 static int show_tag_object(const unsigned char *sha1, struct rev_info *rev)
@@ -495,7 +514,7 @@ int cmd_show(int argc, const char **argv, const char *prefix)
                const char *name = objects[i].name;
                switch (o->type) {
                case OBJ_BLOB:
-                       ret = show_blob_object(o->sha1, NULL);
+                       ret = show_blob_object(o->sha1, &rev, name);
                        break;
                case OBJ_TAG: {
                        struct tag *t = (struct tag *)o;
index 3950fc985875f6f248c90ccc73344f8b7a5bd32a..0ebb028cccde070d0133c282068810673e98c2b4 100755 (executable)
@@ -96,14 +96,14 @@ test_expect_success 'show blob produces binary' '
        test_cmp expect actual
 '
 
-test_expect_failure 'show --textconv blob produces text' '
+test_expect_success 'show --textconv blob produces text' '
        git show --textconv HEAD:file >actual &&
        printf "0\\n1\\n" >expect &&
        test_cmp expect actual
 '
 
-test_success 'show --no-textconv blob produces binary' '
-       git show --textconv HEAD:file >actual &&
+test_expect_success 'show --no-textconv blob produces binary' '
+       git show --no-textconv HEAD:file >actual &&
        printf "\\0\\n\\01\\n" >expect &&
        test_cmp expect actual
 '