MCPcopy Create free account
hub / github.com/git/git / get_short_oid

Function get_short_oid

object-name.c:456–546  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

454}
455
456static enum get_oid_result get_short_oid(struct repository *r,
457 const char *name, int len,
458 struct object_id *oid,
459 unsigned flags)
460{
461 struct odb_for_each_object_options opts = { 0 };
462 int status;
463 struct disambiguate_state ds;
464 int quietly = !!(flags & GET_OID_QUIETLY);
465 const struct git_hash_algo *algo = r->hash_algo;
466
467 if (flags & GET_OID_HASH_ANY)
468 algo = NULL;
469
470 if (init_object_disambiguation(r, name, len, algo, &ds) < 0)
471 return -1;
472
473 if (HAS_MULTI_BITS(flags & GET_OID_DISAMBIGUATORS))
474 BUG("multiple get_short_oid disambiguator flags");
475
476 if (flags & GET_OID_COMMIT)
477 ds.fn = disambiguate_commit_only;
478 else if (flags & GET_OID_COMMITTISH)
479 ds.fn = disambiguate_committish_only;
480 else if (flags & GET_OID_TREE)
481 ds.fn = disambiguate_tree_only;
482 else if (flags & GET_OID_TREEISH)
483 ds.fn = disambiguate_treeish_only;
484 else if (flags & GET_OID_BLOB)
485 ds.fn = disambiguate_blob_only;
486 else
487 ds.fn = default_disambiguate_hint;
488
489 opts.prefix = &ds.bin_pfx;
490 opts.prefix_hex_len = ds.len;
491
492 odb_for_each_object_ext(r->objects, NULL, update_disambiguate_state,
493 &ds, &opts);
494 status = finish_object_disambiguation(&ds, oid);
495
496 /*
497 * If we didn't find it, do the usual reprepare() slow-path,
498 * since the object may have recently been added to the repository
499 * or migrated from loose to packed.
500 */
501 if (status == MISSING_OBJECT) {
502 odb_reprepare(r->objects);
503 odb_for_each_object_ext(r->objects, NULL, update_disambiguate_state,
504 &ds, &opts);
505 status = finish_object_disambiguation(&ds, oid);
506 }
507
508 if (!quietly && (status == SHORT_NAME_AMBIGUOUS)) {
509 struct oid_array collect = OID_ARRAY_INIT;
510 struct ambiguous_output out = {
511 .ds = &ds,
512 .sb = STRBUF_INIT,
513 .advice = STRBUF_INIT,

Callers 3

get_oid_basicFunction · 0.85
get_describe_nameFunction · 0.85
get_oid_1Function · 0.85

Calls 11

odb_for_each_object_extFunction · 0.85
odb_reprepareFunction · 0.85
errorFunction · 0.85
repo_for_each_abbrevFunction · 0.85
sort_ambiguous_oid_arrayFunction · 0.85
oid_array_for_eachFunction · 0.85
adviseFunction · 0.85
oid_array_clearFunction · 0.85
strbuf_releaseFunction · 0.85

Tested by

no test coverage detected