@@ -100,7 +100,7 @@ static char *replace_idents_using_mailmap(char *object_buf, size_t *size)
100100
101101static int filter_object (const char * path , unsigned mode ,
102102 const struct object_id * oid ,
103- char * * buf , unsigned long * size )
103+ char * * buf , size_t * size )
104104{
105105 enum object_type type ;
106106
@@ -136,7 +136,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name)
136136 struct object_id oid ;
137137 enum object_type type ;
138138 char * buf ;
139- unsigned long size ;
139+ size_t size ;
140140 struct object_context obj_context = {0 };
141141 struct object_info oi = OBJECT_INFO_INIT ;
142142 unsigned flags = OBJECT_INFO_LOOKUP_REPLACE ;
@@ -179,11 +179,8 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name)
179179 if (odb_read_object_info_extended (the_repository -> objects , & oid , & oi , flags ) < 0 )
180180 die ("git cat-file: could not get object info" );
181181
182- if (use_mailmap && (type == OBJ_COMMIT || type == OBJ_TAG )) {
183- size_t s = size ;
184- buf = replace_idents_using_mailmap (buf , & s );
185- size = cast_size_t_to_ulong (s );
186- }
182+ if (use_mailmap && (type == OBJ_COMMIT || type == OBJ_TAG ))
183+ buf = replace_idents_using_mailmap (buf , & size );
187184
188185 printf ("%" PRIuMAX "\n" , (uintmax_t )size );
189186 ret = 0 ;
@@ -204,9 +201,15 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name)
204201 break ;
205202
206203 case 'c' :
207- if (textconv_object (the_repository , path , obj_context .mode ,
208- & oid , 1 , & buf , & size ))
204+ {
205+ unsigned long size_ul = 0 ;
206+ int textconv_ret = textconv_object (the_repository , path ,
207+ obj_context .mode , & oid , 1 ,
208+ & buf , & size_ul );
209+ size = size_ul ;
210+ if (textconv_ret )
209211 break ;
212+ }
210213 /* else fallthrough */
211214
212215 case 'p' :
@@ -232,11 +235,8 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name)
232235 if (!buf )
233236 die ("Cannot read object %s" , obj_name );
234237
235- if (use_mailmap ) {
236- size_t s = size ;
237- buf = replace_idents_using_mailmap (buf , & s );
238- size = cast_size_t_to_ulong (s );
239- }
238+ if (use_mailmap )
239+ buf = replace_idents_using_mailmap (buf , & size );
240240
241241 /* otherwise just spit out the data */
242242 break ;
@@ -279,11 +279,8 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name)
279279 buf = odb_read_object_peeled (the_repository -> objects , & oid ,
280280 exp_type_id , & size , NULL );
281281
282- if (use_mailmap ) {
283- size_t s = size ;
284- buf = replace_idents_using_mailmap (buf , & s );
285- size = cast_size_t_to_ulong (s );
286- }
282+ if (use_mailmap )
283+ buf = replace_idents_using_mailmap (buf , & size );
287284 break ;
288285 }
289286 default :
@@ -304,7 +301,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name)
304301struct expand_data {
305302 struct object_id oid ;
306303 enum object_type type ;
307- unsigned long size ;
304+ size_t size ;
308305 unsigned short mode ;
309306 off_t disk_size ;
310307 const char * rest ;
@@ -438,7 +435,7 @@ static void print_object_or_die(struct batch_options *opt, struct expand_data *d
438435 fflush (stdout );
439436 if (opt -> transform_mode ) {
440437 char * contents ;
441- unsigned long size ;
438+ size_t size ;
442439
443440 if (!data -> rest )
444441 die ("missing path for '%s'" , oid_to_hex (oid ));
@@ -450,9 +447,12 @@ static void print_object_or_die(struct batch_options *opt, struct expand_data *d
450447 oid_to_hex (oid ), data -> rest );
451448 } else if (opt -> transform_mode == 'c' ) {
452449 enum object_type type ;
453- if (!textconv_object (the_repository ,
454- data -> rest , 0100644 , oid ,
455- 1 , & contents , & size ))
450+ unsigned long size_ul = 0 ;
451+ if (textconv_object (the_repository ,
452+ data -> rest , 0100644 , oid ,
453+ 1 , & contents , & size_ul ))
454+ size = size_ul ;
455+ else
456456 contents = odb_read_object (the_repository -> objects ,
457457 oid , & type , & size );
458458 if (!contents )
@@ -468,19 +468,16 @@ static void print_object_or_die(struct batch_options *opt, struct expand_data *d
468468 }
469469 else {
470470 enum object_type type ;
471- unsigned long size ;
471+ size_t size ;
472472 void * contents ;
473473
474474 contents = odb_read_object (the_repository -> objects , oid ,
475475 & type , & size );
476476 if (!contents )
477477 die ("object %s disappeared" , oid_to_hex (oid ));
478478
479- if (use_mailmap ) {
480- size_t s = size ;
481- contents = replace_idents_using_mailmap (contents , & s );
482- size = cast_size_t_to_ulong (s );
483- }
479+ if (use_mailmap )
480+ contents = replace_idents_using_mailmap (contents , & size );
484481
485482 if (type != data -> type )
486483 die ("object %s changed type!?" , oid_to_hex (oid ));
@@ -583,15 +580,13 @@ static void batch_object_write(const char *obj_name,
583580 }
584581
585582 if (use_mailmap && (data -> type == OBJ_COMMIT || data -> type == OBJ_TAG )) {
586- size_t s = data -> size ;
587583 char * buf = NULL ;
588584
589585 buf = odb_read_object (the_repository -> objects , & data -> oid ,
590586 & data -> type , & data -> size );
591587 if (!buf )
592588 die (_ ("unable to read %s" ), oid_to_hex (& data -> oid ));
593- buf = replace_idents_using_mailmap (buf , & s );
594- data -> size = cast_size_t_to_ulong (s );
589+ buf = replace_idents_using_mailmap (buf , & data -> size );
595590
596591 free (buf );
597592 }
0 commit comments