@@ -84,7 +84,7 @@ static char *replace_idents_using_mailmap(char *object_buf, size_t *size)
8484
8585static int filter_object (const char * path , unsigned mode ,
8686 const struct object_id * oid ,
87- char * * buf , unsigned long * size )
87+ char * * buf , size_t * size )
8888{
8989 enum object_type type ;
9090
@@ -120,7 +120,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name)
120120 struct object_id oid ;
121121 enum object_type type ;
122122 char * buf ;
123- unsigned long size ;
123+ size_t size ;
124124 struct object_context obj_context = {0 };
125125 struct object_info oi = OBJECT_INFO_INIT ;
126126 unsigned flags = OBJECT_INFO_LOOKUP_REPLACE ;
@@ -163,11 +163,8 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name)
163163 if (odb_read_object_info_extended (the_repository -> objects , & oid , & oi , flags ) < 0 )
164164 die ("git cat-file: could not get object info" );
165165
166- if (use_mailmap && (type == OBJ_COMMIT || type == OBJ_TAG )) {
167- size_t s = size ;
168- buf = replace_idents_using_mailmap (buf , & s );
169- size = cast_size_t_to_ulong (s );
170- }
166+ if (use_mailmap && (type == OBJ_COMMIT || type == OBJ_TAG ))
167+ buf = replace_idents_using_mailmap (buf , & size );
171168
172169 printf ("%" PRIuMAX "\n" , (uintmax_t )size );
173170 ret = 0 ;
@@ -188,9 +185,15 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name)
188185 break ;
189186
190187 case 'c' :
191- if (textconv_object (the_repository , path , obj_context .mode ,
192- & oid , 1 , & buf , & size ))
188+ {
189+ unsigned long size_ul = 0 ;
190+ int textconv_ret = textconv_object (the_repository , path ,
191+ obj_context .mode , & oid , 1 ,
192+ & buf , & size_ul );
193+ size = size_ul ;
194+ if (textconv_ret )
193195 break ;
196+ }
194197 /* else fallthrough */
195198
196199 case 'p' :
@@ -216,11 +219,8 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name)
216219 if (!buf )
217220 die ("Cannot read object %s" , obj_name );
218221
219- if (use_mailmap ) {
220- size_t s = size ;
221- buf = replace_idents_using_mailmap (buf , & s );
222- size = cast_size_t_to_ulong (s );
223- }
222+ if (use_mailmap )
223+ buf = replace_idents_using_mailmap (buf , & size );
224224
225225 /* otherwise just spit out the data */
226226 break ;
@@ -263,11 +263,8 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name)
263263 buf = odb_read_object_peeled (the_repository -> objects , & oid ,
264264 exp_type_id , & size , NULL );
265265
266- if (use_mailmap ) {
267- size_t s = size ;
268- buf = replace_idents_using_mailmap (buf , & s );
269- size = cast_size_t_to_ulong (s );
270- }
266+ if (use_mailmap )
267+ buf = replace_idents_using_mailmap (buf , & size );
271268 break ;
272269 }
273270 default :
@@ -288,7 +285,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name)
288285struct expand_data {
289286 struct object_id oid ;
290287 enum object_type type ;
291- unsigned long size ;
288+ size_t size ;
292289 unsigned short mode ;
293290 off_t disk_size ;
294291 const char * rest ;
@@ -404,7 +401,7 @@ static void print_object_or_die(struct batch_options *opt, struct expand_data *d
404401 fflush (stdout );
405402 if (opt -> transform_mode ) {
406403 char * contents ;
407- unsigned long size ;
404+ size_t size ;
408405
409406 if (!data -> rest )
410407 die ("missing path for '%s'" , oid_to_hex (oid ));
@@ -416,9 +413,12 @@ static void print_object_or_die(struct batch_options *opt, struct expand_data *d
416413 oid_to_hex (oid ), data -> rest );
417414 } else if (opt -> transform_mode == 'c' ) {
418415 enum object_type type ;
419- if (!textconv_object (the_repository ,
420- data -> rest , 0100644 , oid ,
421- 1 , & contents , & size ))
416+ unsigned long size_ul = 0 ;
417+ if (textconv_object (the_repository ,
418+ data -> rest , 0100644 , oid ,
419+ 1 , & contents , & size_ul ))
420+ size = size_ul ;
421+ else
422422 contents = odb_read_object (the_repository -> objects ,
423423 oid , & type , & size );
424424 if (!contents )
@@ -434,19 +434,16 @@ static void print_object_or_die(struct batch_options *opt, struct expand_data *d
434434 }
435435 else {
436436 enum object_type type ;
437- unsigned long size ;
437+ size_t size ;
438438 void * contents ;
439439
440440 contents = odb_read_object (the_repository -> objects , oid ,
441441 & type , & size );
442442 if (!contents )
443443 die ("object %s disappeared" , oid_to_hex (oid ));
444444
445- if (use_mailmap ) {
446- size_t s = size ;
447- contents = replace_idents_using_mailmap (contents , & s );
448- size = cast_size_t_to_ulong (s );
449- }
445+ if (use_mailmap )
446+ contents = replace_idents_using_mailmap (contents , & size );
450447
451448 if (type != data -> type )
452449 die ("object %s changed type!?" , oid_to_hex (oid ));
@@ -549,15 +546,13 @@ static void batch_object_write(const char *obj_name,
549546 }
550547
551548 if (use_mailmap && (data -> type == OBJ_COMMIT || data -> type == OBJ_TAG )) {
552- size_t s = data -> size ;
553549 char * buf = NULL ;
554550
555551 buf = odb_read_object (the_repository -> objects , & data -> oid ,
556552 & data -> type , & data -> size );
557553 if (!buf )
558554 die (_ ("unable to read %s" ), oid_to_hex (& data -> oid ));
559- buf = replace_idents_using_mailmap (buf , & s );
560- data -> size = cast_size_t_to_ulong (s );
555+ buf = replace_idents_using_mailmap (buf , & data -> size );
561556
562557 free (buf );
563558 }
0 commit comments