merge: use commit-slab in merge remote desc instead of commit->util

It's done so that commit->util can be removed. See more explanation in
the commit that removes commit->util.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Nguyễn Thái Ngọc Duy 2018-05-19 07:28:30 +02:00 коммит произвёл Junio C Hamano
Родитель 7b680d32f3
Коммит e2e5ac2303
4 изменённых файлов: 29 добавлений и 18 удалений

Просмотреть файл

@ -443,6 +443,7 @@ static void merge_name(const char *remote, struct strbuf *msg)
struct object_id branch_head;
struct strbuf buf = STRBUF_INIT;
struct strbuf bname = STRBUF_INIT;
struct merge_remote_desc *desc;
const char *ptr;
char *found_ref;
int len, early;
@ -515,16 +516,13 @@ static void merge_name(const char *remote, struct strbuf *msg)
strbuf_release(&truname);
}
if (remote_head->util) {
struct merge_remote_desc *desc;
desc = merge_remote_util(remote_head);
if (desc && desc->obj && desc->obj->type == OBJ_TAG) {
strbuf_addf(msg, "%s\t\t%s '%s'\n",
oid_to_hex(&desc->obj->oid),
type_name(desc->obj->type),
remote);
goto cleanup;
}
desc = merge_remote_util(remote_head);
if (desc && desc->obj && desc->obj->type == OBJ_TAG) {
strbuf_addf(msg, "%s\t\t%s '%s'\n",
oid_to_hex(&desc->obj->oid),
type_name(desc->obj->type),
remote);
goto cleanup;
}
strbuf_addf(msg, "%s\t\tcommit '%s'\n",
@ -932,8 +930,11 @@ static void write_merge_heads(struct commit_list *remoteheads)
for (j = remoteheads; j; j = j->next) {
struct object_id *oid;
struct commit *c = j->item;
if (c->util && merge_remote_util(c)->obj) {
oid = &merge_remote_util(c)->obj->oid;
struct merge_remote_desc *desc;
desc = merge_remote_util(c);
if (desc && desc->obj) {
oid = &desc->obj->oid;
} else {
oid = &c->object.oid;
}

Просмотреть файл

@ -1574,13 +1574,21 @@ out:
return result;
}
define_commit_slab(merge_desc_slab, struct merge_remote_desc *);
static struct merge_desc_slab merge_desc_slab = COMMIT_SLAB_INIT(1, merge_desc_slab);
struct merge_remote_desc *merge_remote_util(struct commit *commit)
{
return *merge_desc_slab_at(&merge_desc_slab, commit);
}
void set_merge_remote_desc(struct commit *commit,
const char *name, struct object *obj)
{
struct merge_remote_desc *desc;
FLEX_ALLOC_STR(desc, name, name);
desc->obj = obj;
commit->util = desc;
*merge_desc_slab_at(&merge_desc_slab, commit) = desc;
}
struct commit *get_merge_parent(const char *name)
@ -1592,7 +1600,7 @@ struct commit *get_merge_parent(const char *name)
return NULL;
obj = parse_object(&oid);
commit = (struct commit *)peel_to_type(name, 0, obj, OBJ_COMMIT);
if (commit && !commit->util)
if (commit && !merge_remote_util(commit))
set_merge_remote_desc(commit, name, obj);
return commit;
}

Просмотреть файл

@ -303,7 +303,7 @@ struct merge_remote_desc {
struct object *obj; /* the named object, could be a tag */
char name[FLEX_ARRAY];
};
#define merge_remote_util(commit) ((struct merge_remote_desc *)((commit)->util))
extern struct merge_remote_desc *merge_remote_util(struct commit *);
extern void set_merge_remote_desc(struct commit *commit,
const char *name, struct object *obj);

Просмотреть файл

@ -223,10 +223,12 @@ static void output(struct merge_options *o, int v, const char *fmt, ...)
static void output_commit_title(struct merge_options *o, struct commit *commit)
{
struct merge_remote_desc *desc;
strbuf_addchars(&o->obuf, ' ', o->call_depth * 2);
if (commit->util)
strbuf_addf(&o->obuf, "virtual %s\n",
merge_remote_util(commit)->name);
desc = merge_remote_util(commit);
if (desc)
strbuf_addf(&o->obuf, "virtual %s\n", desc->name);
else {
strbuf_add_unique_abbrev(&o->obuf, &commit->object.oid,
DEFAULT_ABBREV);