Re: [PATCH v4 3/8] branch: roll show_detached HEAD into regular ref_list
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Sep 14, 2015, 19:35 UTC
- Message-ID
- <xmqqzj0ovlno.fsf@gitster.mtv.corp.google.com>
- In-Reply-To
- <1442129035-31386-4-git-send-email-Karthik.188@gmail.com>
Karthik Nayak <karthik.188@gmail.com> writes:
Show 19 quoted lines
> + /*
> + * 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?