git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Karthik Nayak <karthik.188@gmail.com>
To: Matthieu Moy <Matthieu.Moy@grenoble-inp.fr>
Cc: Git <git@vger.kernel.org>,
	Christian Couder <christian.couder@gmail.com>,
	Junio C Hamano <gitster@pobox.com>
Subject: Re: [RFC/PATCH 05/11] branch: fix width computation
Date: Tue, 28 Jul 2015 23:46:59 +0530	[thread overview]
Message-ID: <CAOLa=ZTsr3rFanRFwDW7YUE=VmcTgpaOHEKX2cJpfKOhW1FZGA@mail.gmail.com> (raw)
In-Reply-To: <vpq6154zk9o.fsf@anie.imag.fr>

On Tue, Jul 28, 2015 at 3:17 PM, Matthieu Moy
<Matthieu.Moy@grenoble-inp.fr> wrote:
> Karthik Nayak <karthik.188@gmail.com> writes:
>
>> From: Karthik Nayak <karthik.188@gmail.com>
>
> Why did send-email add this From: header? Strange, it has the same
> content as your actual From: field.
>

Not sure why, everything else came out fine. Idk what happened here.

>> Remove unnecessary variables from ref_list and ref_item
>> which were used for width computation. Make other changes
>> accordingly. This patch is a precursor for porting branch.c
>> to use ref-filter APIs.
>
> You can explain better why this is needed. I guess something like "we're
> making struct ref_item similar to ref-filter's ref_array_item", but the
> reader shouldn't have to guess.
>

Will explain like you suggested.

> You should adujst the subject like BTW, I don't think you are "fixing"
> anything.
>

I guess refactor would be a better word here.

> On a side note: on the "tag" series, see how explaining better and
> splitting patches led not only to a better history, but also to better
> final code, and to finding a actual bugs (the %(color) thing and the
> absence of reset on the state variable) even after sereval rounds of
> review? I'm being picky and demanding, but don't see that as a complain
> from me, just hints on getting even better ;-).
>

Haha, I look forward to reviews, they show things I usually miss out on,
and help me get better. so keep them coming, I'll keep improving :)
Thanks

>> @@ -386,15 +386,8 @@ static int append_ref(const char *refname, const struct object_id *oid, int flag
>>       newitem->name = xstrdup(refname);
>>       newitem->kind = kind;
>>       newitem->commit = commit;
>> -     newitem->width = utf8_strwidth(refname);
>>       newitem->dest = resolve_symref(orig_refname, prefix);
>>       newitem->ignore = 0;
>> -     /* adjust for "remotes/" */
>> -     if (newitem->kind == REF_REMOTE_BRANCH &&
>> -         ref_list->kinds != REF_REMOTE_BRANCH)
>> -             newitem->width += 8;
>> -     if (newitem->width > ref_list->maxwidth)
>> -             ref_list->maxwidth = newitem->width;
>>
>>       return 0;
>>  }
>
> OK, in the old code, the width computation is done when inserting the
> ref into the array. In the new code, you build the array and then do the
> width computation. You can explain this better in the commit message I
> think (instead of "Make other changes accordingly" which doesn't bring
> much).

Okay I guess will do, just didn't want to explain the whole thing in the commit
message.

