Skip to content

Commit 198551c

Browse files
mbs-cgitster
authored andcommitted
git-p4: fix error handling in P4Unshelve.renameBranch()
The error handling code path is meant to be triggered when the loop does not exit early via "break". This fails, as the boolean variable "found", which is used to track whether the loop was exited early, is initialized incorrectly. It would be possible to fix this issue by correcting the initialization, but Python supports a for:-else: control flow construct for this exact use case (executing code if a loop does not exit early), so it is more idiomatic to remove the tracking variable entirely. In addition, the error message no longer refers to a variable that does not exist. Signed-off-by: Moritz Baumann <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c0d2b07 commit 198551c

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

git-p4.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4369,19 +4369,16 @@ def __init__(self):
43694369
def renameBranch(self, branch_name):
43704370
"""Rename the existing branch to branch_name.N ."""
43714371

4372-
found = True
43734372
for i in range(0, 1000):
43744373
backup_branch_name = "{0}.{1}".format(branch_name, i)
43754374
if not gitBranchExists(backup_branch_name):
43764375
# Copy ref to backup
43774376
gitUpdateRef(backup_branch_name, branch_name)
43784377
gitDeleteRef(branch_name)
4379-
found = True
43804378
print("renamed old unshelve branch to {0}".format(backup_branch_name))
43814379
break
4382-
4383-
if not found:
4384-
sys.exit("gave up trying to rename existing branch {0}".format(sync.branch))
4380+
else:
4381+
sys.exit("gave up trying to rename existing branch {0}".format(branch_name))
43854382

43864383
def findLastP4Revision(self, starting_point):
43874384
"""Look back from starting_point for the first commit created by git-p4

0 commit comments

Comments
 (0)