Skip to content

Commit 083b993

Browse files
Michael J Grubergitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6c37400 commit 083b993

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

builtin/log.c

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -406,10 +406,29 @@ static void show_tagger(char *buf, int len, struct rev_info *rev)
406406
strbuf_release(&out);
407407
}
408408

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)
410410
{
411+
unsigned char sha1c[20];
412+
struct object_context obj_context;
413+
char *buf;
414+
unsigned long size;
415+
411416
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;
413432
}
414433

415434
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)
495514
const char *name = objects[i].name;
496515
switch (o->type) {
497516
case OBJ_BLOB:
498-
ret = show_blob_object(o->sha1, NULL);
517+
ret = show_blob_object(o->sha1, &rev, name);
499518
break;
500519
case OBJ_TAG: {
501520
struct tag *t = (struct tag *)o;

t/t4030-diff-textconv.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,14 @@ test_expect_success 'show blob produces binary' '
9696
test_cmp expect actual
9797
'
9898

99-
test_expect_failure 'show --textconv blob produces text' '
99+
test_expect_success 'show --textconv blob produces text' '
100100
git show --textconv HEAD:file >actual &&
101101
printf "0\\n1\\n" >expect &&
102102
test_cmp expect actual
103103
'
104104

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 &&
107107
printf "\\0\\n\\01\\n" >expect &&
108108
test_cmp expect actual
109109
'

0 commit comments

Comments
 (0)