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

Re: [PATCH 2/2] git-p4: fix error handling in P4Unshelve.renameBranch()

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 20, 2022, 16:21 UTC
Message-ID
<xmqq5yjr4ux8.fsf@gitster.g>
In-Reply-To
<xmqqa6934v2c.fsf@gitster.g>
Junio C Hamano <gitster@pobox.com> writes:
Show 23 quoted lines
>>  
>> -        found = True
>
> This has to be initialized to False, because ...
>
>>          for i in range(0, 1000):
>>              backup_branch_name = "{0}.{1}".format(branch_name, i)
>>              if not gitBranchExists(backup_branch_name):
>>                  # Copy ref to backup
>>                  gitUpdateRef(backup_branch_name, branch_name)
>>                  gitDeleteRef(branch_name)
>> -                found = True
>>                  print("renamed old unshelve branch to {0}".format(backup_branch_name))
>
> ... we flip it to True when we find an available unused name and
> break out ...
>
>>                  break
>> -
>> -        if not found:
>> -            sys.exit("gave up trying to rename existing branch {0}".format(sync.branch))
>
> ... so that we can complain when we didn't find anything usable.

By the way, isn't this a typical time-of-check to time-of-use bug? Not the problem with the fix in the patch but in the original, but regardless of whose fault it is, it may be good to fix it (outside the topic of this patch).

Thanks.
Previous: Junio C HamanoNext: Baumann, Moritz
Message 6 of 11 in “git-p4: fix two undefined variables”
  1. 0/2 git-p4: fix two undefined variablesMoritz Baumann via GitGitGadget, Jul 20, 2022
  2. 1/2 git-p4: fix typo in P4Submit.applyCommit()Moritz Baumann via GitGitGadget, Jul 20, 2022
  3. Junio C HamanoJul 20, 2022
  4. 2/2 git-p4: fix error handling in P4Unshelve.renameBranch()Moritz Baumann via GitGitGadget, Jul 20, 2022
  5. Junio C HamanoJul 20, 2022
  6. Junio C HamanoJul 20, 2022
  7. Baumann, MoritzJul 20, 2022
  8. 0/2 git-p4: fix two undefined variablesMoritz Baumann via GitGitGadget, Jul 20, 2022
  9. 1/2 git-p4: fix typo in P4Submit.applyCommit()Moritz Baumann via GitGitGadget, Jul 20, 2022
  10. 2/2 git-p4: fix error handling in P4Unshelve.renameBranch()Moritz Baumann via GitGitGadget, Jul 20, 2022
  11. Junio C HamanoJul 20, 2022

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.