>
>> @@ -505,11 +498,12 @@ static void add_verbose_info(struct strbuf *out, struct ref_item *item,
>>  }
>>
>>  static void print_ref_item(struct ref_item *item, int maxwidth, int verbose,
>> -                        int abbrev, int current, char *prefix)
>> +                        int abbrev, int current, const char *remote_prefix)
>>  {
>>       char c;
>>       int color;
>>       struct strbuf out = STRBUF_INIT, name = STRBUF_INIT;
>> +     const char *prefix = "";
>>
>>       if (item->ignore)
>>               return;
>> @@ -520,6 +514,7 @@ static void print_ref_item(struct ref_item *item, int maxwidth, int verbose,
>>               break;
>>       case REF_REMOTE_BRANCH:
>>               color = BRANCH_COLOR_REMOTE;
>> +             prefix = remote_prefix;
>>               break;
>
> Why do you need these two hunks? I did not investigate in details, but
> it seems you're calling print_ref_item either with prefix="" or with
> prefix=remote_prefix so it would seem that keeping "prefix" as argument
> would work. I guess I missed something.

This is needed as whenever we do "git branch", show_detached() calls
print_ref_item()
with remote_prefix="". But print_ref_list() calls print_ref_item()
with remote_prefix="remotes"
(only when `git branch -a` is called remote_prefix=""). But only
remote branches should be
given the remotes prefix.

>
>> -static int calc_maxwidth(struct ref_list *refs)
>> +static int calc_maxwidth(struct ref_list *refs, int remote_bonus)
>>  {
>> -     int i, w = 0;
>> +     int i, max = 0;
>>       for (i = 0; i < refs->index; i++) {
>> +             struct ref_item *it = &refs->list[i];
>> +             int w = utf8_strwidth(it->name);
>> +
>>               if (refs->list[i].ignore)
>>                       continue;
>> -             if (refs->list[i].width > w)
>> -                     w = refs->list[i].width;
>> +             if (it->kind == REF_REMOTE_BRANCH)
>> +                     w += remote_bonus;
>> +             if (w > max)
>> +                     max = w;
>>       }
>> -     return w;
>> +     return max;
>>  }
>
> The old code was using 'w' for the max and no variable for the value at
> the current iteration. You're using 'max' for the max and 'w' at the
> current iteration. Using the same name 'w' for different things in the
> pre- and post-image of the patch distracts the reader.
>
> It may make sense to s/w/max/ in a separate preparatory patch. Or maybe
> it's overkill.
>

Since the change was minimal and easily understandable I think it's ok.
But if you still feel otherwise, I'll be happy to introduce a preparatory patch.

>> @@ -600,21 +600,18 @@ static char *get_head_description(void)
>>       return strbuf_detach(&desc, NULL);
>>  }
>>
>> -static void show_detached(struct ref_list *ref_list)
>> +static void show_detached(struct ref_list *ref_list, int maxwidth)
>>  {
>>       struct commit *head_commit = lookup_commit_reference_gently(head_sha1, 1);
>>
>>       if (head_commit && is_descendant_of(head_commit, ref_list->with_commit)) {
>>               struct ref_item item;
>>               item.name = get_head_description();
>> -             item.width = utf8_strwidth(item.name);
>>               item.kind = REF_LOCAL_BRANCH;
>>               item.dest = NULL;
>>               item.commit = head_commit;
>>               item.ignore = 0;
>> -             if (item.width > ref_list->maxwidth)
>> -                     ref_list->maxwidth = item.width;
>> -             print_ref_item(&item, ref_list->maxwidth, ref_list->verbose, ref_list->abbrev, 1, "");
>> +             print_ref_item(&item, maxwidth, ref_list->verbose, ref_list->abbrev, 1, "");
>>               free(item.name);
>>       }
>>  }
> ...
>> +     int maxwidth = 0;
> ...
>> +     if (verbose)
>> +             maxwidth = calc_maxwidth(&ref_list, strlen(remote_prefix));
>>
>>       qsort(ref_list.list, ref_list.index, sizeof(struct ref_item), ref_cmp);
>>
>>       detached = (detached && (kinds & REF_LOCAL_BRANCH));
>>       if (detached && match_patterns(pattern, "HEAD"))
>> -             show_detached(&ref_list);
>> +             show_detached(&ref_list, maxwidth);
>
> This hunks could ideally go in a preparatory patch that would just move
> the place where maxwidth is computed. This preparatory patch would just
> say
>
>         maxwidth = ref_list->maxwidth;
>
> and then you would do the actual change to
>
>         if (verbose)
>                 maxwidth = calc_maxwidth(...)
>
> without the distracting changes in the function's argument list.
>
> I won't insist on that, again it may be overkill. But reading the patch,
> I found it both rather trivial and hard to read, so there's room for
> improvement.
>

I find it too small to make a preparatory patch again, but if you really feel
so, like I said, I'll change :)

-- 
Regards,
Karthik Nayak

  reply	other threads:[~2015-07-28 18:17 UTC|newest]

Thread overview: 88+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-28  6:55 [RFC/PATCH] Port branch.c to use ref-filter APIs Karthik Nayak
2015-07-28  6:56 ` [RFC/PATCH 01/11] ref-filter: add "%(objectname:size=X)" option Karthik Nayak
2015-07-28  6:56   ` [RFC/PATCH 02/11] ref-filter: add 'colornext' atom Karthik Nayak
2015-07-28  8:45     ` Matthieu Moy
2015-07-28 16:03       ` Karthik Nayak
2015-07-28  9:13     ` Christian Couder
2015-07-28 16:04       ` Karthik Nayak
2015-07-29 20:10     ` Eric Sunshine
2015-07-29 21:30       ` Matthieu Moy
2015-07-30  4:27         ` Jacob Keller
2015-07-30 16:17           ` Junio C Hamano
2015-08-01 13:06             ` Karthik Nayak
2015-07-28  6:56   ` [RFC/PATCH 03/11] ref-filter: add option to filter only branches Karthik Nayak
2015-07-28 13:38     ` Matthieu Moy
2015-07-28 16:42       ` Karthik Nayak
2015-07-28  6:56   ` [RFC/PATCH 04/11] ref-filter: add 'ifexists' atom Karthik Nayak
2015-07-28  7:54     ` Jacob Keller
2015-07-28 16:47       ` Karthik Nayak
2015-07-28  8:50     ` Matthieu Moy
2015-07-28 17:39       ` Karthik Nayak
2015-07-28 17:57     ` Junio C Hamano
2015-07-29 17:48       ` Karthik Nayak
2015-07-29 18:00         ` Junio C Hamano
2015-07-29 18:56           ` Junio C Hamano
2015-07-29 21:21             ` Matthieu Moy
2015-07-29 22:05               ` Junio C Hamano
2015-08-01  6:46               ` Karthik Nayak
2015-08-01  7:05                 ` Jacob Keller
2015-08-01  6:44           ` Karthik Nayak
2015-07-28  6:56   ` [RFC/PATCH 05/11] branch: fix width computation Karthik Nayak
2015-07-28  9:47     ` Matthieu Moy
2015-07-28 18:16       ` Karthik Nayak [this message]
2015-07-28  6:56   ` [RFC/PATCH 06/11] branch: roll show_detached HEAD into regular ref_list Karthik Nayak
2015-07-28 13:01     ` Matthieu Moy
2015-07-28 19:19       ` Karthik Nayak
2015-07-29  9:56         ` Matthieu Moy
2015-07-29 17:54           ` Karthik Nayak
2015-07-28  6:56   ` [RFC/PATCH 07/11] branch: move 'current' check down to the presentation layer Karthik Nayak
2015-07-28 13:09     ` Matthieu Moy
2015-07-28 20:12       ` Karthik Nayak
2015-07-29  0:46         ` Jacob Keller
2015-07-29 18:44           ` Karthik Nayak
2015-07-29 10:01         ` Matthieu Moy
2015-07-29 18:52           ` Karthik Nayak
2015-07-29 21:27             ` Matthieu Moy
2015-08-01  6:48               ` Karthik Nayak
2015-08-01  7:06                 ` Jacob Keller
2015-08-01  9:03                 ` Eric Sunshine
2015-08-02 12:59                   ` Karthik Nayak
2015-08-02 17:58                     ` Junio C Hamano
2015-07-28  6:56   ` [RFC/PATCH 08/11] branch: drop non-commit error reporting Karthik Nayak
2015-07-28  6:56   ` [RFC/PATCH 09/11] branch.c: use 'ref-filter' data structures Karthik Nayak
2015-07-28  8:17     ` Christian Couder
2015-07-28 13:48       ` Matthieu Moy
2015-07-28 20:41         ` Karthik Nayak
2015-07-29 10:08           ` Matthieu Moy
2015-07-29 19:38             ` Karthik Nayak
2015-07-28 20:38       ` Karthik Nayak
2015-07-28  8:22     ` Christian Couder
2015-07-28 20:31       ` Karthik Nayak
2015-07-28  8:42   ` [RFC/PATCH 01/11] ref-filter: add "%(objectname:size=X)" option Matthieu Moy
2015-07-28 15:54     ` Karthik Nayak
2015-07-28 15:43   ` Junio C Hamano
2015-07-28 15:55     ` Karthik Nayak
2015-07-28 16:19   ` Junio C Hamano
2015-07-29 16:02     ` Karthik Nayak
2015-07-28  7:11 ` [RFC/PATCH 10/11] branch.c: use 'ref-filter' APIs Karthik Nayak
2015-07-28  7:57   ` Jacob Keller
2015-07-29  3:46     ` Karthik Nayak
2015-07-28  8:09   ` Christian Couder
2015-07-29  3:48     ` Karthik Nayak
2015-07-28 14:17   ` Matthieu Moy
2015-07-29 15:32     ` Karthik Nayak
2015-07-29 15:46       ` Matthieu Moy
2015-07-29 15:37     ` Karthik Nayak
2015-07-29 15:56       ` Matthieu Moy
2015-07-30  6:37         ` Karthik Nayak
2015-07-30  7:29           ` Matthieu Moy
2015-08-03 10:20             ` Karthik Nayak
2015-08-19 15:49               ` Matthieu Moy
2015-08-19 15:52                 ` Karthik Nayak
2015-07-28  7:11 ` [RFC/PATCH 11/11] branch: add '--points-at' option Karthik Nayak
2015-07-28  7:46   ` Jacob Keller
2015-07-29 15:44     ` Karthik Nayak
2015-07-28 13:35 ` [RFC/PATCH] Port branch.c to use ref-filter APIs Matthieu Moy
2015-07-28 15:48   ` Karthik Nayak
2015-07-28 17:53     ` Matthieu Moy
2015-07-29 15:54       ` 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

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAOLa=ZTsr3rFanRFwDW7YUE=VmcTgpaOHEKX2cJpfKOhW1FZGA@mail.gmail.com' \
    --to=karthik.188@gmail.com \
    --cc=Matthieu.Moy@grenoble-inp.fr \
    --cc=christian.couder@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).