cat-file: do not die on --textconv without textconv filters

When a command is supposed to use textconv filters (by default or with "--textconv") and none are configured then the blob is output without conversion; the only exception to this rule is "cat-file --textconv". Make it behave like the rest of textconv aware commands. 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 3ac21617b0f56dd76be3bbaa663bf0fff7f3095d
2 files changed +13 -25
builtin/cat-file.c
+8 -10
@@ -115,6 +115,14 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name)
115 case 'e':
116 return !has_sha1_file(sha1);
117
118 + case 'c':
119 + if (!obj_context.path[0])
120 + die("git cat-file --textconv %s: <object> must be <sha1:path>",
121 + obj_name);
122 +
123 + if (textconv_object(obj_context.path, obj_context.mode, sha1, 1, &buf, &size))
124 + break;
125 +
126 case 'p':
127 type = sha1_object_info(sha1, NULL);
128 if (type < 0)
@@ -141,16 +149,6 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name)
149 /* otherwise just spit out the data */
150 break;
151
144 - case 'c':
145 - if (!obj_context.path[0])
146 - die("git cat-file --textconv %s: <object> must be <sha1:path>",
147 - obj_name);
148 -
149 - if (!textconv_object(obj_context.path, obj_context.mode, sha1, 1, &buf, &size))
150 - die("git cat-file --textconv: unable to run textconv on %s",
151 - obj_name);
152 - break;
153 -
152 case 0:
153 if (type_from_string(exp_type) == OBJ_BLOB) {
154 unsigned char blob_sha1[20];
t/t8007-cat-file-textconv.sh
+5 -15
@@ -22,11 +22,11 @@ test_expect_success 'setup ' '
22 '
23
24 cat >expected <<EOF
25 -fatal: git cat-file --textconv: unable to run textconv on :one.bin
25 +bin: test version 2
26 EOF
27
28 test_expect_success 'no filter specified' '
29 - git cat-file --textconv :one.bin 2>result
29 + git cat-file --textconv :one.bin >result &&
30 test_cmp expected result
31 '
32
@@ -36,10 +36,6 @@ test_expect_success 'setup textconv filters' '
36 git config diff.test.cachetextconv false
37 '
38
39 -cat >expected <<EOF
40 -bin: test version 2
41 -EOF
42 -
39 test_expect_success 'cat-file without --textconv' '
40 git cat-file blob :one.bin >result &&
41 test_cmp expected result
@@ -73,25 +69,19 @@ test_expect_success 'cat-file --textconv on previous commit' '
69 '
70
71 test_expect_success SYMLINKS 'cat-file without --textconv (symlink)' '
72 + printf "%s" "one.bin" >expected &&
73 git cat-file blob :symlink.bin >result &&
77 - printf "%s" "one.bin" >expected
74 test_cmp expected result
75 '
76
77
78 test_expect_success SYMLINKS 'cat-file --textconv on index (symlink)' '
83 - ! git cat-file --textconv :symlink.bin 2>result &&
84 - cat >expected <<\EOF &&
85 -fatal: git cat-file --textconv: unable to run textconv on :symlink.bin
86 -EOF
79 + git cat-file --textconv :symlink.bin >result &&
80 test_cmp expected result
81 '
82
83 test_expect_success SYMLINKS 'cat-file --textconv on HEAD (symlink)' '
91 - ! git cat-file --textconv HEAD:symlink.bin 2>result &&
92 - cat >expected <<EOF &&
93 -fatal: git cat-file --textconv: unable to run textconv on HEAD:symlink.bin
94 -EOF
84 + git cat-file --textconv HEAD:symlink.bin >result &&
85 test_cmp expected result
86 '
87