summaryrefslogtreecommitdiff
path: root/git-p4.py
diff options
context:
space:
mode:
authorLuke Diamand <luke@diamand.org>2020-01-29 11:12:44 (GMT)
committerJunio C Hamano <gitster@pobox.com>2020-01-30 20:20:58 (GMT)
commitca5b5cce6290351f8cb63ee4ff466ed4a2285319 (patch)
tree07772c6e209ef495874dd9b9b7ca096bf5846d2f /git-p4.py
parent4c1d58675d07296adb2cf40b4b1c24f8d7a20d75 (diff)
downloadgit-ca5b5cce6290351f8cb63ee4ff466ed4a2285319.zip
git-ca5b5cce6290351f8cb63ee4ff466ed4a2285319.tar.gz
git-ca5b5cce6290351f8cb63ee4ff466ed4a2285319.tar.bz2
git-p4: create helper function importRevisions()
This makes it easier to try/catch around this block of code to ensure cleanup following p4 failures is handled properly. Signed-off-by: Luke Diamand <luke@diamand.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'git-p4.py')
-rwxr-xr-xgit-p4.py132
1 files changed, 68 insertions, 64 deletions
diff --git a/git-p4.py b/git-p4.py
index d796074..f90b43f 100755
--- a/git-p4.py
+++ b/git-p4.py
@@ -3555,6 +3555,73 @@ class P4Sync(Command, P4UserMap):
print("IO error details: {}".format(err))
print(self.gitError.read())
+
+ def importRevisions(self, args, branch_arg_given):
+ changes = []
+
+ if len(self.changesFile) > 0:
+ output = open(self.changesFile).readlines()
+ changeSet = set()
+ for line in output:
+ changeSet.add(int(line))
+
+ for change in changeSet:
+ changes.append(change)
+
+ changes.sort()
+ else:
+ # catch "git p4 sync" with no new branches, in a repo that
+ # does not have any existing p4 branches
+ if len(args) == 0:
+ if not self.p4BranchesInGit:
+ die("No remote p4 branches. Perhaps you never did \"git p4 clone\" in here.")
+
+ # The default branch is master, unless --branch is used to
+ # specify something else. Make sure it exists, or complain
+ # nicely about how to use --branch.
+ if not self.detectBranches:
+ if not branch_exists(self.branch):
+ if branch_arg_given:
+ die("Error: branch %s does not exist." % self.branch)
+ else:
+ die("Error: no branch %s; perhaps specify one with --branch." %
+ self.branch)
+
+ if self.verbose:
+ print("Getting p4 changes for %s...%s" % (', '.join(self.depotPaths),
+ self.changeRange))
+ changes = p4ChangesForPaths(self.depotPaths, self.changeRange, self.changes_block_size)
+
+ if len(self.maxChanges) > 0:
+ changes = changes[:min(int(self.maxChanges), len(changes))]
+
+ if len(changes) == 0:
+ if not self.silent:
+ print("No changes to import!")
+ else:
+ if not self.silent and not self.detectBranches:
+ print("Import destination: %s" % self.branch)
+
+ self.updatedBranches = set()
+
+ if not self.detectBranches:
+ if args:
+ # start a new branch
+ self.initialParent = ""
+ else:
+ # build on a previous revision
+ self.initialParent = parseRevision(self.branch)
+
+ self.importChanges(changes)
+
+ if not self.silent:
+ print("")
+ if len(self.updatedBranches) > 0:
+ sys.stdout.write("Updated branches: ")
+ for b in self.updatedBranches:
+ sys.stdout.write("%s " % b)
+ sys.stdout.write("\n")
+
def openStreams(self):
self.importProcess = subprocess.Popen(["git", "fast-import"],
stdin=subprocess.PIPE,
@@ -3761,70 +3828,7 @@ class P4Sync(Command, P4UserMap):
if revision:
self.importHeadRevision(revision)
else:
- changes = []
-
- if len(self.changesFile) > 0:
- output = open(self.changesFile).readlines()
- changeSet = set()
- for line in output:
- changeSet.add(int(line))
-
- for change in changeSet:
- changes.append(change)
-
- changes.sort()
- else:
- # catch "git p4 sync" with no new branches, in a repo that
- # does not have any existing p4 branches
- if len(args) == 0:
- if not self.p4BranchesInGit:
- die("No remote p4 branches. Perhaps you never did \"git p4 clone\" in here.")
-
- # The default branch is master, unless --branch is used to
- # specify something else. Make sure it exists, or complain
- # nicely about how to use --branch.
- if not self.detectBranches:
- if not branch_exists(self.branch):
- if branch_arg_given:
- die("Error: branch %s does not exist." % self.branch)
- else:
- die("Error: no branch %s; perhaps specify one with --branch." %
- self.branch)
-
- if self.verbose:
- print("Getting p4 changes for %s...%s" % (', '.join(self.depotPaths),
- self.changeRange))
- changes = p4ChangesForPaths(self.depotPaths, self.changeRange, self.changes_block_size)
-
- if len(self.maxChanges) > 0:
- changes = changes[:min(int(self.maxChanges), len(changes))]
-
- if len(changes) == 0:
- if not self.silent:
- print("No changes to import!")
- else:
- if not self.silent and not self.detectBranches:
- print("Import destination: %s" % self.branch)
-
- self.updatedBranches = set()
-
- if not self.detectBranches:
- if args:
- # start a new branch
- self.initialParent = ""
- else:
- # build on a previous revision
- self.initialParent = parseRevision(self.branch)
-
- self.importChanges(changes)
-
- if not self.silent:
- print("")
- if len(self.updatedBranches) > 0:
- sys.stdout.write("Updated branches: ")
- for b in self.updatedBranches:
- sys.stdout.write("%s " % b)
- sys.stdout.write("\n")
+ self.importRevisions(args, branch_arg_given)
if gitConfigBool("git-p4.importLabels"):
self.importLabels = True