@@ -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 ;
@@ -485,9 +513,8 @@ static int batch_objects(struct batch_options *opt)
485
513
return retval ;
486
514
}
487
515
488
- static const char * const cat_file_usage [] = {
489
516
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]" ),
517
+ N_ ("git cat-file (--batch | --batch-check) [--follow-symlinks] [--textconv | --filters] " ),
491
518
NULL
492
519
};
493
520
@@ -558,7 +585,9 @@ int cmd_cat_file(int argc, const char **argv, const char *prefix)
558
585
argc = parse_options (argc , argv , prefix , options , cat_file_usage , 0 );
559
586
560
587
if (opt ) {
561
- if (argc == 1 )
588
+ if (batch .enabled && (opt == 'c' || opt == 'w' ))
589
+ batch .cmdmode = opt ;
590
+ else if (argc == 1 )
562
591
obj_name = argv [0 ];
563
592
else
564
593
usage_with_options (cat_file_usage , options );
@@ -570,8 +599,12 @@ int cmd_cat_file(int argc, const char **argv, const char *prefix)
570
599
} else
571
600
usage_with_options (cat_file_usage , options );
572
601
}
573
- if (batch .enabled && (opt || argc )) {
574
- usage_with_options (cat_file_usage , options );
602
+ if (batch .enabled ) {
603
+ if (batch .cmdmode != opt || argc )
604
+ usage_with_options (cat_file_usage , options );
605
+ if (batch .cmdmode && batch .all_objects )
606
+ die ("--batch-all-objects cannot be combined with "
607
+ "--textconv nor with --filters" );
575
608
}
576
609
577
610
if ((batch .follow_symlinks || batch .all_objects ) && !batch .enabled ) {
@@ -583,6 +616,11 @@ int cmd_cat_file(int argc, const char **argv, const char *prefix)
583
616
usage_with_options (cat_file_usage , options );
584
617
}
585
618
619
+ if (force_path && batch .enabled ) {
620
+ error ("--path=<path> incompatible with --batch" );
621
+ usage_with_options (cat_file_usage , options );
622
+ }
623
+
586
624
if (batch .buffer_output < 0 )
587
625
batch .buffer_output = batch .all_objects ;
588
626
0 commit comments