@@ -193,25 +193,28 @@ static size_t expand_format(struct strbuf *sb, const char *start, void *data)
193193 return end - start + 1 ;
194194}
195195
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 )
198197{
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 ) {
200203 if (stream_blob_to_fd (fd , sha1 , NULL , 0 ) < 0 )
201204 die ("unable to stream %s to stdout" , sha1_to_hex (sha1 ));
202205 }
203206 else {
204- enum object_type rtype ;
205- unsigned long rsize ;
207+ enum object_type type ;
208+ unsigned long size ;
206209 void * contents ;
207210
208- contents = read_sha1_file (sha1 , & rtype , & rsize );
211+ contents = read_sha1_file (sha1 , & type , & size );
209212 if (!contents )
210213 die ("object %s disappeared" , sha1_to_hex (sha1 ));
211- if (rtype != type )
214+ if (type != data -> type )
212215 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 ));
215218
216219 write_or_die (fd , contents , size );
217220 free (contents );
@@ -250,7 +253,7 @@ static int batch_one_object(const char *obj_name, struct batch_options *opt,
250253 strbuf_release (& buf );
251254
252255 if (opt -> print_contents ) {
253- print_object_or_die (1 , data -> sha1 , data -> type , data -> size );
256+ print_object_or_die (1 , data );
254257 write_or_die (1 , "\n" , 1 );
255258 }
256259 return 0 ;
@@ -274,6 +277,13 @@ static int batch_objects(struct batch_options *opt)
274277 strbuf_expand (& buf , opt -> format , expand_format , & data );
275278 data .mark_query = 0 ;
276279
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+
277287 /*
278288 * We are going to call get_sha1 on a potentially very large number of
279289 * objects. In most large cases, these will be actual object sha1s. The
0 commit comments