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

Function do_label

sequencer.c:3944–3983  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3942}
3943
3944static int do_label(struct repository *r, const char *name, int len)
3945{
3946 struct ref_store *refs = get_main_ref_store(r);
3947 struct ref_transaction *transaction;
3948 struct strbuf ref_name = STRBUF_INIT, err = STRBUF_INIT;
3949 struct strbuf msg = STRBUF_INIT;
3950 int ret = 0;
3951 struct object_id head_oid;
3952
3953 if (len == 1 && *name == '#')
3954 return error(_("illegal label name: '%.*s'"), len, name);
3955
3956 strbuf_addf(&ref_name, "refs/rewritten/%.*s", len, name);
3957 strbuf_addf(&msg, "rebase (label) '%.*s'", len, name);
3958
3959 transaction = ref_store_transaction_begin(refs, 0, &err);
3960 if (!transaction) {
3961 error("%s", err.buf);
3962 ret = -1;
3963 } else if (repo_get_oid(r, "HEAD", &head_oid)) {
3964 error(_("could not read HEAD"));
3965 ret = -1;
3966 } else if (ref_transaction_update(transaction, ref_name.buf,
3967 &head_oid, NULL, NULL, NULL,
3968 0, msg.buf, &err) < 0 ||
3969 ref_transaction_commit(transaction, &err)) {
3970 error("%s", err.buf);
3971 ret = -1;
3972 }
3973 ref_transaction_free(transaction);
3974 strbuf_release(&err);
3975 strbuf_release(&msg);
3976
3977 if (!ret)
3978 ret = safe_append(rebase_path_refs_to_delete(),
3979 "%s\n", ref_name.buf);
3980 strbuf_release(&ref_name);
3981
3982 return ret;
3983}
3984
3985static struct commit *lookup_label(struct repository *r, const char *label,
3986 int len, struct strbuf *buf)

Callers 1

pick_commitsFunction · 0.85

Calls 10

get_main_ref_storeFunction · 0.85
errorFunction · 0.85
strbuf_addfFunction · 0.85
repo_get_oidFunction · 0.85
ref_transaction_updateFunction · 0.85
ref_transaction_commitFunction · 0.85
ref_transaction_freeFunction · 0.85
strbuf_releaseFunction · 0.85
safe_appendFunction · 0.85

Tested by

no test coverage detected