1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-05-03 23:36:11 +02:00

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>
This commit is contained in:
Luke Diamand 2020-01-29 11:12:44 +00:00 committed by Junio C Hamano
parent 4c1d58675d
commit ca5b5cce62

132
git-p4.py
View File

@ -3555,6 +3555,73 @@ def importHeadRevision(self, revision):
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 @@ def run(self, args):
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