@@ -20,6 +20,32 @@ struct batch_options {
20
20
const char * format ;
21
21
};
22
22
23
+ static int smudge_object (const char * path , unsigned mode , unsigned char * sha1 ,
24
+ char * * buf , unsigned long * size )
25
+ {
26
+ enum object_type type ;
27
+
28
+ * buf = read_sha1_file (sha1 , & type , size );
29
+ if (!* buf )
30
+ return error (_ ("cannot read object %s '%s'" ),
31
+ sha1_to_hex (sha1 ), path );
32
+ if (type != OBJ_BLOB ) {
33
+ free (* buf );
34
+ return error (_ ("blob expected for %s '%s'" ),
35
+ sha1_to_hex (sha1 ), path );
36
+ }
37
+ if (S_ISREG (mode )) {
38
+ struct strbuf strbuf = STRBUF_INIT ;
39
+ if (convert_to_working_tree (path , * buf , * size , & strbuf )) {
40
+ free (* buf );
41
+ * size = strbuf .len ;
42
+ * buf = strbuf_detach (& strbuf , NULL );
43
+ }
44
+ }
45
+
46
+ return 0 ;
47
+ }
48
+
23
49
static int cat_one_file (int opt , const char * exp_type , const char * obj_name ,
24
50
int unknown_type )
25
51
{
@@ -61,6 +87,15 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
61
87
case 'e' :
62
88
return !has_sha1_file (sha1 );
63
89
90
+ case 'w' :
91
+ if (!obj_context .path [0 ])
92
+ die ("git cat-file --smudge %s: <object> must be <sha1:path>" ,
93
+ obj_name );
94
+
95
+ if (smudge_object (obj_context .path , obj_context .mode , sha1 , & buf , & size ))
96
+ return -1 ;
97
+ break ;
98
+
64
99
case 'c' :
65
100
if (!obj_context .path [0 ])
66
101
die ("git cat-file --textconv %s: <object> must be <sha1:path>" ,
@@ -440,7 +475,7 @@ static int batch_objects(struct batch_options *opt)
440
475
}
441
476
442
477
static const char * const cat_file_usage [] = {
443
- N_ ("git cat-file (-t [--allow-unknown-type]|-s [--allow-unknown-type]|-e|-p|<type>|--textconv) <object>" ),
478
+ N_ ("git cat-file (-t [--allow-unknown-type]|-s [--allow-unknown-type]|-e|-p|<type>|--textconv|--smudge ) <object>" ),
444
479
N_ ("git cat-file (--batch | --batch-check) [--follow-symlinks]" ),
445
480
NULL
446
481
};
@@ -486,6 +521,8 @@ int cmd_cat_file(int argc, const char **argv, const char *prefix)
486
521
OPT_CMDMODE ('p' , NULL , & opt , N_ ("pretty-print object's content" ), 'p' ),
487
522
OPT_CMDMODE (0 , "textconv" , & opt ,
488
523
N_ ("for blob objects, run textconv on object's content" ), 'c' ),
524
+ OPT_CMDMODE (0 , "smudge" , & opt ,
525
+ N_ ("for blob objects, run smudge filters on object's content" ), 'w' ),
489
526
OPT_BOOL (0 , "allow-unknown-type" , & unknown_type ,
490
527
N_ ("allow -s and -t to work with broken/corrupt objects" )),
491
528
OPT_BOOL (0 , "buffer" , & batch .buffer_output , N_ ("buffer --batch output" )),
0 commit comments