All of lore.kernel.org
 help / color / mirror / Atom feed
From: Michael Haggerty <mhagger@alum.mit.edu>
To: Jonathan Nieder <jrnieder@gmail.com>
Cc: Junio C Hamano <gitster@pobox.com>, git@vger.kernel.org
Subject: Re: [PATCH 3/5] safe_create_leading_directories(): add "slash" pointer
Date: Wed, 01 Jan 2014 22:10:25 +0100	[thread overview]
Message-ID: <52C48441.8060605@alum.mit.edu> (raw)
In-Reply-To: <20131226223444.GY20443@google.com>

On 12/26/2013 11:34 PM, Jonathan Nieder wrote:
> Michael Haggerty wrote:
> 
>> [Subject: safe_create_leading_directories(): add "slash" pointer]
> 
> Is this a cleanup or improving the (internal) functionality of the
> function somehow?  The above one-liner doesn't sum up for me in an
> obvious way why this is a good change.

It's hard to make the subject more self-explanatory, given so few
characters.  But I will make the rest of the log message better in the
reroll.

>> Keep track of the position of the slash character separately, and
> 
> Separately from what?
> 
>> restore the slash character at a single place, at the end of the while
>> loop.  This makes the next change easier to implement.
>>
>> Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
> 
> Ah, do I understand correctly that this is about cleaning up
> after the code that scribbles over 'path' in one place, to make
> it harder to forget to do that cleanup as new code paths are
> introduced?

Yes.

> It's too bad there's no variant of 'stat' and 'mkdir' that takes
> a (buf, len) pair which would avoid the scribbling altogether.

Yes.

>> ---
>>  sha1_file.c | 36 ++++++++++++++++++------------------
>>  1 file changed, 18 insertions(+), 18 deletions(-)
>>
>> diff --git a/sha1_file.c b/sha1_file.c
>> index cc9957e..dcfd35a 100644
>> --- a/sha1_file.c
>> +++ b/sha1_file.c
>> @@ -107,40 +107,40 @@ int mkdir_in_gitdir(const char *path)
>>  
>>  int safe_create_leading_directories(char *path)
>>  {
>> -	char *pos = path + offset_1st_component(path);
>> +	char *next_component = path + offset_1st_component(path);
> 
> This name change is probably worth also mentioning in the commit
> message (or lifting into a separate patch) so the reader doesn't get
> distracted.

OK, I split the renaming into a separate commit.

>> +	int retval = 0;
>>  
>> -	while (pos) {
>> +	while (!retval && next_component) {
> 
> A more usual style would be
> [...]
> Using retval for control flow instead makes it eight lines more
> concise, which is probably worth it.

Agreed.

> [...]
>> 			if (!S_ISDIR(st.st_mode)) {
>> -				*pos = '/';
>> -				return -3;
>> +				retval = -3;
>> 			}
> 
> Now the 'if' body is one line, so we can drop the braces and save
> another line. :)

Will fix.

> One more nit: elsewhere in this file, a variable keeping track of the
> return value is named 'ret', so it probably makes sense to also use
> that name here.

OK, will change.

> That would mean the following changes to be potentially squashed in
> [...]

While going over the code again, I noticed another problem in the
original version; namely, that the handling of redundant multiple
slashes in the input path is not correct.  I will fix this problem and
split up the commit into smaller steps in the re-roll.

Michael

-- 
Michael Haggerty
mhagger@alum.mit.edu
http://softwareswirl.blogspot.com/

  reply	other threads:[~2014-01-01 21:10 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-22  7:14 [PATCH 0/5] Fix two mkdir/rmdir races Michael Haggerty
2013-12-22  7:14 ` [PATCH 1/5] safe_create_leading_directories(): modernize format of "if" chaining Michael Haggerty
2013-12-26 21:52   ` Jonathan Nieder
2013-12-22  7:14 ` [PATCH 2/5] safe_create_leading_directories(): reduce scope of local variable Michael Haggerty
2013-12-26 21:55   ` Jonathan Nieder
2014-01-01 12:39     ` Michael Haggerty
2013-12-22  7:14 ` [PATCH 3/5] safe_create_leading_directories(): add "slash" pointer Michael Haggerty
2013-12-26 22:34   ` Jonathan Nieder
2014-01-01 21:10     ` Michael Haggerty [this message]
2013-12-22  7:14 ` [PATCH 4/5] safe_create_leading_directories(): fix a mkdir/rmdir race Michael Haggerty
2013-12-22 22:42   ` Ramsay Jones
2013-12-26 23:02   ` Jonathan Nieder
2014-01-02  0:53     ` Michael Haggerty
2013-12-22  7:14 ` [PATCH 5/5] rename_ref(): fix a mkdir()/rmdir() race Michael Haggerty
2013-12-26 23:20   ` Jonathan Nieder

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=52C48441.8060605@alum.mit.edu \
    --to=mhagger@alum.mit.edu \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=jrnieder@gmail.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.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.