git p4: refactor diffOpts calculation
P4Submit.applyCommit() To avoid recalculating the same diffOpts for each commit, move it out of applyCommit() and into the top-level run(). Also fix a bug in that code which interpreted the value of detectRenames as a string rather than as a boolean. [pw: fix documentation, rearrange code a bit] Signed-off-by: Gary Gibbons <ggibbons@perforce.com> Signed-off-by: Pete Wyckoff <pw@padd.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
committed by
Junio C Hamano
parent
a0327c0edc
commit
84cb00036f
52
git-p4.py
52
git-p4.py
@ -1046,27 +1046,8 @@ class P4Submit(Command, P4UserMap):
|
||||
|
||||
(p4User, gitEmail) = self.p4UserForCommit(id)
|
||||
|
||||
if not self.detectRenames:
|
||||
# If not explicitly set check the config variable
|
||||
self.detectRenames = gitConfig("git-p4.detectRenames")
|
||||
|
||||
if self.detectRenames.lower() == "false" or self.detectRenames == "":
|
||||
diffOpts = ""
|
||||
elif self.detectRenames.lower() == "true":
|
||||
diffOpts = "-M"
|
||||
else:
|
||||
diffOpts = "-M%s" % self.detectRenames
|
||||
|
||||
detectCopies = gitConfig("git-p4.detectCopies")
|
||||
if detectCopies.lower() == "true":
|
||||
diffOpts += " -C"
|
||||
elif detectCopies != "" and detectCopies.lower() != "false":
|
||||
diffOpts += " -C%s" % detectCopies
|
||||
|
||||
if gitConfig("git-p4.detectCopiesHarder", "--bool") == "true":
|
||||
diffOpts += " --find-copies-harder"
|
||||
|
||||
diff = read_pipe_lines("git diff-tree -r %s \"%s^\" \"%s\"" % (diffOpts, id, id))
|
||||
diff = read_pipe_lines("git diff-tree -r %s \"%s^\" \"%s\"" % (self.diffOpts, id, id))
|
||||
filesToAdd = set()
|
||||
filesToDelete = set()
|
||||
editedFiles = set()
|
||||
@ -1433,6 +1414,37 @@ class P4Submit(Command, P4UserMap):
|
||||
if self.preserveUser:
|
||||
self.checkValidP4Users(commits)
|
||||
|
||||
#
|
||||
# Build up a set of options to be passed to diff when
|
||||
# submitting each commit to p4.
|
||||
#
|
||||
if self.detectRenames:
|
||||
# command-line -M arg
|
||||
self.diffOpts = "-M"
|
||||
else:
|
||||
# If not explicitly set check the config variable
|
||||
detectRenames = gitConfig("git-p4.detectRenames")
|
||||
|
||||
if detectRenames.lower() == "false" or detectRenames == "":
|
||||
self.diffOpts = ""
|
||||
elif detectRenames.lower() == "true":
|
||||
self.diffOpts = "-M"
|
||||
else:
|
||||
self.diffOpts = "-M%s" % detectRenames
|
||||
|
||||
# no command-line arg for -C or --find-copies-harder, just
|
||||
# config variables
|
||||
detectCopies = gitConfig("git-p4.detectCopies")
|
||||
if detectCopies.lower() == "false" or detectCopies == "":
|
||||
pass
|
||||
elif detectCopies.lower() == "true":
|
||||
self.diffOpts += " -C"
|
||||
else:
|
||||
self.diffOpts += " -C%s" % detectCopies
|
||||
|
||||
if gitConfig("git-p4.detectCopiesHarder", "--bool") == "true":
|
||||
self.diffOpts += " --find-copies-harder"
|
||||
|
||||
while len(commits) > 0:
|
||||
commit = commits[0]
|
||||
commits = commits[1:]
|
||||
|
||||
Reference in New Issue
Block a user