Merge branch 'zh/format-ref-array-optim'
"git (branch|tag) --format=..." has been micro-optimized. * zh/format-ref-array-optim: ref-filter: reuse output buffer ref-filter: get rid of show_ref_array_item
This commit is contained in:
commit
c108c8c2f2
@ -411,6 +411,8 @@ static void print_ref_list(struct ref_filter *filter, struct ref_sorting *sortin
|
||||
{
|
||||
int i;
|
||||
struct ref_array array;
|
||||
struct strbuf out = STRBUF_INIT;
|
||||
struct strbuf err = STRBUF_INIT;
|
||||
int maxwidth = 0;
|
||||
const char *remote_prefix = "";
|
||||
char *to_free = NULL;
|
||||
@ -440,8 +442,8 @@ static void print_ref_list(struct ref_filter *filter, struct ref_sorting *sortin
|
||||
ref_array_sort(sorting, &array);
|
||||
|
||||
for (i = 0; i < array.nr; i++) {
|
||||
struct strbuf out = STRBUF_INIT;
|
||||
struct strbuf err = STRBUF_INIT;
|
||||
strbuf_reset(&err);
|
||||
strbuf_reset(&out);
|
||||
if (format_ref_array_item(array.items[i], format, &out, &err))
|
||||
die("%s", err.buf);
|
||||
if (column_active(colopts)) {
|
||||
@ -452,10 +454,10 @@ static void print_ref_list(struct ref_filter *filter, struct ref_sorting *sortin
|
||||
fwrite(out.buf, 1, out.len, stdout);
|
||||
putchar('\n');
|
||||
}
|
||||
strbuf_release(&err);
|
||||
strbuf_release(&out);
|
||||
}
|
||||
|
||||
strbuf_release(&err);
|
||||
strbuf_release(&out);
|
||||
ref_array_clear(&array);
|
||||
free(to_free);
|
||||
}
|
||||
|
@ -22,6 +22,8 @@ int cmd_for_each_ref(int argc, const char **argv, const char *prefix)
|
||||
struct ref_array array;
|
||||
struct ref_filter filter;
|
||||
struct ref_format format = REF_FORMAT_INIT;
|
||||
struct strbuf output = STRBUF_INIT;
|
||||
struct strbuf err = STRBUF_INIT;
|
||||
|
||||
struct option opts[] = {
|
||||
OPT_BIT('s', "shell", &format.quote_style,
|
||||
@ -80,8 +82,17 @@ int cmd_for_each_ref(int argc, const char **argv, const char *prefix)
|
||||
|
||||
if (!maxcount || array.nr < maxcount)
|
||||
maxcount = array.nr;
|
||||
for (i = 0; i < maxcount; i++)
|
||||
show_ref_array_item(array.items[i], &format);
|
||||
for (i = 0; i < maxcount; i++) {
|
||||
strbuf_reset(&err);
|
||||
strbuf_reset(&output);
|
||||
if (format_ref_array_item(array.items[i], &format, &output, &err))
|
||||
die("%s", err.buf);
|
||||
fwrite(output.buf, 1, output.len, stdout);
|
||||
putchar('\n');
|
||||
}
|
||||
|
||||
strbuf_release(&err);
|
||||
strbuf_release(&output);
|
||||
ref_array_clear(&array);
|
||||
return 0;
|
||||
}
|
||||
|
@ -39,6 +39,8 @@ static int list_tags(struct ref_filter *filter, struct ref_sorting *sorting,
|
||||
struct ref_format *format)
|
||||
{
|
||||
struct ref_array array;
|
||||
struct strbuf output = STRBUF_INIT;
|
||||
struct strbuf err = STRBUF_INIT;
|
||||
char *to_free = NULL;
|
||||
int i;
|
||||
|
||||
@ -63,8 +65,17 @@ static int list_tags(struct ref_filter *filter, struct ref_sorting *sorting,
|
||||
filter_refs(&array, filter, FILTER_REFS_TAGS);
|
||||
ref_array_sort(sorting, &array);
|
||||
|
||||
for (i = 0; i < array.nr; i++)
|
||||
show_ref_array_item(array.items[i], format);
|
||||
for (i = 0; i < array.nr; i++) {
|
||||
strbuf_reset(&output);
|
||||
strbuf_reset(&err);
|
||||
if (format_ref_array_item(array.items[i], format, &output, &err))
|
||||
die("%s", err.buf);
|
||||
fwrite(output.buf, 1, output.len, stdout);
|
||||
putchar('\n');
|
||||
}
|
||||
|
||||
strbuf_release(&err);
|
||||
strbuf_release(&output);
|
||||
ref_array_clear(&array);
|
||||
free(to_free);
|
||||
|
||||
|
25
ref-filter.c
25
ref-filter.c
@ -2435,27 +2435,22 @@ int format_ref_array_item(struct ref_array_item *info,
|
||||
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;
|
||||
|
||||
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');
|
||||
}
|
||||
|
||||
void pretty_print_ref(const char *name, const struct object_id *oid,
|
||||
const struct ref_format *format)
|
||||
{
|
||||
struct ref_array_item *ref_item;
|
||||
struct strbuf output = STRBUF_INIT;
|
||||
struct strbuf err = STRBUF_INIT;
|
||||
|
||||
ref_item = new_ref_array_item(name, oid);
|
||||
ref_item->kind = ref_kind_from_refname(name);
|
||||
show_ref_array_item(ref_item, format);
|
||||
if (format_ref_array_item(ref_item, format, &output, &err))
|
||||
die("%s", err.buf);
|
||||
fwrite(output.buf, 1, output.len, stdout);
|
||||
putchar('\n');
|
||||
|
||||
strbuf_release(&err);
|
||||
strbuf_release(&output);
|
||||
free_array_item(ref_item);
|
||||
}
|
||||
|
||||
|
@ -119,8 +119,6 @@ int format_ref_array_item(struct ref_array_item *info,
|
||||
const struct ref_format *format,
|
||||
struct strbuf *final_buf,
|
||||
struct strbuf *error_buf);
|
||||
/* Print the ref using the given format and quote_style */
|
||||
void show_ref_array_item(struct ref_array_item *info, const struct ref_format *format);
|
||||
/* Parse a single sort specifier and add it to the list */
|
||||
void parse_ref_sorting(struct ref_sorting **sorting_tail, const char *atom);
|
||||
/* Callback function for parsing the sort option */
|
||||
|
Loading…
Reference in New Issue
Block a user