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

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

@ -1574,13 +1574,21 @@ out:
return result; 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, void set_merge_remote_desc(struct commit *commit,
const char *name, struct object *obj) const char *name, struct object *obj)
{ {
struct merge_remote_desc *desc; struct merge_remote_desc *desc;
FLEX_ALLOC_STR(desc, name, name); FLEX_ALLOC_STR(desc, name, name);
desc->obj = obj; desc->obj = obj;
commit->util = desc; *merge_desc_slab_at(&merge_desc_slab, commit) = desc;
} }
struct commit *get_merge_parent(const char *name) struct commit *get_merge_parent(const char *name)
@ -1592,7 +1600,7 @@ struct commit *get_merge_parent(const char *name)
return NULL; return NULL;
obj = parse_object(&oid); obj = parse_object(&oid);
commit = (struct commit *)peel_to_type(name, 0, obj, OBJ_COMMIT); 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); set_merge_remote_desc(commit, name, obj);
return commit; return commit;
} }

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

@ -303,7 +303,7 @@ struct merge_remote_desc {
struct object *obj; /* the named object, could be a tag */ struct object *obj; /* the named object, could be a tag */
char name[FLEX_ARRAY]; 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, extern void set_merge_remote_desc(struct commit *commit,
const char *name, struct object *obj); 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) 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); strbuf_addchars(&o->obuf, ' ', o->call_depth * 2);
if (commit->util) desc = merge_remote_util(commit);
strbuf_addf(&o->obuf, "virtual %s\n", if (desc)
merge_remote_util(commit)->name); strbuf_addf(&o->obuf, "virtual %s\n", desc->name);
else { else {
strbuf_add_unique_abbrev(&o->obuf, &commit->object.oid, strbuf_add_unique_abbrev(&o->obuf, &commit->object.oid,
DEFAULT_ABBREV); DEFAULT_ABBREV);