On Wed, Sep 16, 2015 at 11:53 AM, Karthik Nayak <karthik.188@xxxxxxxxx> wrote: > On Tue, Sep 15, 2015 at 1:05 AM, Junio C Hamano <gitster@xxxxxxxxx> wrote: >> Karthik Nayak <karthik.188@xxxxxxxxx> writes: >> >>> + /* >>> + * First we obtain all regular branch refs and if the HEAD is >>> + * detached then we insert that ref to the end of the ref_fist >>> + * so that it can be printed and removed first. >>> + */ >>> for_each_rawref(append_ref, &cb); >>> + if (detached) >>> + head_ref(append_ref, &cb); >>> + index = ref_list.index; >>> + >>> + /* Print detached HEAD before sorting and printing the rest */ >>> + if (detached && (ref_list.list[index - 1].kind == REF_DETACHED_HEAD) && >>> + !strcmp(ref_list.list[index - 1].name, head)) { >>> + print_ref_item(&ref_list.list[index - 1], maxwidth, verbose, abbrev, >>> + 1, remote_prefix); >>> + index -= 1; >>> + } >>> >>> + qsort(ref_list.list, index, sizeof(struct ref_item), ref_cmp); >> >> This looks somewhat strange. Wouldn't it be more consistent to >> teach ref_cmp that HEAD sorts where in the collection of refs (I >> presume that kind is checked first and then name, so if you give >> REF_DETACHED_HEAD a low number than others, it would automatically >> give you the ordering you want) without all of the above special >> casing? > > Thats nice, we could do that, something like this perhaps: > > qsort(ref_list.list, ref_list.index, sizeof(struct ref_item), ref_cmp); > > for (i = 0; i < ref_list.index; i++) { > int current = !detached && (ref_list.list[i].kind == > REF_LOCAL_BRANCH) && > !strcmp(ref_list.list[i].name, head); > /* If detached the first ref_item is the current ref */ > if (detached && i == 0) > current = 1; > print_ref_item(&ref_list.list[i], maxwidth, verbose, > abbrev, current, remote_prefix); > } > Although this solves the problem here, we'd still need to do something similar when we use ref-filter APIs as in [PATCH 7/8]. So either we could introduce a new atom for sorting something like `branch_sort` which uses the FILTER_REFS_(DETACHED_HEAD | BRANCHES | REMOTES) to sort or we could sort after printing the detached head, as done in this series. I'm ok with either. -- Regards, Karthik Nayak -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html