12
12
13
13
static const char bundle_signature [] = "# v2 git bundle\n" ;
14
14
15
- static void add_to_ref_list (const unsigned char * sha1 , const char * name ,
15
+ static void add_to_ref_list (const struct object_id * oid , const char * name ,
16
16
struct ref_list * list )
17
17
{
18
18
ALLOC_GROW (list -> list , list -> nr + 1 , list -> alloc );
19
- hashcpy ( list -> list [list -> nr ].sha1 , sha1 );
19
+ oidcpy ( & list -> list [list -> nr ].oid , oid );
20
20
list -> list [list -> nr ].name = xstrdup (name );
21
21
list -> nr ++ ;
22
22
}
@@ -40,8 +40,9 @@ static int parse_bundle_header(int fd, struct bundle_header *header,
40
40
/* The bundle header ends with an empty line */
41
41
while (!strbuf_getwholeline_fd (& buf , fd , '\n' ) &&
42
42
buf .len && buf .buf [0 ] != '\n' ) {
43
- unsigned char sha1 [ 20 ] ;
43
+ struct object_id oid ;
44
44
int is_prereq = 0 ;
45
+ const char * p ;
45
46
46
47
if (* buf .buf == '-' ) {
47
48
is_prereq = 1 ;
@@ -54,19 +55,19 @@ static int parse_bundle_header(int fd, struct bundle_header *header,
54
55
* Prerequisites have object name that is optionally
55
56
* followed by SP and subject line.
56
57
*/
57
- if (get_sha1_hex (buf .buf , sha1 ) ||
58
- (buf . len > 40 && !isspace (buf . buf [ 40 ] )) ||
59
- (!is_prereq && buf . len <= 40 )) {
58
+ if (parse_oid_hex (buf .buf , & oid , & p ) ||
59
+ (* p && !isspace (* p )) ||
60
+ (!is_prereq && ! * p )) {
60
61
if (report_path )
61
62
error (_ ("unrecognized header: %s%s (%d)" ),
62
63
(is_prereq ? "-" : "" ), buf .buf , (int )buf .len );
63
64
status = -1 ;
64
65
break ;
65
66
} else {
66
67
if (is_prereq )
67
- add_to_ref_list (sha1 , "" , & header -> prerequisites );
68
+ add_to_ref_list (& oid , "" , & header -> prerequisites );
68
69
else
69
- add_to_ref_list (sha1 , buf . buf + 41 , & header -> references );
70
+ add_to_ref_list (& oid , p + 1 , & header -> references );
70
71
}
71
72
}
72
73
@@ -115,7 +116,7 @@ static int list_refs(struct ref_list *r, int argc, const char **argv)
115
116
if (j == argc )
116
117
continue ;
117
118
}
118
- printf ("%s %s\n" , sha1_to_hex ( r -> list [i ].sha1 ),
119
+ printf ("%s %s\n" , oid_to_hex ( & r -> list [i ].oid ),
119
120
r -> list [i ].name );
120
121
}
121
122
return 0 ;
@@ -141,15 +142,15 @@ int verify_bundle(struct bundle_header *header, int verbose)
141
142
init_revisions (& revs , NULL );
142
143
for (i = 0 ; i < p -> nr ; i ++ ) {
143
144
struct ref_list_entry * e = p -> list + i ;
144
- struct object * o = parse_object (e -> sha1 );
145
+ struct object * o = parse_object (e -> oid . hash );
145
146
if (o ) {
146
147
o -> flags |= PREREQ_MARK ;
147
148
add_pending_object (& revs , o , e -> name );
148
149
continue ;
149
150
}
150
151
if (++ ret == 1 )
151
152
error ("%s" , message );
152
- error ("%s %s" , sha1_to_hex ( e -> sha1 ), e -> name );
153
+ error ("%s %s" , oid_to_hex ( & e -> oid ), e -> name );
153
154
}
154
155
if (revs .pending .nr != p -> nr )
155
156
return ret ;
@@ -285,16 +286,16 @@ static int compute_and_write_prerequisites(int bundle_fd,
285
286
return -1 ;
286
287
rls_fout = xfdopen (rls .out , "r" );
287
288
while (strbuf_getwholeline (& buf , rls_fout , '\n' ) != EOF ) {
288
- unsigned char sha1 [ 20 ] ;
289
+ struct object_id oid ;
289
290
if (buf .len > 0 && buf .buf [0 ] == '-' ) {
290
291
write_or_die (bundle_fd , buf .buf , buf .len );
291
- if (!get_sha1_hex (buf .buf + 1 , sha1 )) {
292
- struct object * object = parse_object_or_die (sha1 , buf .buf );
292
+ if (!get_oid_hex (buf .buf + 1 , & oid )) {
293
+ struct object * object = parse_object_or_die (oid . hash , buf .buf );
293
294
object -> flags |= UNINTERESTING ;
294
295
add_pending_object (revs , object , buf .buf );
295
296
}
296
- } else if (!get_sha1_hex (buf .buf , sha1 )) {
297
- struct object * object = parse_object_or_die (sha1 , buf .buf );
297
+ } else if (!get_oid_hex (buf .buf , & oid )) {
298
+ struct object * object = parse_object_or_die (oid . hash , buf .buf );
298
299
object -> flags |= SHOWN ;
299
300
}
300
301
}
0 commit comments