@@ -193,25 +193,28 @@ static size_t expand_format(struct strbuf *sb, const char *start, void *data)
193
193
return end - start + 1 ;
194
194
}
195
195
196
- static void print_object_or_die (int fd , const unsigned char * sha1 ,
197
- enum object_type type , unsigned long size )
196
+ static void print_object_or_die (int fd , struct expand_data * data )
198
197
{
199
- if (type == OBJ_BLOB ) {
198
+ const unsigned char * sha1 = data -> sha1 ;
199
+
200
+ assert (data -> info .typep );
201
+
202
+ if (data -> type == OBJ_BLOB ) {
200
203
if (stream_blob_to_fd (fd , sha1 , NULL , 0 ) < 0 )
201
204
die ("unable to stream %s to stdout" , sha1_to_hex (sha1 ));
202
205
}
203
206
else {
204
- enum object_type rtype ;
205
- unsigned long rsize ;
207
+ enum object_type type ;
208
+ unsigned long size ;
206
209
void * contents ;
207
210
208
- contents = read_sha1_file (sha1 , & rtype , & rsize );
211
+ contents = read_sha1_file (sha1 , & type , & size );
209
212
if (!contents )
210
213
die ("object %s disappeared" , sha1_to_hex (sha1 ));
211
- if (rtype != type )
214
+ if (type != data -> type )
212
215
die ("object %s changed type!?" , sha1_to_hex (sha1 ));
213
- if (rsize != size )
214
- die ("object %s change size!?" , sha1_to_hex (sha1 ));
216
+ if (data -> info . sizep && size != data -> size )
217
+ die ("object %s changed size!?" , sha1_to_hex (sha1 ));
215
218
216
219
write_or_die (fd , contents , size );
217
220
free (contents );
@@ -250,7 +253,7 @@ static int batch_one_object(const char *obj_name, struct batch_options *opt,
250
253
strbuf_release (& buf );
251
254
252
255
if (opt -> print_contents ) {
253
- print_object_or_die (1 , data -> sha1 , data -> type , data -> size );
256
+ print_object_or_die (1 , data );
254
257
write_or_die (1 , "\n" , 1 );
255
258
}
256
259
return 0 ;
@@ -274,6 +277,13 @@ static int batch_objects(struct batch_options *opt)
274
277
strbuf_expand (& buf , opt -> format , expand_format , & data );
275
278
data .mark_query = 0 ;
276
279
280
+ /*
281
+ * If we are printing out the object, then always fill in the type,
282
+ * since we will want to decide whether or not to stream.
283
+ */
284
+ if (opt -> print_contents )
285
+ data .info .typep = & data .type ;
286
+
277
287
/*
278
288
* We are going to call get_sha1 on a potentially very large number of
279
289
* objects. In most large cases, these will be actual object sha1s. The
0 commit comments