]> git.ipfire.org Git - thirdparty/git.git/commitdiff
git-p4: fix error handling in P4Unshelve.renameBranch()
authorMoritz Baumann <moritz.baumann@sap.com>
Wed, 20 Jul 2022 18:55:30 +0000 (18:55 +0000)
committerJunio C Hamano <gitster@pobox.com>
Wed, 20 Jul 2022 20:53:54 +0000 (13:53 -0700)
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 <moritz.baumann@sap.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
git-p4.py

index 1de3d6f1cd40a6dbf61e4bd4e2568173e632150a..8f20d15f27263e69f9b03f1d2272762c0b91696a 100755 (executable)
--- a/git-p4.py
+++ b/git-p4.py
@@ -4369,19 +4369,16 @@ class P4Unshelve(Command):
     def renameBranch(self, branch_name):
         """Rename the existing branch to branch_name.N ."""
 
-        found = True
         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))
                 break
-
-        if not found:
-            sys.exit("gave up trying to rename existing branch {0}".format(sync.branch))
+        else:
+            sys.exit("gave up trying to rename existing branch {0}".format(branch_name))
 
     def findLastP4Revision(self, starting_point):
         """Look back from starting_point for the first commit created by git-p4