On Tue, Sep 15, 2015 at 1:05 AM, Junio C Hamano <[email protected]> wrote:
> Karthik Nayak <[email protected]> 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);
}
--
Regards,
Karthik Nayak
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html