25
#include "midx.h"
26
#include "commit-reach.h"
27
#include "date.h"
28
+#include "object-file-convert.h"
29
30
static int get_oid_oneline(struct repository *r, const char *, struct object_id *, struct commit_list *);
31
50
51
static void update_candidates(struct disambiguate_state *ds, const struct object_id *current)
52
{
53
+ /* The hash algorithm of current has already been filtered */
54
if (ds->always_call_fn) {
55
ds->ambiguous = ds->fn(ds->repo, current, ds->cb_data) ? 1 : 0;
56
return;
136
{
137
uint32_t num, i, first = 0;
138
const struct object_id *current = NULL;
139
+ int len = ds->len > ds->repo->hash_algo->hexsz ?
140
+ ds->repo->hash_algo->hexsz : ds->len;
141
num = m->num_objects;
142
143
if (!num)
153
for (i = first; i < num && !ds->ambiguous; i++) {
154
struct object_id oid;
155
current = nth_midxed_object_oid(&oid, m, i);
152
- if (!match_hash(ds->len, ds->bin_pfx.hash, current->hash))
156
+ if (!match_hash(len, ds->bin_pfx.hash, current->hash))
157
break;
158
update_candidates(ds, current);
159
}
163
struct disambiguate_state *ds)
164
{
165
uint32_t num, i, first = 0;
166
+ int len = ds->len > ds->repo->hash_algo->hexsz ?
167
+ ds->repo->hash_algo->hexsz : ds->len;
168
169
if (p->multi_pack_index)
170
return;
183
for (i = first; i < num && !ds->ambiguous; i++) {
184
struct object_id oid;
185
nth_packed_object_id(&oid, p, i);
180
- if (!match_hash(ds->len, ds->bin_pfx.hash, oid.hash))
186
+ if (!match_hash(len, ds->bin_pfx.hash, oid.hash))
187
break;
188
update_candidates(ds, &oid);
189
}
194
struct multi_pack_index *m;
195
struct packed_git *p;
196
197
+ /* Skip, unless oids from the storage hash algorithm are wanted */
198
+ if (ds->bin_pfx.algo && (&hash_algos[ds->bin_pfx.algo] != ds->repo->hash_algo))
199
+ return;
200
+
201
for (m = get_multi_pack_index(ds->repo); m && !ds->ambiguous;
202
m = m->next)
203
unique_in_midx(m, ds);
336
337
static int init_object_disambiguation(struct repository *r,
338
const char *name, int len,
339
+ const struct git_hash_algo *algo,
340
struct disambiguate_state *ds)
341
{
342
int i;
343
333
- if (len < MINIMUM_ABBREV || len > the_hash_algo->hexsz)
344
+ if (len < MINIMUM_ABBREV || len > GIT_MAX_HEXSZ)
345
return -1;
346
347
memset(ds, 0, sizeof(*ds));
368
ds->len = len;
369
ds->hex_pfx[len] = '\0';
370
ds->repo = r;
371
+ ds->bin_pfx.algo = algo ? hash_algo_by_ptr(algo) : GIT_HASH_UNKNOWN;
372
prepare_alt_odb(r);
373
return 0;
374
}
503
return collect_ambiguous(oid, data);
504
}
505
494
-static int sort_ambiguous(const void *a, const void *b, void *ctx)
506
+static int sort_ambiguous(const void *va, const void *vb, void *ctx)
507
{
508
struct repository *sort_ambiguous_repo = ctx;
509
+ const struct object_id *a = va, *b = vb;
510
int a_type = oid_object_info(sort_ambiguous_repo, a, NULL);
511
int b_type = oid_object_info(sort_ambiguous_repo, b, NULL);
512
int a_type_sort;
516
* Sorts by hash within the same object type, just as
517
* oid_array_for_each_unique() would do.
518
*/
506
- if (a_type == b_type)
507
- return oidcmp(a, b);
519
+ if (a_type == b_type) {
520
+ if (a->algo == b->algo)
521
+ return oidcmp(a, b);
522
+ else
523
+ return a->algo > b->algo ? 1 : -1;
524
+ }
525
526
/*
527
* Between object types show tags, then commits, and finally
550
int status;
551
struct disambiguate_state ds;
552
int quietly = !!(flags & GET_OID_QUIETLY);
553
+ const struct git_hash_algo *algo = r->hash_algo;
554
+
555
+ if (flags & GET_OID_HASH_ANY)
556
+ algo = NULL;
557
537
- if (init_object_disambiguation(r, name, len, &ds) < 0)
558
+ if (init_object_disambiguation(r, name, len, algo, &ds) < 0)
559
return -1;
560
561
if (HAS_MULTI_BITS(flags & GET_OID_DISAMBIGUATORS))
609
if (!ds.ambiguous)
610
ds.fn = NULL;
611
591
- repo_for_each_abbrev(r, ds.hex_pfx, collect_ambiguous, &collect);
612
+ repo_for_each_abbrev(r, ds.hex_pfx, algo, collect_ambiguous, &collect);
613
sort_ambiguous_oid_array(r, &collect);
614
615
if (oid_array_for_each(&collect, show_ambiguous_object, &out))
631
}
632
633
int repo_for_each_abbrev(struct repository *r, const char *prefix,
634
+ const struct git_hash_algo *algo,
635
each_abbrev_fn fn, void *cb_data)
636
{
637
struct oid_array collect = OID_ARRAY_INIT;
638
struct disambiguate_state ds;
639
int ret;
640
619
- if (init_object_disambiguation(r, prefix, strlen(prefix), &ds) < 0)
641
+ if (init_object_disambiguation(r, prefix, strlen(prefix), algo, &ds) < 0)
642
return -1;
643
644
ds.always_call_fn = 1;
809
int repo_find_unique_abbrev_r(struct repository *r, char *hex,
810
const struct object_id *oid, int len)
811
{
812
+ const struct git_hash_algo *algo =
813
+ oid->algo ? &hash_algos[oid->algo] : r->hash_algo;
814
struct disambiguate_state ds;
815
struct min_abbrev_data mad;
816
struct object_id oid_ret;
793
- const unsigned hexsz = r->hash_algo->hexsz;
817
+ const unsigned hexsz = algo->hexsz;
818
819
if (len < 0) {
820
unsigned long count = repo_approximate_object_count(r);
850
851
find_abbrev_len_packed(&mad);
852
829
- if (init_object_disambiguation(r, hex, mad.cur_len, &ds) < 0)
853
+ if (init_object_disambiguation(r, hex, mad.cur_len, algo, &ds) < 0)
854
return -1;
855
856
ds.fn = repo_extend_abbrev_len;