|
12 | 12 | #include "packfile.h"
|
13 | 13 | #include "object-store.h"
|
14 | 14 | #include "repository.h"
|
| 15 | +#include "midx.h" |
15 | 16 |
|
16 | 17 | static int get_oid_oneline(const char *, struct object_id *, struct commit_list *);
|
17 | 18 |
|
@@ -149,6 +150,32 @@ static int match_sha(unsigned len, const unsigned char *a, const unsigned char *
|
149 | 150 | return 1;
|
150 | 151 | }
|
151 | 152 |
|
| 153 | +static void unique_in_midx(struct multi_pack_index *m, |
| 154 | + struct disambiguate_state *ds) |
| 155 | +{ |
| 156 | + uint32_t num, i, first = 0; |
| 157 | + const struct object_id *current = NULL; |
| 158 | + num = m->num_objects; |
| 159 | + |
| 160 | + if (!num) |
| 161 | + return; |
| 162 | + |
| 163 | + bsearch_midx(&ds->bin_pfx, m, &first); |
| 164 | + |
| 165 | + /* |
| 166 | + * At this point, "first" is the location of the lowest object |
| 167 | + * with an object name that could match "bin_pfx". See if we have |
| 168 | + * 0, 1 or more objects that actually match(es). |
| 169 | + */ |
| 170 | + for (i = first; i < num && !ds->ambiguous; i++) { |
| 171 | + struct object_id oid; |
| 172 | + current = nth_midxed_object_oid(&oid, m, i); |
| 173 | + if (!match_sha(ds->len, ds->bin_pfx.hash, current->hash)) |
| 174 | + break; |
| 175 | + update_candidates(ds, current); |
| 176 | + } |
| 177 | +} |
| 178 | + |
152 | 179 | static void unique_in_pack(struct packed_git *p,
|
153 | 180 | struct disambiguate_state *ds)
|
154 | 181 | {
|
@@ -177,8 +204,12 @@ static void unique_in_pack(struct packed_git *p,
|
177 | 204 |
|
178 | 205 | static void find_short_packed_object(struct disambiguate_state *ds)
|
179 | 206 | {
|
| 207 | + struct multi_pack_index *m; |
180 | 208 | struct packed_git *p;
|
181 | 209 |
|
| 210 | + for (m = get_multi_pack_index(the_repository); m && !ds->ambiguous; |
| 211 | + m = m->next) |
| 212 | + unique_in_midx(m, ds); |
182 | 213 | for (p = get_packed_git(the_repository); p && !ds->ambiguous;
|
183 | 214 | p = p->next)
|
184 | 215 | unique_in_pack(p, ds);
|
@@ -527,6 +558,42 @@ static int extend_abbrev_len(const struct object_id *oid, void *cb_data)
|
527 | 558 | return 0;
|
528 | 559 | }
|
529 | 560 |
|
| 561 | +static void find_abbrev_len_for_midx(struct multi_pack_index *m, |
| 562 | + struct min_abbrev_data *mad) |
| 563 | +{ |
| 564 | + int match = 0; |
| 565 | + uint32_t num, first = 0; |
| 566 | + struct object_id oid; |
| 567 | + const struct object_id *mad_oid; |
| 568 | + |
| 569 | + if (!m->num_objects) |
| 570 | + return; |
| 571 | + |
| 572 | + num = m->num_objects; |
| 573 | + mad_oid = mad->oid; |
| 574 | + match = bsearch_midx(mad_oid, m, &first); |
| 575 | + |
| 576 | + /* |
| 577 | + * first is now the position in the packfile where we would insert |
| 578 | + * mad->hash if it does not exist (or the position of mad->hash if |
| 579 | + * it does exist). Hence, we consider a maximum of two objects |
| 580 | + * nearby for the abbreviation length. |
| 581 | + */ |
| 582 | + mad->init_len = 0; |
| 583 | + if (!match) { |
| 584 | + if (nth_midxed_object_oid(&oid, m, first)) |
| 585 | + extend_abbrev_len(&oid, mad); |
| 586 | + } else if (first < num - 1) { |
| 587 | + if (nth_midxed_object_oid(&oid, m, first + 1)) |
| 588 | + extend_abbrev_len(&oid, mad); |
| 589 | + } |
| 590 | + if (first > 0) { |
| 591 | + if (nth_midxed_object_oid(&oid, m, first - 1)) |
| 592 | + extend_abbrev_len(&oid, mad); |
| 593 | + } |
| 594 | + mad->init_len = mad->cur_len; |
| 595 | +} |
| 596 | + |
530 | 597 | static void find_abbrev_len_for_pack(struct packed_git *p,
|
531 | 598 | struct min_abbrev_data *mad)
|
532 | 599 | {
|
@@ -565,8 +632,11 @@ static void find_abbrev_len_for_pack(struct packed_git *p,
|
565 | 632 |
|
566 | 633 | static void find_abbrev_len_packed(struct min_abbrev_data *mad)
|
567 | 634 | {
|
| 635 | + struct multi_pack_index *m; |
568 | 636 | struct packed_git *p;
|
569 | 637 |
|
| 638 | + for (m = get_multi_pack_index(the_repository); m; m = m->next) |
| 639 | + find_abbrev_len_for_midx(m, mad); |
570 | 640 | for (p = get_packed_git(the_repository); p; p = p->next)
|
571 | 641 | find_abbrev_len_for_pack(p, mad);
|
572 | 642 | }
|
|
0 commit comments