From: Luke Diamand <luke@diamand.org>
To: git@vger.kernel.org
Cc: "SZEDER Gábor" <szeder.dev@gmail.com>,
"Lars Schneider" <larsxschneider@gmail.com>,
"Yang Zhao" <yang.zhao@skyboxlabs.com>,
"Johannes Schindelin" <Johannes.Schindelin@gmx.de>,
"Luke Diamand" <luke@diamand.org>
Subject: [PATCHv1 4/6] git-p4: create helper function importRevisions()
Date: Wed, 29 Jan 2020 11:12:44 +0000 [thread overview]
Message-ID: <20200129111246.12196-5-luke@diamand.org> (raw)
In-Reply-To: <20200129111246.12196-4-luke@diamand.org>
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>
---
git-p4.py | 132 ++++++++++++++++++++++++++++--------------------------
1 file changed, 68 insertions(+), 64 deletions(-)
diff --git a/git-p4.py b/git-p4.py
index d796074b87..f90b43fe5e 100755
--- a/git-p4.py
+++ b/git-p4.py
@@ -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
--
2.20.1.390.gb5101f9297
next prev parent reply other threads:[~2020-01-29 11:12 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-29 11:12 [PATCHv1 0/6] git-p4: wait() for child processes better Luke Diamand
2020-01-29 11:12 ` [PATCHv1 1/6] git-p4: make closeStreams() idempotent Luke Diamand
2020-01-29 11:12 ` [PATCHv1 2/6] git-p4: add P4CommandException to report errors talking to Perforce Luke Diamand
2020-01-29 11:12 ` [PATCHv1 3/6] git-p4: disable some pylint warnings, to get pylint output to something manageable Luke Diamand
2020-01-29 11:12 ` Luke Diamand [this message]
2020-01-29 11:12 ` [PATCHv1 5/6] git-p4: cleanup better on error exit Luke Diamand
2020-01-29 11:12 ` [PATCHv1 6/6] git-p4: check for access to remote host earlier Luke Diamand
2020-01-29 15:00 ` [PATCHv1 4/6] git-p4: create helper function importRevisions() Eric Sunshine
2020-01-29 18:36 ` Luke Diamand
2020-01-30 19:59 ` Junio C Hamano
2020-01-31 10:36 ` Luke Diamand
2020-01-30 10:52 ` [PATCHv1 0/6] git-p4: wait() for child processes better Johannes Schindelin
2020-01-30 11:33 ` Luke Diamand
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200129111246.12196-5-luke@diamand.org \
--to=luke@diamand.org \
--cc=Johannes.Schindelin@gmx.de \
--cc=git@vger.kernel.org \
--cc=larsxschneider@gmail.com \
--cc=szeder.dev@gmail.com \
--cc=yang.zhao@skyboxlabs.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).