git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 2/5] safe_create_leading_directories(): reduce scope of local variable

From
Michael Haggerty <mhagger@alum.mit.edu>
Date
Jan 1, 2014, 12:39 UTC
Message-ID
<52C40C9B.2040001@alum.mit.edu>
In-Reply-To
<20131226215559.GX20443@google.com>
On 12/26/2013 10:55 PM, Jonathan Nieder wrote:
Show 23 quoted lines
> Michael Haggerty wrote:
> 
>> Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
>> ---
>>  sha1_file.c | 3 ++-
>>  1 file changed, 2 insertions(+), 1 deletion(-)
>>
>> diff --git a/sha1_file.c b/sha1_file.c
>> index c9245a6..cc9957e 100644
>> --- a/sha1_file.c
>> +++ b/sha1_file.c
>> @@ -108,9 +108,10 @@ int mkdir_in_gitdir(const char *path)
>>  int safe_create_leading_directories(char *path)
>>  {
>>  	char *pos = path + offset_1st_component(path);
>> -	struct stat st;
>>  
>>  	while (pos) {
>> +		struct stat st;
> 
> Is this to make it easier to reason about whether 'st' has been
> properly initialized at any given moment, or is there a more subtle
> reason?

No, just the boring reason, the one that makes me reduce the scope of variables whenever possible. I'll buff up the log message.

Michael
-- 
Michael Haggerty
mhagger@alum.mit.edu
http://softwareswirl.blogspot.com/
Previous: Jonathan NiederNext: Michael Haggerty
Message 6 of 15 in “Fix two mkdir/rmdir races”
  1. 0/5 Fix two mkdir/rmdir racesMichael Haggerty, Dec 22, 2013
  2. 1/5 safe_create_leading_directories(): modernize format of "if" chainingMichael Haggerty, Dec 22, 2013
  3. Jonathan NiederDec 26, 2013
  4. 2/5 safe_create_leading_directories(): reduce scope of local variableMichael Haggerty, Dec 22, 2013
  5. Jonathan NiederDec 26, 2013
  6. Michael HaggertyJan 1, 2014
  7. 3/5 safe_create_leading_directories(): add "slash" pointerMichael Haggerty, Dec 22, 2013
  8. Jonathan NiederDec 26, 2013
  9. Michael HaggertyJan 1, 2014
  10. 4/5 safe_create_leading_directories(): fix a mkdir/rmdir raceMichael Haggerty, Dec 22, 2013
  11. Ramsay JonesDec 22, 2013
  12. Jonathan NiederDec 26, 2013
  13. Michael HaggertyJan 2, 2014
  14. 5/5 rename_ref(): fix a mkdir()/rmdir() raceMichael Haggerty, Dec 22, 2013
  15. Jonathan NiederDec 26, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.