git-p4: Handle Windows EOLs properly after removal of p4 submit template handling.
git-p4s handling of Windows style EOL was broken after the removal of the p4 submit template handling in commit f2a6059. Fix that, and make getP4OpenedType() more robust. Signed-off-by: Marius Storm-Olsen <marius@trolltech.com> Signed-off-by: Simon Hausmann <simon@lst.de>
Marius Storm-Olsen committed
Mar 28, 2008 at 15:40 UTC
f3e5ae4f06ae968b710d286280a46b38ae3d36e8
1 file changed
+15
-13
contrib/fast-import/git-p4
+15
-13
@@ -90,11 +90,11 @@ def getP4OpenedType(file):
90
# Returns the perforce file type for the given file.
91
92
result = read_pipe("p4 opened %s" % file)
93
- match = re.match(".*\((.+)\)$", result)
93
+ match = re.match(".*\((.+)\)\r?$", result)
94
if match:
95
return match.group(1)
96
else:
97
- die("Could not determine file type for %s" % file)
97
+ die("Could not determine file type for %s (result: '%s')" % (file, result))
98
99
def diffTreePattern():
100
# This is a simple generator for the diff tree regex pattern. This could be
@@ -513,6 +513,8 @@ class P4Submit(Command):
513
template = ""
514
inFilesSection = False
515
for line in read_pipe_lines("p4 change -o"):
516
+ if line.endswith("\r\n"):
517
+ line = line[:-2] + "\n"
518
if inFilesSection:
519
if line.startswith("\t"):
520
# path starts and ends with a tab
@@ -619,8 +621,6 @@ class P4Submit(Command):
621
setP4ExecBit(f, mode)
622
623
logMessage = extractLogMessageFromGitCommit(id)
622
- if self.isWindows:
623
- logMessage = logMessage.replace("\n", "\r\n")
624
logMessage = logMessage.strip()
625
626
template = self.prepareSubmitTemplate()
@@ -631,23 +631,25 @@ class P4Submit(Command):
631
del(os.environ["P4DIFF"])
632
diff = read_pipe("p4 diff -du ...")
633
634
+ newdiff = ""
635
for newFile in filesToAdd:
635
- diff += "==== new file ====\n"
636
- diff += "--- /dev/null\n"
637
- diff += "+++ %s\n" % newFile
636
+ newdiff += "==== new file ====\n"
637
+ newdiff += "--- /dev/null\n"
638
+ newdiff += "+++ %s\n" % newFile
639
f = open(newFile, "r")
640
for line in f.readlines():
640
- diff += "+" + line
641
+ newdiff += "+" + line
642
f.close()
643
643
- separatorLine = "######## everything below this line is just the diff #######"
644
- if platform.system() == "Windows":
645
- separatorLine += "\r"
646
- separatorLine += "\n"
644
+ separatorLine = "######## everything below this line is just the diff #######\n"
645
646
[handle, fileName] = tempfile.mkstemp()
647
tmpFile = os.fdopen(handle, "w+")
650
- tmpFile.write(submitTemplate + separatorLine + diff)
648
+ if self.isWindows:
649
+ submitTemplate = submitTemplate.replace("\n", "\r\n")
650
+ separatorLine = separatorLine.replace("\n", "\r\n")
651
+ newdiff = newdiff.replace("\n", "\r\n")
652
+ tmpFile.write(submitTemplate + separatorLine + diff + newdiff)
653
tmpFile.close()
654
defaultEditor = "vi"
655
if platform.system() == "Windows":