@@ -17,6 +17,7 @@ struct batch_options {
17
17
int print_contents ;
18
18
int buffer_output ;
19
19
int all_objects ;
20
+ int cmdmode ; /* may be 'w' or 'c' for --filters or --textconv */
20
21
const char * format ;
21
22
};
22
23
@@ -285,7 +286,32 @@ static void print_object_or_die(struct batch_options *opt, struct expand_data *d
285
286
if (data -> type == OBJ_BLOB ) {
286
287
if (opt -> buffer_output )
287
288
fflush (stdout );
288
- if (stream_blob_to_fd (1 , sha1 , NULL , 0 ) < 0 )
289
+ if (opt -> cmdmode ) {
290
+ char * contents ;
291
+ unsigned long size ;
292
+
293
+ if (!data -> rest )
294
+ die ("missing path for '%s'" , sha1_to_hex (sha1 ));
295
+
296
+ if (opt -> cmdmode == 'w' ) {
297
+ if (filter_object (data -> rest , 0100644 , sha1 ,
298
+ & contents , & size ))
299
+ die ("could not convert '%s' %s" ,
300
+ sha1_to_hex (sha1 ), data -> rest );
301
+ } else if (opt -> cmdmode == 'c' ) {
302
+ enum object_type type ;
303
+ if (!textconv_object (data -> rest , 0100644 , sha1 ,
304
+ 1 , & contents , & size ))
305
+ contents = read_sha1_file (sha1 , & type ,
306
+ & size );
307
+ if (!contents )
308
+ die ("could not convert '%s' %s" ,
309
+ sha1_to_hex (sha1 ), data -> rest );
310
+ } else
311
+ die ("BUG: invalid cmdmode: %c" , opt -> cmdmode );
312
+ batch_write (opt , contents , size );
313
+ free (contents );
314
+ } else if (stream_blob_to_fd (1 , sha1 , NULL , 0 ) < 0 )
289
315
die ("unable to stream %s to stdout" , sha1_to_hex (sha1 ));
290
316
}
291
317
else {
@@ -422,6 +448,8 @@ static int batch_objects(struct batch_options *opt)
422
448
data .mark_query = 1 ;
423
449
strbuf_expand (& buf , opt -> format , expand_format , & data );
424
450
data .mark_query = 0 ;
451
+ if (opt -> cmdmode )
452
+ data .split_on_whitespace = 1 ;
425
453
426
454
if (opt -> all_objects ) {
427
455
struct object_info empty ;
@@ -487,7 +515,7 @@ static int batch_objects(struct batch_options *opt)
487
515
488
516
static const char * const cat_file_usage [] = {
489
517
N_ ("git cat-file (-t [--allow-unknown-type]|-s [--allow-unknown-type]|-e|-p|<type>|--textconv|--filters) [--path=<path>] <object>" ),
490
- N_ ("git cat-file (--batch | --batch-check) [--follow-symlinks]" ),
518
+ N_ ("git cat-file (--batch | --batch-check) [--follow-symlinks] [--textconv|--filters] " ),
491
519
NULL
492
520
};
493
521
@@ -558,7 +586,9 @@ int cmd_cat_file(int argc, const char **argv, const char *prefix)
558
586
argc = parse_options (argc , argv , prefix , options , cat_file_usage , 0 );
559
587
560
588
if (opt ) {
561
- if (argc == 1 )
589
+ if (batch .enabled && (opt == 'c' || opt == 'w' ))
590
+ batch .cmdmode = opt ;
591
+ else if (argc == 1 )
562
592
obj_name = argv [0 ];
563
593
else
564
594
usage_with_options (cat_file_usage , options );
@@ -570,8 +600,12 @@ int cmd_cat_file(int argc, const char **argv, const char *prefix)
570
600
} else
571
601
usage_with_options (cat_file_usage , options );
572
602
}
573
- if (batch .enabled && (opt || argc )) {
574
- usage_with_options (cat_file_usage , options );
603
+ if (batch .enabled ) {
604
+ if (batch .cmdmode != opt || argc )
605
+ usage_with_options (cat_file_usage , options );
606
+ if (batch .cmdmode && batch .all_objects )
607
+ die ("--batch-all-objects cannot be combined with "
608
+ "--textconv nor with --filters" );
575
609
}
576
610
577
611
if ((batch .follow_symlinks || batch .all_objects ) && !batch .enabled ) {
@@ -583,6 +617,11 @@ int cmd_cat_file(int argc, const char **argv, const char *prefix)
583
617
usage_with_options (cat_file_usage , options );
584
618
}
585
619
620
+ if (force_path && batch .enabled ) {
621
+ error ("--path=<path> incompatible with --batch" );
622
+ usage_with_options (cat_file_usage , options );
623
+ }
624
+
586
625
if (batch .buffer_output < 0 )
587
626
batch .buffer_output = batch .all_objects ;
588
627
0 commit comments