sha1_name: convert struct disambiguate_state to object_id
Convert struct disambiguate_state to use struct object_id by changing the structure definition and applying the following semantic patch: @@ struct disambiguate_state E1; @@ - E1.bin_pfx + E1.bin_pfx.hash @@ struct disambiguate_state *E1; @@ - E1->bin_pfx + E1->bin_pfx.hash @@ struct disambiguate_state E1; @@ - E1.candidate + E1.candidate.hash @@ struct disambiguate_state *E1; @@ - E1->candidate + E1->candidate.hash This conversion is needed so we can convert disambiguate_hint_fn later. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
brian m. carlson committed
Mar 26, 2017 at 16:01 UTC
d2ee11859ce6c0edecb94a7e3e9600ab69823b06
1 file changed
+11
-11
sha1_name.c
+11
-11
@@ -16,11 +16,11 @@ typedef int (*disambiguate_hint_fn)(const unsigned char *, void *);
16
struct disambiguate_state {
17
int len; /* length of prefix in hex chars */
18
char hex_pfx[GIT_MAX_HEXSZ + 1];
19
- unsigned char bin_pfx[GIT_MAX_RAWSZ];
19
+ struct object_id bin_pfx;
20
21
disambiguate_hint_fn fn;
22
void *cb_data;
23
- unsigned char candidate[GIT_MAX_RAWSZ];
23
+ struct object_id candidate;
24
unsigned candidate_exists:1;
25
unsigned candidate_checked:1;
26
unsigned candidate_ok:1;
@@ -37,10 +37,10 @@ static void update_candidates(struct disambiguate_state *ds, const unsigned char
37
}
38
if (!ds->candidate_exists) {
39
/* this is the first candidate */
40
- hashcpy(ds->candidate, current);
40
+ hashcpy(ds->candidate.hash, current);
41
ds->candidate_exists = 1;
42
return;
43
- } else if (!hashcmp(ds->candidate, current)) {
43
+ } else if (!hashcmp(ds->candidate.hash, current)) {
44
/* the same as what we already have seen */
45
return;
46
}
@@ -52,14 +52,14 @@ static void update_candidates(struct disambiguate_state *ds, const unsigned char
52
}
53
54
if (!ds->candidate_checked) {
55
- ds->candidate_ok = ds->fn(ds->candidate, ds->cb_data);
55
+ ds->candidate_ok = ds->fn(ds->candidate.hash, ds->cb_data);
56
ds->disambiguate_fn_used = 1;
57
ds->candidate_checked = 1;
58
}
59
60
if (!ds->candidate_ok) {
61
/* discard the candidate; we know it does not satisfy fn */
62
- hashcpy(ds->candidate, current);
62
+ hashcpy(ds->candidate.hash, current);
63
ds->candidate_checked = 0;
64
return;
65
}
@@ -151,7 +151,7 @@ static void unique_in_pack(struct packed_git *p,
151
int cmp;
152
153
current = nth_packed_object_sha1(p, mid);
154
- cmp = hashcmp(ds->bin_pfx, current);
154
+ cmp = hashcmp(ds->bin_pfx.hash, current);
155
if (!cmp) {
156
first = mid;
157
break;
@@ -170,7 +170,7 @@ static void unique_in_pack(struct packed_git *p,
170
*/
171
for (i = first; i < num && !ds->ambiguous; i++) {
172
current = nth_packed_object_sha1(p, i);
173
- if (!match_sha(ds->len, ds->bin_pfx, current))
173
+ if (!match_sha(ds->len, ds->bin_pfx.hash, current))
174
break;
175
update_candidates(ds, current);
176
}
@@ -213,12 +213,12 @@ static int finish_object_disambiguation(struct disambiguate_state *ds,
213
* same repository!
214
*/
215
ds->candidate_ok = (!ds->disambiguate_fn_used ||
216
- ds->fn(ds->candidate, ds->cb_data));
216
+ ds->fn(ds->candidate.hash, ds->cb_data));
217
218
if (!ds->candidate_ok)
219
return SHORT_NAME_AMBIGUOUS;
220
221
- hashcpy(sha1, ds->candidate);
221
+ hashcpy(sha1, ds->candidate.hash);
222
return 0;
223
}
224
@@ -332,7 +332,7 @@ static int init_object_disambiguation(const char *name, int len,
332
ds->hex_pfx[i] = c;
333
if (!(i & 1))
334
val <<= 4;
335
- ds->bin_pfx[i >> 1] |= val;
335
+ ds->bin_pfx.hash[i >> 1] |= val;
336
}
337
338
ds->len = len;