@@ -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
111110static 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
123123static 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