describe: Do not use a flex array in struct commit_name
Now add_to_known_names overwrites commit_names in place when multiple tags point to the same commit. This will make it easier to store commit_names in a hash table. Signed-off-by: Anders Kaseorg <andersk@ksplice.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>maint
parent
56a5f3afa7
commit
1e1ade1833
|
@ -38,7 +38,7 @@ struct commit_name {
|
||||||
unsigned prio:2; /* annotated tag = 2, tag = 1, head = 0 */
|
unsigned prio:2; /* annotated tag = 2, tag = 1, head = 0 */
|
||||||
unsigned name_checked:1;
|
unsigned name_checked:1;
|
||||||
unsigned char sha1[20];
|
unsigned char sha1[20];
|
||||||
char path[FLEX_ARRAY]; /* more */
|
const char *path;
|
||||||
};
|
};
|
||||||
static const char *prio_names[] = {
|
static const char *prio_names[] = {
|
||||||
"head", "lightweight", "annotated",
|
"head", "lightweight", "annotated",
|
||||||
|
@ -85,15 +85,15 @@ static void add_to_known_names(const char *path,
|
||||||
struct commit_name *e = commit->util;
|
struct commit_name *e = commit->util;
|
||||||
struct tag *tag = NULL;
|
struct tag *tag = NULL;
|
||||||
if (replace_name(e, prio, sha1, &tag)) {
|
if (replace_name(e, prio, sha1, &tag)) {
|
||||||
size_t len = strlen(path)+1;
|
if (!e) {
|
||||||
free(e);
|
e = xmalloc(sizeof(struct commit_name));
|
||||||
e = xmalloc(sizeof(struct commit_name) + len);
|
commit->util = e;
|
||||||
|
}
|
||||||
e->tag = tag;
|
e->tag = tag;
|
||||||
e->prio = prio;
|
e->prio = prio;
|
||||||
e->name_checked = 0;
|
e->name_checked = 0;
|
||||||
hashcpy(e->sha1, sha1);
|
hashcpy(e->sha1, sha1);
|
||||||
memcpy(e->path, path, len);
|
e->path = path;
|
||||||
commit->util = e;
|
|
||||||
}
|
}
|
||||||
found_names = 1;
|
found_names = 1;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue