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

Function reftable_backend_read_ref

refs/reftable-backend.c:66–123  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

64}
65
66static int reftable_backend_read_ref(struct reftable_backend *be,
67 const char *refname,
68 struct object_id *oid,
69 struct strbuf *referent,
70 unsigned int *type)
71{
72 struct reftable_ref_record ref = {0};
73 int ret;
74
75 if (!be->it.ops) {
76 ret = reftable_stack_init_ref_iterator(be->stack, &be->it);
77 if (ret)
78 goto done;
79 }
80
81 ret = reftable_iterator_seek_ref(&be->it, refname);
82 if (ret)
83 goto done;
84
85 ret = reftable_iterator_next_ref(&be->it, &ref);
86 if (ret)
87 goto done;
88
89 if (strcmp(ref.refname, refname)) {
90 ret = 1;
91 goto done;
92 }
93
94 if (ref.value_type == REFTABLE_REF_SYMREF) {
95 strbuf_reset(referent);
96 strbuf_addstr(referent, ref.value.symref);
97 *type |= REF_ISSYMREF;
98 } else if (reftable_ref_record_val1(&ref)) {
99 unsigned int hash_id;
100
101 switch (reftable_stack_hash_id(be->stack)) {
102 case REFTABLE_HASH_SHA1:
103 hash_id = GIT_HASH_SHA1;
104 break;
105 case REFTABLE_HASH_SHA256:
106 hash_id = GIT_HASH_SHA256;
107 break;
108 default:
109 BUG("unhandled hash ID %d", reftable_stack_hash_id(be->stack));
110 }
111
112 oidread(oid, reftable_ref_record_val1(&ref),
113 &hash_algos[hash_id]);
114 } else {
115 /* We got a tombstone, which should not happen. */
116 BUG("unhandled reference value type %d", ref.value_type);
117 }
118
119done:
120 assert(ret != REFTABLE_API_ERROR);
121 reftable_ref_record_release(&ref);
122 return ret;
123}

Callers 6

reftable_be_read_raw_refFunction · 0.85
prepare_single_updateFunction · 0.85
write_copy_tableFunction · 0.85

Calls 8

strbuf_addstrFunction · 0.85
reftable_ref_record_val1Function · 0.85
reftable_stack_hash_idFunction · 0.85
oidreadFunction · 0.85

Tested by

no test coverage detected