Skip to content

Commit e9b7caa

Browse files
pks-tgitster
authored andcommitted
object-name: merge update_candidates() and match_prefix()
There's only a single callsite for `match_prefix()`, and that function is a rather trivial wrapper of `update_candidates()`. Merge these two functions into a single `update_disambiguate_state()` function. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent eac58de commit e9b7caa

1 file changed

Lines changed: 18 additions & 16 deletions

File tree

object-name.c

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -51,27 +51,31 @@ struct disambiguate_state {
5151
unsigned always_call_fn:1;
5252
};
5353

54-
static void update_candidates(struct disambiguate_state *ds, const struct object_id *current)
54+
static int update_disambiguate_state(const struct object_id *current,
55+
struct object_info *oi UNUSED,
56+
void *cb_data)
5557
{
58+
struct disambiguate_state *ds = cb_data;
59+
5660
/* The hash algorithm of current has already been filtered */
5761
if (ds->always_call_fn) {
5862
ds->ambiguous = ds->fn(ds->repo, current, ds->cb_data) ? 1 : 0;
59-
return;
63+
return ds->ambiguous;
6064
}
6165
if (!ds->candidate_exists) {
6266
/* this is the first candidate */
6367
oidcpy(&ds->candidate, current);
6468
ds->candidate_exists = 1;
65-
return;
69+
return 0;
6670
} else if (oideq(&ds->candidate, current)) {
6771
/* the same as what we already have seen */
68-
return;
72+
return 0;
6973
}
7074

7175
if (!ds->fn) {
7276
/* cannot disambiguate between ds->candidate and current */
7377
ds->ambiguous = 1;
74-
return;
78+
return ds->ambiguous;
7579
}
7680

7781
if (!ds->candidate_checked) {
@@ -84,7 +88,7 @@ static void update_candidates(struct disambiguate_state *ds, const struct object
8488
/* discard the candidate; we know it does not satisfy fn */
8589
oidcpy(&ds->candidate, current);
8690
ds->candidate_checked = 0;
87-
return;
91+
return 0;
8892
}
8993

9094
/* if we reach this point, we know ds->candidate satisfies fn */
@@ -95,17 +99,12 @@ static void update_candidates(struct disambiguate_state *ds, const struct object
9599
*/
96100
ds->candidate_ok = 0;
97101
ds->ambiguous = 1;
102+
return ds->ambiguous;
98103
}
99104

100105
/* otherwise, current can be discarded and candidate is still good */
101-
}
102106

103-
static int match_prefix(const struct object_id *oid, struct object_info *oi UNUSED, void *arg)
104-
{
105-
struct disambiguate_state *ds = arg;
106-
/* no need to call match_hash, oidtree_each did prefix match */
107-
update_candidates(ds, oid);
108-
return ds->ambiguous;
107+
return 0;
109108
}
110109

111110
static void find_short_object_filename(struct disambiguate_state *ds)
@@ -117,7 +116,8 @@ static void find_short_object_filename(struct disambiguate_state *ds)
117116
struct odb_source *source;
118117

119118
for (source = ds->repo->objects->sources; source && !ds->ambiguous; source = source->next)
120-
odb_source_loose_for_each_object(source, NULL, match_prefix, ds, &opts);
119+
odb_source_loose_for_each_object(source, NULL, update_disambiguate_state,
120+
ds, &opts);
121121
}
122122

123123
static int finish_object_disambiguation(struct disambiguate_state *ds,
@@ -508,7 +508,8 @@ static enum get_oid_result get_short_oid(struct repository *r,
508508
opts.prefix = &ds.bin_pfx;
509509
opts.prefix_hex_len = ds.len;
510510

511-
odb_for_each_object_ext(r->objects, NULL, match_prefix, &ds, &opts);
511+
odb_for_each_object_ext(r->objects, NULL, update_disambiguate_state,
512+
&ds, &opts);
512513
status = finish_object_disambiguation(&ds, oid);
513514

514515
/*
@@ -518,7 +519,8 @@ static enum get_oid_result get_short_oid(struct repository *r,
518519
*/
519520
if (status == MISSING_OBJECT) {
520521
odb_reprepare(r->objects);
521-
odb_for_each_object_ext(r->objects, NULL, match_prefix, &ds, &opts);
522+
odb_for_each_object_ext(r->objects, NULL, update_disambiguate_state,
523+
&ds, &opts);
522524
status = finish_object_disambiguation(&ds, oid);
523525
}
524526

0 commit comments

Comments
 (0)