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

From: Junio C Hamano <[email-masked]>
Date: Wed, 20 Jul 2022 09:21:07 -0700

Junio C Hamano <[email-masked]> writes:

>>  
>> -        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.