From: Junio C Hamano <gitster@pobox.com>
To: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Cc: Clemens Buchacher <drizzd@aon.at>, git@vger.kernel.org
Subject: Re: [PATCH 2/3] unpack-trees: fix path search bug in verify_absent
Date: Sun, 04 Jan 2009 02:01:14 -0800 [thread overview]
Message-ID: <7vtz8fz8yd.fsf@gitster.siamese.dyndns.org> (raw)
In-Reply-To: alpine.DEB.1.00.0901031353090.30769@pacific.mpi-cbg.de
Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
> On Sat, 3 Jan 2009, Clemens Buchacher wrote:
>
>> On Fri, Jan 02, 2009 at 10:59:47PM +0100, Johannes Schindelin wrote:
>> > This explanation makes sense. However, this:
>> >
>> > > @@ -289,7 +289,8 @@ static int unpack_nondirectories(int n, unsigned long mask, unsigned long dirmas
>> > > return 0;
>> > > }
>> > >
>> > > -static int unpack_callback(int n, unsigned long mask, unsigned long dirmask, struct name_entry *names, struct traverse_info *info)
>> > > +static int unpack_callback(int n, unsigned long mask, unsigned long dirmask,
>> > > + struct name_entry *names, struct traverse_info *info)
>> > > {
>> > > struct cache_entry *src[5] = { NULL, };
>> > > struct unpack_trees_options *o = info->data;
>> >
>> > ... is distracting during review, and this:
>> >
>> > > @@ -517,22 +518,22 @@ static int verify_clean_subdirectory(struct cache_entry *ce, const char *action,
>> > > namelen = strlen(ce->name);
>> > > pos = index_name_pos(o->src_index, ce->name, namelen);
>> > > if (0 <= pos)
>> > > - return cnt; /* we have it as nondirectory */
>> > > + return 0; /* we have it as nondirectory */
>> > > pos = -pos - 1;
>> > > for (i = pos; i < o->src_index->cache_nr; i++) {
>> >
>> > ... is not accounted for in the commit message. Intended or not, that is
>> > the question.
>>
>> Those are trivial readability improvements in the context of the patch.
>
> They are not trivial enough for me not to be puzzled. Reason enough to
> explain in the commit message?
I'd say the first hunk quoted is probably on the borderline. It is an
unnecessary churn that won't even be commented on if it were sent alone,
but as a "while we are at it" hunk in a patch that is not too big, this is
a kind of thing that often is tolerated, because it is obvious enough not
to hurt anything from the correctness standpoint [*1*].
The second one is moderately worse for two reasons.
* I actually had to scratch my head because you need to view the change
in a lot wider context that covers the initializing definition of "int
cnt" near the beginning of the function down to the area affected by
the hunk, in order to see that the new "return 0" is the same as the
old "return cnt" and does not break things. A comment to say that "at
this point in the codeflow, cnt which is returned by the old code is
always zero", perhaps below the three-dash marker, would have saved me
a minute.
* The function's purpose and logic is to see if the subdirectory is
clean, and return how many cache entries need to be skipped if it is
(otherwise a negative number as an error indicator). For that purpose,
the return value cnt is initialized to 0 (i.e. "we haven't counted any
entry that needs to be skipped yet"), the loop below the patched part
counts it up while performing the verification, and then the resulting
count is returned from the function. The logic flow, at least to me,
is easier to follow if it returned the value in cnt, not a hardcoded 0,
from the place the patch tries to touch.
The latter point is with "at least to me", because I think an alternate
position is entirely valid if the author wants to justify the change by
saying something like:
The function's purpose is .... Before entering the loop to count the
number of entries to skip, this check to detect if we do not even have
to count appears. When this check triggers, we know we do not want to
skip anything, and returning constant 0 is much clearer than returning
a variable cnt that was initialized to 0 near the beginning of the
function; we haven't even started using it to count yet.
But the point is, if that is the reason the author thinks it is an
improvement, that probably needs to be stated.
[Footnote]
*1* I am not sure if it is obviously clear that the change improves any
readability. Some people argue that splitting the function definition
header hurts greppability for one thing. I personally do not find it easy
to read when the subsequent header lines are indented without aligning
(compare the way it is indented in the postimage of the patch with the way
the headers verify_absent() and show_stage_entry() are indented), either.
next prev parent reply other threads:[~2009-01-04 10:02 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-01-01 20:54 unpack-trees: fix D/F conflict bugs in verify_absent Clemens Buchacher
2009-01-01 20:54 ` [PATCH 1/3] unpack-trees: handle failure " Clemens Buchacher
2009-01-01 20:54 ` [PATCH 2/3] unpack-trees: fix path search bug " Clemens Buchacher
2009-01-01 20:54 ` [PATCH 3/3] unpack-trees: remove redundant path search " Clemens Buchacher
2009-01-06 8:19 ` Junio C Hamano
2009-01-02 21:59 ` [PATCH 2/3] unpack-trees: fix path search bug " Johannes Schindelin
2009-01-03 10:39 ` Clemens Buchacher
2009-01-03 12:53 ` Johannes Schindelin
2009-01-04 10:01 ` Junio C Hamano [this message]
2009-01-04 20:01 ` Clemens Buchacher
2009-01-06 19:35 ` Johannes Schindelin
2011-01-13 2:24 ` [RFC/PATCH 0/2] unpack-trees: handle lstat failures " Jonathan Nieder
2011-01-13 2:26 ` [PATCH 1/2] unpack-trees: handle lstat failure for existing directory Jonathan Nieder
2011-01-13 4:37 ` Miles Bader
2011-01-13 5:38 ` Jonathan Nieder
2011-01-13 2:28 ` [PATCH 2/2] unpack-trees: handle lstat failure for existing file Jonathan Nieder
2011-01-13 20:20 ` [RFC/PATCH 0/2] unpack-trees: handle lstat failures in verify_absent Clemens Buchacher
2009-01-01 21:28 ` unpack-trees: fix D/F conflict bugs " Junio C Hamano
-- strict thread matches above, loose matches on Subject: below --
2008-12-16 23:24 Strange untracked file behaviour Miklos Vajna
2008-12-17 5:09 ` Johannes Schindelin
2008-12-17 14:38 ` Miklos Vajna
2009-01-02 21:59 ` [PATCH 2/3] unpack-trees: fix path search bug in verify_absent Johannes Schindelin
2009-01-03 14:01 ` Miklos Vajna
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=7vtz8fz8yd.fsf@gitster.siamese.dyndns.org \
--to=gitster@pobox.com \
--cc=Johannes.Schindelin@gmx.de \
--cc=drizzd@aon.at \
--cc=git@vger.kernel.org \
/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.
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 NNTP newsgroup(s).