show: honor --textconv for blobs
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>
Michael J Gruber committed
May 10, 2013 at 17:10 UTC
083b99310978c6768d8e954c9bab1d3692a515a1
2 files changed
+25
-6
builtin/log.c
+22
-3
@@ -406,10 +406,29 @@ static void show_tagger(char *buf, int len, struct rev_info *rev)
406
strbuf_release(&out);
407
}
408
409
-static int show_blob_object(const unsigned char *sha1, struct rev_info *rev)
409
+static int show_blob_object(const unsigned char *sha1, struct rev_info *rev, const char *obj_name)
410
{
411
+ unsigned char sha1c[20];
412
+ struct object_context obj_context;
413
+ char *buf;
414
+ unsigned long size;
415
+
416
fflush(stdout);
412
- return stream_blob_to_fd(1, sha1, NULL, 0);
417
+ if (!DIFF_OPT_TOUCHED(&rev->diffopt, ALLOW_TEXTCONV) ||
418
+ !DIFF_OPT_TST(&rev->diffopt, ALLOW_TEXTCONV))
419
+ return stream_blob_to_fd(1, sha1, NULL, 0);
420
+
421
+ if (get_sha1_with_context(obj_name, 0, sha1c, &obj_context))
422
+ die("Not a valid object name %s", obj_name);
423
+ if (!obj_context.path[0] ||
424
+ !textconv_object(obj_context.path, obj_context.mode, sha1c, 1, &buf, &size))
425
+ return stream_blob_to_fd(1, sha1, NULL, 0);
426
+
427
+ if (!buf)
428
+ die("git show %s: bad file", obj_name);
429
+
430
+ write_or_die(1, buf, size);
431
+ return 0;
432
}
433
434
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)
514
const char *name = objects[i].name;
515
switch (o->type) {
516
case OBJ_BLOB:
498
- ret = show_blob_object(o->sha1, NULL);
517
+ ret = show_blob_object(o->sha1, &rev, name);
518
break;
519
case OBJ_TAG: {
520
struct tag *t = (struct tag *)o;
t/t4030-diff-textconv.sh
+3
-3
@@ -96,14 +96,14 @@ test_expect_success 'show blob produces binary' '
96
test_cmp expect actual
97
'
98
99
-test_expect_failure 'show --textconv blob produces text' '
99
+test_expect_success 'show --textconv blob produces text' '
100
git show --textconv HEAD:file >actual &&
101
printf "0\\n1\\n" >expect &&
102
test_cmp expect actual
103
'
104
105
-test_success 'show --no-textconv blob produces binary' '
106
- git show --textconv HEAD:file >actual &&
105
+test_expect_success 'show --no-textconv blob produces binary' '
106
+ git show --no-textconv HEAD:file >actual &&
107
printf "\\0\\n\\01\\n" >expect &&
108
test_cmp expect actual
109
'