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>
This commit is contained in:
parent
803d515812
commit
f3e5ae4f06
@ -90,11 +90,11 @@ def getP4OpenedType(file):
|
|||||||
# Returns the perforce file type for the given file.
|
# Returns the perforce file type for the given file.
|
||||||
|
|
||||||
result = read_pipe("p4 opened %s" % file)
|
result = read_pipe("p4 opened %s" % file)
|
||||||
match = re.match(".*\((.+)\)$", result)
|
match = re.match(".*\((.+)\)\r?$", result)
|
||||||
if match:
|
if match:
|
||||||
return match.group(1)
|
return match.group(1)
|
||||||
else:
|
else:
|
||||||
die("Could not determine file type for %s" % file)
|
die("Could not determine file type for %s (result: '%s')" % (file, result))
|
||||||
|
|
||||||
def diffTreePattern():
|
def diffTreePattern():
|
||||||
# This is a simple generator for the diff tree regex pattern. This could be
|
# This is a simple generator for the diff tree regex pattern. This could be
|
||||||
@ -513,6 +513,8 @@ class P4Submit(Command):
|
|||||||
template = ""
|
template = ""
|
||||||
inFilesSection = False
|
inFilesSection = False
|
||||||
for line in read_pipe_lines("p4 change -o"):
|
for line in read_pipe_lines("p4 change -o"):
|
||||||
|
if line.endswith("\r\n"):
|
||||||
|
line = line[:-2] + "\n"
|
||||||
if inFilesSection:
|
if inFilesSection:
|
||||||
if line.startswith("\t"):
|
if line.startswith("\t"):
|
||||||
# path starts and ends with a tab
|
# path starts and ends with a tab
|
||||||
@ -619,8 +621,6 @@ class P4Submit(Command):
|
|||||||
setP4ExecBit(f, mode)
|
setP4ExecBit(f, mode)
|
||||||
|
|
||||||
logMessage = extractLogMessageFromGitCommit(id)
|
logMessage = extractLogMessageFromGitCommit(id)
|
||||||
if self.isWindows:
|
|
||||||
logMessage = logMessage.replace("\n", "\r\n")
|
|
||||||
logMessage = logMessage.strip()
|
logMessage = logMessage.strip()
|
||||||
|
|
||||||
template = self.prepareSubmitTemplate()
|
template = self.prepareSubmitTemplate()
|
||||||
@ -631,23 +631,25 @@ class P4Submit(Command):
|
|||||||
del(os.environ["P4DIFF"])
|
del(os.environ["P4DIFF"])
|
||||||
diff = read_pipe("p4 diff -du ...")
|
diff = read_pipe("p4 diff -du ...")
|
||||||
|
|
||||||
|
newdiff = ""
|
||||||
for newFile in filesToAdd:
|
for newFile in filesToAdd:
|
||||||
diff += "==== new file ====\n"
|
newdiff += "==== new file ====\n"
|
||||||
diff += "--- /dev/null\n"
|
newdiff += "--- /dev/null\n"
|
||||||
diff += "+++ %s\n" % newFile
|
newdiff += "+++ %s\n" % newFile
|
||||||
f = open(newFile, "r")
|
f = open(newFile, "r")
|
||||||
for line in f.readlines():
|
for line in f.readlines():
|
||||||
diff += "+" + line
|
newdiff += "+" + line
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
separatorLine = "######## everything below this line is just the diff #######"
|
separatorLine = "######## everything below this line is just the diff #######\n"
|
||||||
if platform.system() == "Windows":
|
|
||||||
separatorLine += "\r"
|
|
||||||
separatorLine += "\n"
|
|
||||||
|
|
||||||
[handle, fileName] = tempfile.mkstemp()
|
[handle, fileName] = tempfile.mkstemp()
|
||||||
tmpFile = os.fdopen(handle, "w+")
|
tmpFile = os.fdopen(handle, "w+")
|
||||||
tmpFile.write(submitTemplate + separatorLine + diff)
|
if self.isWindows:
|
||||||
|
submitTemplate = submitTemplate.replace("\n", "\r\n")
|
||||||
|
separatorLine = separatorLine.replace("\n", "\r\n")
|
||||||
|
newdiff = newdiff.replace("\n", "\r\n")
|
||||||
|
tmpFile.write(submitTemplate + separatorLine + diff + newdiff)
|
||||||
tmpFile.close()
|
tmpFile.close()
|
||||||
defaultEditor = "vi"
|
defaultEditor = "vi"
|
||||||
if platform.system() == "Windows":
|
if platform.system() == "Windows":
|
||||||
|
Loading…
Reference in New Issue
Block a user