99#include "tree.h"
1010#include "builtin.h"
1111#include "parse-options.h"
12+ #include "diff.h"
13+ #include "userdiff.h"
1214
1315#define BATCH 1
1416#define BATCH_CHECK 2
@@ -84,10 +86,11 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name)
8486{
8587 unsigned char sha1 [20 ];
8688 enum object_type type ;
87- void * buf ;
89+ char * buf ;
8890 unsigned long size ;
91+ struct object_context obj_context ;
8992
90- if (get_sha1 (obj_name , sha1 ))
93+ if (get_sha1_with_context (obj_name , sha1 , & obj_context ))
9194 die ("Not a valid object name %s" , obj_name );
9295
9396 buf = NULL ;
@@ -134,6 +137,17 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name)
134137
135138 /* otherwise just spit out the data */
136139 break ;
140+
141+ case 'c' :
142+ if (!obj_context .path [0 ])
143+ die ("git cat-file --textconv %s: <object> must be <sha1:path>" ,
144+ obj_name );
145+
146+ if (!textconv_object (obj_context .path , sha1 , & buf , & size ))
147+ die ("git cat-file --textconv: unable to run textconv on %s" ,
148+ obj_name );
149+ break ;
150+
137151 case 0 :
138152 buf = read_object_with_reference (sha1 , exp_type , & size , NULL );
139153 break ;
@@ -203,11 +217,25 @@ static int batch_objects(int print_contents)
203217}
204218
205219static const char * const cat_file_usage [] = {
206- "git cat-file (-t|-s|-e|-p|<type>) <object>" ,
220+ "git cat-file (-t|-s|-e|-p|<type>|--textconv ) <object>" ,
207221 "git cat-file (--batch|--batch-check) < <list_of_objects>" ,
208222 NULL
209223};
210224
225+ static int git_cat_file_config (const char * var , const char * value , void * cb )
226+ {
227+ switch (userdiff_config (var , value )) {
228+ case 0 :
229+ break ;
230+ case -1 :
231+ return -1 ;
232+ default :
233+ return 0 ;
234+ }
235+
236+ return git_default_config (var , value , cb );
237+ }
238+
211239int cmd_cat_file (int argc , const char * * argv , const char * prefix )
212240{
213241 int opt = 0 , batch = 0 ;
@@ -220,6 +248,8 @@ int cmd_cat_file(int argc, const char **argv, const char *prefix)
220248 OPT_SET_INT ('e' , NULL , & opt ,
221249 "exit with zero when there's no error" , 'e' ),
222250 OPT_SET_INT ('p' , NULL , & opt , "pretty-print object's content" , 'p' ),
251+ OPT_SET_INT (0 , "textconv" , & opt ,
252+ "for blob objects, run textconv on object's content" , 'c' ),
223253 OPT_SET_INT (0 , "batch" , & batch ,
224254 "show info and content of objects fed from the standard input" ,
225255 BATCH ),
@@ -229,7 +259,7 @@ int cmd_cat_file(int argc, const char **argv, const char *prefix)
229259 OPT_END ()
230260 };
231261
232- git_config (git_default_config , NULL );
262+ git_config (git_cat_file_config , NULL );
233263
234264 if (argc != 3 && argc != 2 )
235265 usage_with_options (cat_file_usage , options );
0 commit comments