MCPcopy Index your code
hub / github.com/git/git / label_oid

Function label_oid

sequencer.c:5763–5897  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5761};
5762
5763static const char *label_oid(struct object_id *oid, const char *label,
5764 struct label_state *state)
5765{
5766 struct labels_entry *labels_entry;
5767 struct string_entry *string_entry;
5768 struct object_id dummy;
5769 int i;
5770
5771 string_entry = oidmap_get(&state->commit2label, oid);
5772 if (string_entry)
5773 return string_entry->string;
5774
5775 /*
5776 * For "uninteresting" commits, i.e. commits that are not to be
5777 * rebased, and which can therefore not be labeled, we use a unique
5778 * abbreviation of the commit name. This is slightly more complicated
5779 * than calling repo_find_unique_abbrev() because we also need to make
5780 * sure that the abbreviation does not conflict with any other
5781 * label.
5782 *
5783 * We disallow "interesting" commits to be labeled by a string that
5784 * is a valid full-length hash, to ensure that we always can find an
5785 * abbreviation for any uninteresting commit's names that does not
5786 * clash with any other label.
5787 */
5788 strbuf_reset(&state->buf);
5789 if (!label) {
5790 char *p;
5791
5792 strbuf_grow(&state->buf, GIT_MAX_HEXSZ);
5793 label = p = state->buf.buf;
5794
5795 repo_find_unique_abbrev_r(the_repository, p, oid,
5796 default_abbrev);
5797
5798 /*
5799 * We may need to extend the abbreviated hash so that there is
5800 * no conflicting label.
5801 */
5802 if (hashmap_get_from_hash(&state->labels, strihash(p), p)) {
5803 size_t i = strlen(p) + 1;
5804
5805 oid_to_hex_r(p, oid);
5806 for (; i < the_hash_algo->hexsz; i++) {
5807 char save = p[i];
5808 p[i] = '\0';
5809 if (!hashmap_get_from_hash(&state->labels,
5810 strihash(p), p))
5811 break;
5812 p[i] = save;
5813 }
5814 }
5815 } else {
5816 struct strbuf *buf = &state->buf;
5817 int label_is_utf8 = 1; /* start with this assumption */
5818 size_t max_len = buf->len + state->max_label_length;
5819
5820 /*

Callers 1

make_script_with_mergesFunction · 0.85

Calls 15

oidmap_getFunction · 0.85
strbuf_growFunction · 0.85
hashmap_get_from_hashFunction · 0.85
strihashFunction · 0.85
oid_to_hex_rFunction · 0.85
strbuf_addchFunction · 0.85
utf8_widthFunction · 0.85
strbuf_addFunction · 0.85
strbuf_addstrFunction · 0.85
strbuf_add_unique_abbrevFunction · 0.85
get_oid_hexFunction · 0.85

Tested by

no test coverage detected