@@ -751,6 +751,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
*/
if (list_empty(&sorting.list))
ref_default_sorting(&sorting);
+ parse_ref_sorting_list(&sorting, &format);
ref_sorting_set_sort_flags_all(&sorting, REF_SORTING_ICASE, icase);
ref_sorting_set_sort_flags_all(
&sorting, REF_SORTING_DETACHED_HEAD_FIRST, 1);
@@ -73,6 +73,7 @@ int cmd_for_each_ref(int argc, const char **argv, const char *prefix)
if (list_empty(&sorting.list))
ref_default_sorting(&sorting);
+ parse_ref_sorting_list(&sorting, &format);
ref_sorting_set_sort_flags_all(&sorting, REF_SORTING_ICASE, icase);
filter.ignore_case = icase;
@@ -49,6 +49,7 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
TRANSPORT_LS_REFS_OPTIONS_INIT;
int i;
struct string_list server_options = STRING_LIST_INIT_DUP;
+ struct ref_format dummy = REF_FORMAT_INIT;
struct remote *remote;
struct transport *transport;
@@ -136,9 +137,10 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
item->symref = xstrdup_or_null(ref->symref);
}
- if (!list_empty(&sorting.list))
+ if (!list_empty(&sorting.list)) {
+ parse_ref_sorting_list(&sorting, &dummy);
ref_array_sort(&sorting, &ref_array);
-
+ }
for (i = 0; i < ref_array.nr; i++) {
const struct ref_array_item *ref = ref_array.items[i];
if (show_symref_target && ref->symref)
@@ -529,6 +529,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
}
if (list_empty(&sorting.list))
ref_default_sorting(&sorting);
+ parse_ref_sorting_list(&sorting, &format);
ref_sorting_set_sort_flags_all(&sorting, REF_SORTING_ICASE, icase);
filter.ignore_case = icase;
if (cmdmode == 'l') {
@@ -2656,30 +2656,33 @@ void pretty_print_ref(const char *name, const struct object_id *oid,
free_array_item(ref_item);
}
-static int parse_sorting_atom(const char *atom)
+static int parse_sorting_atom(struct ref_format *format, const char *atom)
{
- /*
- * This parses an atom using a dummy ref_format, since we don't
- * actually care about the formatting details.
- */
- struct ref_format dummy = REF_FORMAT_INIT;
const char *end = atom + strlen(atom);
struct strbuf err = STRBUF_INIT;
- int res = parse_ref_filter_atom(&dummy, atom, end, &err);
+ int res = parse_ref_filter_atom(format, atom, end, &err);
if (res < 0)
die("%s", err.buf);
strbuf_release(&err);
return res;
}
+void parse_ref_sorting_list(struct ref_sorting *sorting_list, struct ref_format *format) {
+ struct list_head *pos;
+ struct ref_sorting *entry;
+
+ list_for_each(pos, &sorting_list->list) {
+ entry = list_entry(pos, struct ref_sorting, list);
+ entry->atom = parse_sorting_atom(format, entry->arg);
+ }
+}
+
/* If no sorting option is given, use refname to sort as default */
void ref_default_sorting(struct ref_sorting *sorting_list)
{
- static const char cstr_name[] = "refname";
-
struct ref_sorting *sorting = xcalloc(1, sizeof(*sorting));
list_add_tail(&sorting->list, &sorting_list->list);
- sorting->atom = parse_sorting_atom(cstr_name);
+ sorting->arg = "refname";
}
void free_ref_sorting_list(struct ref_sorting *sorting_list) {
@@ -2707,7 +2710,7 @@ void parse_ref_sorting(struct ref_sorting *sorting_list, const char *arg)
if (skip_prefix(arg, "version:", &arg) ||
skip_prefix(arg, "v:", &arg))
s->sort_flags |= REF_SORTING_VERSION;
- s->atom = parse_sorting_atom(arg);
+ s->arg = arg;
}
int parse_opt_ref_sorting(const struct option *opt, const char *arg, int unset)
@@ -28,6 +28,7 @@ struct atom_value;
struct ref_sorting {
struct list_head list;
int atom; /* index into used_atom array (internal) */
+ const char *arg;
enum {
REF_SORTING_REVERSE = 1<<0,
REF_SORTING_ICASE = 1<<1,
@@ -128,6 +129,8 @@ void parse_ref_sorting(struct ref_sorting *sorting_list, const char *arg);
int parse_opt_ref_sorting(const struct option *opt, const char *arg, int unset);
/* Default sort option based on refname */
void ref_default_sorting(struct ref_sorting *sorting_list);
+/* Parse every sort atom of ref_sorting list */
+void parse_ref_sorting_list(struct ref_sorting *sorting_list, struct ref_format *format);
/* Free all ref_sorting items in sorting list */
void free_ref_sorting_list(struct ref_sorting *sorting_list);
/* Function to parse --merged and --no-merged options */