diff --git a/bisect.c b/bisect.c index 37200b41f1..59f1aeebe3 100644 --- a/bisect.c +++ b/bisect.c @@ -216,11 +216,12 @@ static struct commit_list *best_bisection_sorted(struct commit_list *list, int n } qsort(array, cnt, sizeof(*array), compare_commit_dist); for (p = list, i = 0; i < cnt; i++) { - struct name_decoration *r = xmalloc(sizeof(*r) + 100); + char buf[100]; /* enough for dist=%d */ struct object *obj = &(array[i].commit->object); - sprintf(r->name, "dist=%d", array[i].distance); - r->next = add_decoration(&name_decoration, obj, r); + snprintf(buf, sizeof(buf), "dist=%d", array[i].distance); + add_name_decoration(DECORATION_NONE, buf, obj); + p->item = array[i].commit; p = p->next; } diff --git a/commit.h b/commit.h index a9f177ba48..06c06df3ec 100644 --- a/commit.h +++ b/commit.h @@ -34,6 +34,18 @@ struct name_decoration { char name[1]; }; +enum decoration_type { + DECORATION_NONE = 0, + DECORATION_REF_LOCAL, + DECORATION_REF_REMOTE, + DECORATION_REF_TAG, + DECORATION_REF_STASH, + DECORATION_REF_HEAD, + DECORATION_GRAFTED, +}; + +void add_name_decoration(enum decoration_type type, const char *name, struct object *obj); + struct commit *lookup_commit(const unsigned char *sha1); struct commit *lookup_commit_reference(const unsigned char *sha1); struct commit *lookup_commit_reference_gently(const unsigned char *sha1, diff --git a/log-tree.c b/log-tree.c index 08970bf46e..f7c6b035c9 100644 --- a/log-tree.c +++ b/log-tree.c @@ -14,16 +14,6 @@ struct decoration name_decoration = { "object names" }; -enum decoration_type { - DECORATION_NONE = 0, - DECORATION_REF_LOCAL, - DECORATION_REF_REMOTE, - DECORATION_REF_TAG, - DECORATION_REF_STASH, - DECORATION_REF_HEAD, - DECORATION_GRAFTED, -}; - static char decoration_colors[][COLOR_MAXLEN] = { GIT_COLOR_RESET, GIT_COLOR_BOLD_GREEN, /* REF_LOCAL */ @@ -84,7 +74,7 @@ int parse_decorate_color_config(const char *var, const int ofs, const char *valu #define decorate_get_color_opt(o, ix) \ decorate_get_color((o)->use_color, ix) -static void add_name_decoration(enum decoration_type type, const char *name, struct object *obj) +void add_name_decoration(enum decoration_type type, const char *name, struct object *obj) { int nlen = strlen(name); struct name_decoration *res = xmalloc(sizeof(struct name_decoration) + nlen);