@@ -101,6 +101,11 @@ int check_refname_format(const char *refname, int flags)
101
101
102
102
struct ref_entry ;
103
103
104
+ struct ref_value {
105
+ unsigned char sha1 [20 ];
106
+ unsigned char peeled [20 ];
107
+ };
108
+
104
109
struct ref_array {
105
110
int nr , alloc ;
106
111
@@ -120,8 +125,9 @@ struct ref_array {
120
125
121
126
struct ref_entry {
122
127
unsigned char flag ; /* ISSYMREF? ISPACKED? */
123
- unsigned char sha1 [20 ];
124
- unsigned char peeled [20 ];
128
+ union {
129
+ struct ref_value value ;
130
+ } u ;
125
131
/* The full name of the reference (e.g., "refs/heads/master"): */
126
132
char name [FLEX_ARRAY ];
127
133
};
@@ -138,8 +144,8 @@ static struct ref_entry *create_ref_entry(const char *refname,
138
144
die ("Reference has invalid format: '%s'" , refname );
139
145
len = strlen (refname ) + 1 ;
140
146
ref = xmalloc (sizeof (struct ref_entry ) + len );
141
- hashcpy (ref -> sha1 , sha1 );
142
- hashclr (ref -> peeled );
147
+ hashcpy (ref -> u . value . sha1 , sha1 );
148
+ hashclr (ref -> u . value . peeled );
143
149
memcpy (ref -> name , refname , len );
144
150
ref -> flag = flag ;
145
151
return ref ;
@@ -210,7 +216,7 @@ static int is_dup_ref(const struct ref_entry *ref1, const struct ref_entry *ref2
210
216
{
211
217
if (!strcmp (ref1 -> name , ref2 -> name )) {
212
218
/* Duplicate name; make sure that the SHA1s match: */
213
- if (hashcmp (ref1 -> sha1 , ref2 -> sha1 ))
219
+ if (hashcmp (ref1 -> u . value . sha1 , ref2 -> u . value . sha1 ))
214
220
die ("Duplicated ref, and SHA1s don't match: %s" ,
215
221
ref1 -> name );
216
222
warning ("Duplicated ref: %s" , ref1 -> name );
@@ -262,13 +268,13 @@ static int do_one_ref(const char *base, each_ref_fn fn, int trim,
262
268
if (!(flags & DO_FOR_EACH_INCLUDE_BROKEN )) {
263
269
if (entry -> flag & REF_ISBROKEN )
264
270
return 0 ; /* ignore broken refs e.g. dangling symref */
265
- if (!has_sha1_file (entry -> sha1 )) {
271
+ if (!has_sha1_file (entry -> u . value . sha1 )) {
266
272
error ("%s does not point to a valid object!" , entry -> name );
267
273
return 0 ;
268
274
}
269
275
}
270
276
current_ref = entry ;
271
- retval = fn (entry -> name + trim , entry -> sha1 , entry -> flag , cb_data );
277
+ retval = fn (entry -> name + trim , entry -> u . value . sha1 , entry -> flag , cb_data );
272
278
current_ref = NULL ;
273
279
return retval ;
274
280
}
@@ -531,7 +537,7 @@ static void read_packed_refs(FILE *f, struct ref_array *array)
531
537
strlen (refline ) == 42 &&
532
538
refline [41 ] == '\n' &&
533
539
!get_sha1_hex (refline + 1 , sha1 ))
534
- hashcpy (last -> peeled , sha1 );
540
+ hashcpy (last -> u . value . peeled , sha1 );
535
541
}
536
542
}
537
543
@@ -653,7 +659,7 @@ static int resolve_gitlink_packed_ref(struct ref_cache *refs,
653
659
if (ref == NULL )
654
660
return -1 ;
655
661
656
- memcpy (sha1 , ref -> sha1 , 20 );
662
+ memcpy (sha1 , ref -> u . value . sha1 , 20 );
657
663
return 0 ;
658
664
}
659
665
@@ -723,7 +729,7 @@ static int get_packed_ref(const char *refname, unsigned char *sha1)
723
729
struct ref_array * packed = get_packed_refs (get_ref_cache (NULL ));
724
730
struct ref_entry * entry = search_ref_array (packed , refname );
725
731
if (entry ) {
726
- hashcpy (sha1 , entry -> sha1 );
732
+ hashcpy (sha1 , entry -> u . value . sha1 );
727
733
return 0 ;
728
734
}
729
735
return -1 ;
@@ -886,10 +892,10 @@ int peel_ref(const char *refname, unsigned char *sha1)
886
892
if (current_ref && (current_ref -> name == refname
887
893
|| !strcmp (current_ref -> name , refname ))) {
888
894
if (current_ref -> flag & REF_KNOWS_PEELED ) {
889
- hashcpy (sha1 , current_ref -> peeled );
895
+ hashcpy (sha1 , current_ref -> u . value . peeled );
890
896
return 0 ;
891
897
}
892
- hashcpy (base , current_ref -> sha1 );
898
+ hashcpy (base , current_ref -> u . value . sha1 );
893
899
goto fallback ;
894
900
}
895
901
@@ -901,7 +907,7 @@ int peel_ref(const char *refname, unsigned char *sha1)
901
907
struct ref_entry * r = search_ref_array (array , refname );
902
908
903
909
if (r != NULL && r -> flag & REF_KNOWS_PEELED ) {
904
- hashcpy (sha1 , r -> peeled );
910
+ hashcpy (sha1 , r -> u . value . peeled );
905
911
return 0 ;
906
912
}
907
913
}
0 commit comments