struct atom_value {
const char *s;
+ void (*handler)(struct atom_value *atomv, struct ref_formatting_state *state);
unsigned long ul; /* used for sorting when not FIELD_STR */
};
return at;
}
+static void quote_formatting(struct strbuf *s, const char *str, int quote_style)
+{
+ switch (quote_style) {
+ case QUOTE_NONE:
+ strbuf_addstr(s, str);
+ break;
+ case QUOTE_SHELL:
+ sq_quote_buf(s, str);
+ break;
+ case QUOTE_PERL:
+ perl_quote_buf(s, str);
+ break;
+ case QUOTE_PYTHON:
+ python_quote_buf(s, str);
+ break;
+ case QUOTE_TCL:
+ tcl_quote_buf(s, str);
+ break;
+ }
+}
+
+static void append_atom(struct atom_value *v, struct ref_formatting_state *state)
+{
+ quote_formatting(&state->stack->output, v->s, state->quote_style);
+}
+
static void push_stack_element(struct ref_formatting_stack **stack)
{
struct ref_formatting_stack *s = xcalloc(1, sizeof(struct ref_formatting_stack));
const char *formatp;
struct branch *branch = NULL;
+ v->handler = append_atom;
+
if (*name == '*') {
deref = 1;
name++;
qsort(array->items, array->nr, sizeof(struct ref_array_item *), compare_refs);
}
-static void append_atom(struct atom_value *v, struct ref_formatting_state *state)
-{
- struct strbuf *s = &state->stack->output;
-
- switch (state->quote_style) {
- case QUOTE_NONE:
- strbuf_addstr(s, v->s);
- break;
- case QUOTE_SHELL:
- sq_quote_buf(s, v->s);
- break;
- case QUOTE_PERL:
- perl_quote_buf(s, v->s);
- break;
- case QUOTE_PYTHON:
- python_quote_buf(s, v->s);
- break;
- case QUOTE_TCL:
- tcl_quote_buf(s, v->s);
- break;
- }
-}
-
static int hex1(char ch)
{
if ('0' <= ch && ch <= '9')
if (cp < sp)
append_literal(cp, sp, &state);
get_ref_atom_value(info, parse_ref_filter_atom(sp + 2, ep), &atomv);
- append_atom(atomv, &state);
+ atomv->handler(atomv, &state);
}
if (*cp) {
sp = cp + strlen(cp);