summaryrefslogtreecommitdiff
path: root/ref-filter.c
diff options
context:
space:
mode:
authorOlga Telezhnaya <olyatelezhnaya@gmail.com>2018-03-29 12:49:45 (GMT)
committerJunio C Hamano <gitster@pobox.com>2018-03-29 21:24:49 (GMT)
commit3019eca918d168d5f0cb773c8853222745e1b37a (patch)
treed6acfbf69e41f411174935099d10e01857c3c149 /ref-filter.c
parente2e7a245459391a06a11b70282177135b3fe111c (diff)
downloadgit-3019eca918d168d5f0cb773c8853222745e1b37a.zip
git-3019eca918d168d5f0cb773c8853222745e1b37a.tar.gz
git-3019eca918d168d5f0cb773c8853222745e1b37a.tar.bz2
ref-filter: start adding strbufs with errors
This is a first step in removing die() calls from ref-filter formatting logic, so that it could be used by other commands that do not want to die during formatting process. die() calls related to bugs in code will not be touched in this patch. Everything would be the same for show_ref_array_item() users. But, if you want to deal with errors by your own, you could invoke format_ref_array_item(). It means that you need to print everything (the result and errors) on your side. This commit changes signature of format_ref_array_item() by adding return value and strbuf parameter for errors, and adjusts its callers. While at it, reduce the scope of the out-variable. Signed-off-by: Olga Telezhnaia <olyatelezhnaya@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'ref-filter.c')
-rw-r--r--ref-filter.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/ref-filter.c b/ref-filter.c
index 0c8d158..9833709 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -2131,9 +2131,10 @@ static void append_literal(const char *cp, const char *ep, struct ref_formatting
}
}
-void format_ref_array_item(struct ref_array_item *info,
+int format_ref_array_item(struct ref_array_item *info,
const struct ref_format *format,
- struct strbuf *final_buf)
+ struct strbuf *final_buf,
+ struct strbuf *error_buf)
{
const char *cp, *sp, *ep;
struct ref_formatting_state state = REF_FORMATTING_STATE_INIT;
@@ -2161,19 +2162,25 @@ void format_ref_array_item(struct ref_array_item *info,
resetv.s = GIT_COLOR_RESET;
append_atom(&resetv, &state);
}
- if (state.stack->prev)
- die(_("format: %%(end) atom missing"));
+ if (state.stack->prev) {
+ pop_stack_element(&state.stack);
+ return strbuf_addf_ret(error_buf, -1, _("format: %%(end) atom missing"));
+ }
strbuf_addbuf(final_buf, &state.stack->output);
pop_stack_element(&state.stack);
+ return 0;
}
void show_ref_array_item(struct ref_array_item *info,
const struct ref_format *format)
{
struct strbuf final_buf = STRBUF_INIT;
+ struct strbuf error_buf = STRBUF_INIT;
- format_ref_array_item(info, format, &final_buf);
+ if (format_ref_array_item(info, format, &final_buf, &error_buf))
+ die("%s", error_buf.buf);
fwrite(final_buf.buf, 1, final_buf.len, stdout);
+ strbuf_release(&error_buf);
strbuf_release(&final_buf);
putchar('\n');
}