Merge branch 'vd/for-each-ref-unsorted-optimization'
"git for-each-ref --no-sort" still sorted the refs alphabetically which paid non-trivial cost. It has been redefined to show output in an unspecified order, to allow certain optimizations to take advantage of. * vd/for-each-ref-unsorted-optimization: t/perf: add perf tests for for-each-ref ref-filter.c: use peeled tag for '*' format fields for-each-ref: clean up documentation of --format ref-filter.c: filter & format refs in the same callback ref-filter.c: refactor to create common helper functions ref-filter.c: rename 'ref_filter_handler()' to 'filter_one()' ref-filter.h: add functions for filter/format & format-only ref-filter.h: move contains caches into filter ref-filter.h: add max_count and omit_empty to ref_format ref-filter.c: really don't sort when using --no-sort
This commit is contained in:
@ -45,7 +45,6 @@ static const char *head;
|
||||
static struct object_id head_oid;
|
||||
static int recurse_submodules = 0;
|
||||
static int submodule_propagate_branches = 0;
|
||||
static int omit_empty = 0;
|
||||
|
||||
static int branch_use_color = -1;
|
||||
static char branch_colors[][COLOR_MAXLEN] = {
|
||||
@ -438,8 +437,6 @@ 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;
|
||||
@ -469,24 +466,27 @@ static void print_ref_list(struct ref_filter *filter, struct ref_sorting *sortin
|
||||
filter_ahead_behind(the_repository, format, &array);
|
||||
ref_array_sort(sorting, &array);
|
||||
|
||||
for (i = 0; i < array.nr; i++) {
|
||||
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)) {
|
||||
assert(!filter->verbose && "--column and --verbose are incompatible");
|
||||
/* format to a string_list to let print_columns() do its job */
|
||||
if (column_active(colopts)) {
|
||||
struct strbuf out = STRBUF_INIT, err = STRBUF_INIT;
|
||||
|
||||
assert(!filter->verbose && "--column and --verbose are incompatible");
|
||||
|
||||
for (i = 0; i < array.nr; i++) {
|
||||
strbuf_reset(&err);
|
||||
strbuf_reset(&out);
|
||||
if (format_ref_array_item(array.items[i], format, &out, &err))
|
||||
die("%s", err.buf);
|
||||
|
||||
/* format to a string_list to let print_columns() do its job */
|
||||
string_list_append(output, out.buf);
|
||||
} else {
|
||||
fwrite(out.buf, 1, out.len, stdout);
|
||||
if (out.len || !omit_empty)
|
||||
putchar('\n');
|
||||
}
|
||||
|
||||
strbuf_release(&err);
|
||||
strbuf_release(&out);
|
||||
} else {
|
||||
print_formatted_ref_array(&array, format);
|
||||
}
|
||||
|
||||
strbuf_release(&err);
|
||||
strbuf_release(&out);
|
||||
ref_array_clear(&array);
|
||||
free(to_free);
|
||||
}
|
||||
@ -737,7 +737,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
|
||||
OPT_BIT('D', NULL, &delete, N_("delete branch (even if not merged)"), 2),
|
||||
OPT_BIT('m', "move", &rename, N_("move/rename a branch and its reflog"), 1),
|
||||
OPT_BIT('M', NULL, &rename, N_("move/rename a branch, even if target exists"), 2),
|
||||
OPT_BOOL(0, "omit-empty", &omit_empty,
|
||||
OPT_BOOL(0, "omit-empty", &format.array_opts.omit_empty,
|
||||
N_("do not output a newline after empty formatted refs")),
|
||||
OPT_BIT('c', "copy", ©, N_("copy a branch and its reflog"), 1),
|
||||
OPT_BIT('C', NULL, ©, N_("copy a branch, even if target exists"), 2),
|
||||
@ -767,7 +767,13 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
|
||||
if (argc == 2 && !strcmp(argv[1], "-h"))
|
||||
usage_with_options(builtin_branch_usage, options);
|
||||
|
||||
/*
|
||||
* Try to set sort keys from config. If config does not set any,
|
||||
* fall back on default (refname) sorting.
|
||||
*/
|
||||
git_config(git_branch_config, &sorting_options);
|
||||
if (!sorting_options.nr)
|
||||
string_list_append(&sorting_options, "refname");
|
||||
|
||||
track = git_branch_track;
|
||||
|
||||
|
Reference in New Issue
Block a user