From: ZheNing Hu <adlternative@xxxxxxxxx> There are many global options variables in ref-filter, e.g. need_tagged, need_symref, which may affect the reentrancy of the functions. Moving these variables into ref_format which can make the code cleaner. Mentored-by: Christian Couder <christian.couder@xxxxxxxxx> Mentored-by: Hariom Verma <hariom18599@xxxxxxxxx> Signed-off-by: ZheNing Hu <adlternative@xxxxxxxxx> --- ref-filter.c | 14 +++++++------- ref-filter.h | 2 ++ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/ref-filter.c b/ref-filter.c index e4f96dad504..29be1e865d2 100644 --- a/ref-filter.c +++ b/ref-filter.c @@ -213,7 +213,7 @@ static struct used_atom { char *head; } u; } *used_atom; -static int used_atom_cnt, need_tagged, need_symref; +static int used_atom_cnt; /* * Expand string, append it to strbuf *sb, then return error code ret. @@ -499,7 +499,7 @@ static int person_email_atom_parser(struct ref_format *format, struct used_atom static int symref_atom_parser(struct ref_format *format, struct used_atom *atom, const char *arg, struct strbuf *err) { - need_symref = 1; + format->need_symref = 1; return refname_atom_parser_internal(&atom->u.refname, arg, atom->name, err); } @@ -769,7 +769,7 @@ static int parse_ref_filter_atom(struct ref_format *format, if (valid_atom[i].parser && valid_atom[i].parser(format, &used_atom[at], arg, err)) return -1; if (deref) - need_tagged = 1; + format->need_tagged = 1; return at; } @@ -1816,10 +1816,10 @@ static int populate_value(struct ref_array_item *ref, struct strbuf *err) struct object *obj; int i; struct object_info empty = OBJECT_INFO_INIT; - + struct ref_format *format = ref->format; CALLOC_ARRAY(ref->value, used_atom_cnt); - if (need_symref && (ref->flag & REF_ISSYMREF) && !ref->symref) { + if (format->need_symref && (ref->flag & REF_ISSYMREF) && !ref->symref) { ref->symref = resolve_refdup(ref->refname, RESOLVE_REF_READING, NULL, NULL); if (!ref->symref) @@ -1958,7 +1958,7 @@ static int populate_value(struct ref_array_item *ref, struct strbuf *err) oid_to_hex(&ref->objectname), ref->refname); } - if (need_tagged) + if (format->need_tagged) oi.info.contentp = &oi.content; if (!memcmp(&oi.info, &empty, sizeof(empty)) && !memcmp(&oi_deref.info, &empty, sizeof(empty))) @@ -1973,7 +1973,7 @@ static int populate_value(struct ref_array_item *ref, struct strbuf *err) * If there is no atom that wants to know about tagged * object, we are done. */ - if (!need_tagged || (obj->type != OBJ_TAG)) + if (!format->need_tagged || (obj->type != OBJ_TAG)) return 0; /* diff --git a/ref-filter.h b/ref-filter.h index e95c055fb86..ec4cc1e5f9c 100644 --- a/ref-filter.h +++ b/ref-filter.h @@ -86,6 +86,8 @@ struct ref_format { /* Internal state to ref-filter */ int need_color_reset_at_eol; + int need_tagged; + int need_symref; }; #define REF_FORMAT_INIT { .use_color = -1 } -- gitgitgadget