@matheusbsbs / matheus-bagliano / commits / 1e1ade1833
Fork 0

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>

Anders Kaseorg committed Dec 9, 2010 at 01:43 UTC 1e1ade1833db42a75f2792b4472748721f73c827
1 file changed +6 -6
builtin/describe.c
+6 -6
@@ -38,7 +38,7 @@ struct commit_name {
38 unsigned prio:2; /* annotated tag = 2, tag = 1, head = 0 */
39 unsigned name_checked:1;
40 unsigned char sha1[20];
41 - char path[FLEX_ARRAY]; /* more */
41 + const char *path;
42 };
43 static const char *prio_names[] = {
44 "head", "lightweight", "annotated",
@@ -85,15 +85,15 @@ static void add_to_known_names(const char *path,
85 struct commit_name *e = commit->util;
86 struct tag *tag = NULL;
87 if (replace_name(e, prio, sha1, &tag)) {
88 - size_t len = strlen(path)+1;
89 - free(e);
90 - e = xmalloc(sizeof(struct commit_name) + len);
88 + if (!e) {
89 + e = xmalloc(sizeof(struct commit_name));
90 + commit->util = e;
91 + }
92 e->tag = tag;
93 e->prio = prio;
94 e->name_checked = 0;
95 hashcpy(e->sha1, sha1);
95 - memcpy(e->path, path, len);
96 - commit->util = e;
96 + e->path = path;
97 }
98 found_names = 1;
99 }