diff options
author | Junio C Hamano <gitster@pobox.com> | 2014-09-11 10:33:36 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2014-09-11 10:33:36 -0700 |
commit | 1ebe6a825a1ff12e12905e28265aa30e269700d6 (patch) | |
tree | 0ad33ffa41525b67198a5d756a8e5beedee2ea73 /log-tree.c | |
parent | f28763d7561f66c0c6ff9b5d48146a0f923781d3 (diff) | |
parent | 2e3dfb216991974b60fdb1933eb3331e03383e61 (diff) | |
download | git-1ebe6a825a1ff12e12905e28265aa30e269700d6.tar.gz |
Merge branch 'jk/name-decoration-alloc'
The API to allocate the structure to keep track of commit
decoration was cumbersome to use, inviting lazy code to
overallocate memory.
* jk/name-decoration-alloc:
log-tree: use FLEX_ARRAY in name_decoration
log-tree: make name_decoration hash static
log-tree: make add_name_decoration a public function
Diffstat (limited to 'log-tree.c')
-rw-r--r-- | log-tree.c | 25 |
1 files changed, 10 insertions, 15 deletions
diff --git a/log-tree.c b/log-tree.c index 95e9b1da25..bcee7c5966 100644 --- a/log-tree.c +++ b/log-tree.c @@ -12,17 +12,7 @@ #include "sequencer.h" #include "line-log.h" -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 struct decoration name_decoration = { "object names" }; static char decoration_colors[][COLOR_MAXLEN] = { GIT_COLOR_RESET, @@ -84,15 +74,20 @@ 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); + struct name_decoration *res = xmalloc(sizeof(*res) + nlen + 1); memcpy(res->name, name, nlen + 1); res->type = type; res->next = add_decoration(&name_decoration, obj, res); } +const struct name_decoration *get_name_decoration(const struct object *obj) +{ + return lookup_decoration(&name_decoration, obj); +} + static int add_ref_decoration(const char *refname, const unsigned char *sha1, int flags, void *cb_data) { struct object *obj; @@ -187,13 +182,13 @@ void format_decorations(struct strbuf *sb, int use_color) { const char *prefix; - struct name_decoration *decoration; + const struct name_decoration *decoration; const char *color_commit = diff_get_color(use_color, DIFF_COMMIT); const char *color_reset = decorate_get_color(use_color, DECORATION_NONE); - decoration = lookup_decoration(&name_decoration, &commit->object); + decoration = get_name_decoration(&commit->object); if (!decoration) return; prefix = " ("; |