@@ -360,6 +360,13 @@ static void print_object_or_die(struct batch_options *opt, struct expand_data *d
360
360
}
361
361
}
362
362
363
+ static void print_default_format (struct strbuf * scratch , struct expand_data * data )
364
+ {
365
+ strbuf_addf (scratch , "%s %s %" PRIuMAX "\n" , oid_to_hex (& data -> oid ),
366
+ type_name (data -> type ),
367
+ (uintmax_t )data -> size );
368
+ }
369
+
363
370
/*
364
371
* If "pack" is non-NULL, then "offset" is the byte offset within the pack from
365
372
* which the object may be accessed (though note that we may also rely on
@@ -391,8 +398,14 @@ static void batch_object_write(const char *obj_name,
391
398
}
392
399
393
400
strbuf_reset (scratch );
394
- strbuf_expand (scratch , opt -> format , expand_format , data );
395
- strbuf_addch (scratch , '\n' );
401
+
402
+ if (!opt -> format ) {
403
+ print_default_format (scratch , data );
404
+ } else {
405
+ strbuf_expand (scratch , opt -> format , expand_format , data );
406
+ strbuf_addch (scratch , '\n' );
407
+ }
408
+
396
409
batch_write (opt , scratch -> buf , scratch -> len );
397
410
398
411
if (opt -> batch_mode == BATCH_MODE_CONTENTS ) {
@@ -646,6 +659,8 @@ static void batch_objects_command(struct batch_options *opt,
646
659
strbuf_release (& input );
647
660
}
648
661
662
+ #define DEFAULT_FORMAT "%(objectname) %(objecttype) %(objectsize)"
663
+
649
664
static int batch_objects (struct batch_options * opt )
650
665
{
651
666
struct strbuf input = STRBUF_INIT ;
@@ -654,22 +669,24 @@ static int batch_objects(struct batch_options *opt)
654
669
int save_warning ;
655
670
int retval = 0 ;
656
671
657
- if (!opt -> format )
658
- opt -> format = "%(objectname) %(objecttype) %(objectsize)" ;
659
-
660
672
/*
661
673
* Expand once with our special mark_query flag, which will prime the
662
674
* object_info to be handed to oid_object_info_extended for each
663
675
* object.
664
676
*/
665
677
memset (& data , 0 , sizeof (data ));
666
678
data .mark_query = 1 ;
667
- strbuf_expand (& output , opt -> format , expand_format , & data );
679
+ strbuf_expand (& output ,
680
+ opt -> format ? opt -> format : DEFAULT_FORMAT ,
681
+ expand_format ,
682
+ & data );
668
683
data .mark_query = 0 ;
669
684
strbuf_release (& output );
670
685
if (opt -> transform_mode )
671
686
data .split_on_whitespace = 1 ;
672
687
688
+ if (opt -> format && !strcmp (opt -> format , DEFAULT_FORMAT ))
689
+ opt -> format = NULL ;
673
690
/*
674
691
* If we are printing out the object, then always fill in the type,
675
692
* since we will want to decide whether or not to stream.
0 commit comments