11
11
#include "parse-options.h"
12
12
#include "diff.h"
13
13
#include "userdiff.h"
14
+ #include "streaming.h"
14
15
15
16
#define BATCH 1
16
17
#define BATCH_CHECK 2
@@ -127,6 +128,8 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name)
127
128
return cmd_ls_tree (2 , ls_args , NULL );
128
129
}
129
130
131
+ if (type == OBJ_BLOB )
132
+ return stream_blob_to_fd (1 , sha1 , NULL , 0 );
130
133
buf = read_sha1_file (sha1 , & type , & size );
131
134
if (!buf )
132
135
die ("Cannot read object %s" , obj_name );
@@ -149,6 +152,28 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name)
149
152
break ;
150
153
151
154
case 0 :
155
+ if (type_from_string (exp_type ) == OBJ_BLOB ) {
156
+ unsigned char blob_sha1 [20 ];
157
+ if (sha1_object_info (sha1 , NULL ) == OBJ_TAG ) {
158
+ enum object_type type ;
159
+ unsigned long size ;
160
+ char * buffer = read_sha1_file (sha1 , & type , & size );
161
+ if (memcmp (buffer , "object " , 7 ) ||
162
+ get_sha1_hex (buffer + 7 , blob_sha1 ))
163
+ die ("%s not a valid tag" , sha1_to_hex (sha1 ));
164
+ free (buffer );
165
+ } else
166
+ hashcpy (blob_sha1 , sha1 );
167
+
168
+ if (sha1_object_info (blob_sha1 , NULL ) == OBJ_BLOB )
169
+ return stream_blob_to_fd (1 , blob_sha1 , NULL , 0 );
170
+ /*
171
+ * we attempted to dereference a tag to a blob
172
+ * and failed; there may be new dereference
173
+ * mechanisms this code is not aware of.
174
+ * fall-back to the usual case.
175
+ */
176
+ }
152
177
buf = read_object_with_reference (sha1 , exp_type , & size , NULL );
153
178
break ;
154
179
0 commit comments