From: Matthieu Moy <Matthieu.Moy@grenoble-inp•fr>
To: Karthik Nayak <karthik.188@gmail•com>
Cc: git@vger•kernel.org, christian.couder@gmail•com, gitster@pobox•com
Subject: Re: [PATCH v4 3/8] branch: roll show_detached HEAD into regular ref_list
Date: Sun, 13 Sep 2015 14:12:58 +0200 [thread overview]
Message-ID: <vpqa8sqv7p1.fsf@anie.imag.fr> (raw)
In-Reply-To: <1442129035-31386-4-git-send-email-Karthik.188@gmail.com> (Karthik Nayak's message of "Sun, 13 Sep 2015 12:53:50 +0530")
Karthik Nayak <karthik.188@gmail•com> writes:
> @@ -679,15 +682,20 @@ static int print_ref_list(int kinds, int detached, int verbose, int abbrev, stru
> if (verbose)
> maxwidth = calc_maxwidth(&ref_list, strlen(remote_prefix));
>
> - qsort(ref_list.list, ref_list.index, sizeof(struct ref_item), ref_cmp);
> + 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;
> + }
I think Eric already mentionned it, but I don't remember the conclusion
and can't find it in the archives. Wouldn't it be cleaner to actually
remove the detached head from the array (do "ref_list.index -= 1"
instead of "index -= 1", and possibly free() what needs to be freed?
If you did so, you wouldn't have any possible confusion between the
local variable "index" and ref_list.index in the code below:
> - detached = (detached && (kinds & REF_LOCAL_BRANCH));
> - if (detached && match_patterns(pattern, "HEAD"))
> - show_detached(&ref_list, maxwidth);
> + qsort(ref_list.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) &&
> + for (i = 0; i < index; i++) {
> + int current = !detached && (ref_list.list[i].kind == REF_LOCAL_BRANCH) &&
> !strcmp(ref_list.list[i].name, head);
> print_ref_item(&ref_list.list[i], maxwidth, verbose,
> abbrev, current, remote_prefix);
--
Matthieu Moy
http://www-verimag.imag.fr/~moy/
next prev parent reply other threads:[~2015-09-13 12:13 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-09-13 7:23 [PATCH v4 0/8] port the filtering part of branch.c to use ref-filter APIs Karthik Nayak
2015-09-13 7:23 ` [PATCH v4 1/8] branch: refactor width computation Karthik Nayak
2015-09-13 11:51 ` Matthieu Moy
2015-09-13 12:23 ` Karthik Nayak
2015-09-13 12:33 ` Matthieu Moy
2015-09-13 7:23 ` [PATCH v4 2/8] branch: bump get_head_description() to the top Karthik Nayak
2015-09-13 7:23 ` [PATCH v4 3/8] branch: roll show_detached HEAD into regular ref_list Karthik Nayak
2015-09-13 12:12 ` Matthieu Moy [this message]
2015-09-13 13:24 ` Karthik Nayak
2015-09-13 16:46 ` Eric Sunshine
2015-09-13 18:31 ` Eric Sunshine
2015-09-14 14:48 ` Karthik Nayak
2015-09-14 14:54 ` Matthieu Moy
2015-09-14 19:35 ` Junio C Hamano
2015-09-16 6:23 ` Karthik Nayak
2015-09-17 9:47 ` Karthik Nayak
2015-09-17 14:18 ` Matthieu Moy
2015-09-17 15:15 ` Junio C Hamano
2015-09-17 15:43 ` Matthieu Moy
2015-09-17 16:49 ` Junio C Hamano
2015-09-17 17:08 ` Matthieu Moy
2015-09-17 17:21 ` Junio C Hamano
2015-09-17 18:25 ` Karthik Nayak
2015-09-13 7:23 ` [PATCH v4 4/8] branch: move 'current' check down to the presentation layer Karthik Nayak
2015-09-13 12:15 ` Matthieu Moy
2015-09-13 13:22 ` Karthik Nayak
2015-09-13 15:35 ` Karthik Nayak
2015-09-13 7:23 ` [PATCH v4 5/8] branch: drop non-commit error reporting Karthik Nayak
2015-09-14 19:49 ` Junio C Hamano
2015-09-16 6:04 ` Karthik Nayak
2015-09-13 7:23 ` [PATCH v4 6/8] branch.c: use 'ref-filter' data structures Karthik Nayak
2015-09-13 12:26 ` Matthieu Moy
2015-09-13 13:19 ` Karthik Nayak
2015-09-13 17:49 ` Matthieu Moy
2015-09-13 7:23 ` Karthik Nayak
2015-09-13 7:32 ` Karthik Nayak
2015-09-13 7:23 ` [PATCH v4 8/8] branch: add '--points-at' option Karthik Nayak
2015-09-13 7:29 ` [PATCH v4 7/8] branch.c: use 'ref-filter' APIs Karthik Nayak
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=vpqa8sqv7p1.fsf@anie.imag.fr \
--to=matthieu.moy@grenoble-inp$(echo .)fr \
--cc=christian.couder@gmail$(echo .)com \
--cc=git@vger$(echo .)kernel.org \
--cc=gitster@pobox$(echo .)com \
--cc=karthik.188@gmail$(echo .)com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox