fmt-merge-msg: don't use static buffer in record_person

The record_person function just parses out the "name" field of the person line in a commit and adds it to a string_list. The only reason we need an extra buffer is that the string_list functions require a NUL-terminated string. Instead of the static buffer, we can just allocate a temporary NUL-terminated copy. In addition to removing a useless limit, this removes the only user of MAX_GITNAME outside of ident.c. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed May 21, 2012 at 19:09 UTC e21ab1340a1a22f017e9c3e4fc0deb9f4de36917
1 file changed +4 -4
builtin/fmt-merge-msg.c
+4 -4
@@ -230,7 +230,7 @@ static void add_branch_desc(struct strbuf *out, const char *name)
230 static void record_person(int which, struct string_list *people,
231 struct commit *commit)
232 {
233 - char name_buf[MAX_GITNAME], *name, *name_end;
233 + char *name_buf, *name, *name_end;
234 struct string_list_item *elem;
235 const char *field = (which == 'a') ? "\nauthor " : "\ncommitter ";
236
@@ -243,10 +243,9 @@ static void record_person(int which, struct string_list *people,
243 name_end--;
244 while (isspace(*name_end) && name <= name_end)
245 name_end--;
246 - if (name_end < name || name + MAX_GITNAME <= name_end)
246 + if (name_end < name)
247 return;
248 - memcpy(name_buf, name, name_end - name + 1);
249 - name_buf[name_end - name + 1] = '\0';
248 + name_buf = xmemdupz(name, name_end - name + 1);
249
250 elem = string_list_lookup(people, name_buf);
251 if (!elem) {
@@ -254,6 +253,7 @@ static void record_person(int which, struct string_list *people,
253 elem->util = (void *)0;
254 }
255 elem->util = (void*)(util_as_integral(elem) + 1);
256 + free(name_buf);
257 }
258
259 static int cmp_string_list_util_as_integral(const void *a_, const void *b_)