Skip to content

Commit

Permalink
git-p4: fix submit in non --prepare-p4-only mode
Browse files Browse the repository at this point in the history
b4073bb (git-p4: Do not include diff in spec file when just
preparing p4, 2014-05-24) broke git p4 submit, here is a proper
fix, including proper handling for windows end of lines.

Signed-off-by: Maxime Coste <frrrwww@gmail.com>
Acked-by: Pete Wyckoff <pw@padd.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Maxime Coste authored and Junio C Hamano committed Jun 13, 2014
1 parent b4073bb commit e2a892e
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions git-p4.py
Original file line number Diff line number Diff line change
Expand Up @@ -1238,7 +1238,7 @@ def edit_template(self, template_file):
if response == 'n':
return False

def get_diff_description(self, editedFiles):
def get_diff_description(self, editedFiles, filesToAdd):
# diff
if os.environ.has_key("P4DIFF"):
del(os.environ["P4DIFF"])
Expand All @@ -1258,7 +1258,7 @@ def get_diff_description(self, editedFiles):
newdiff += "+" + line
f.close()

return diff + newdiff
return (diff + newdiff).replace('\r\n', '\n')

def applyCommit(self, id):
"""Apply one commit, return True if it succeeded."""
Expand Down Expand Up @@ -1422,10 +1422,10 @@ def applyCommit(self, id):
separatorLine = "######## everything below this line is just the diff #######\n"
if not self.prepare_p4_only:
submitTemplate += separatorLine
submitTemplate += self.get_diff_description(editedFiles)
submitTemplate += self.get_diff_description(editedFiles, filesToAdd)

(handle, fileName) = tempfile.mkstemp()
tmpFile = os.fdopen(handle, "w+")
tmpFile = os.fdopen(handle, "w+b")
if self.isWindows:
submitTemplate = submitTemplate.replace("\n", "\r\n")
tmpFile.write(submitTemplate)
Expand Down Expand Up @@ -1475,9 +1475,9 @@ def applyCommit(self, id):
tmpFile = open(fileName, "rb")
message = tmpFile.read()
tmpFile.close()
submitTemplate = message[:message.index(separatorLine)]
if self.isWindows:
submitTemplate = submitTemplate.replace("\r\n", "\n")
message = message.replace("\r\n", "\n")
submitTemplate = message[:message.index(separatorLine)]
p4_write_pipe(['submit', '-i'], submitTemplate)

if self.preserveUser:
Expand Down

0 comments on commit e2a892e

Please sign in to comment.