Fixed line endings not having the right line endings in CRLF files with autoCRLF=false
This also fixes the stage line/hunk issues of #221 and #213
This commit is contained in:
parent
8d863492ed
commit
765bae578f
@ -4,7 +4,5 @@ import org.eclipse.jgit.diff.RawText
|
|||||||
import java.io.ByteArrayOutputStream
|
import java.io.ByteArrayOutputStream
|
||||||
|
|
||||||
fun RawText.lineAt(line: Int): String {
|
fun RawText.lineAt(line: Int): String {
|
||||||
val outputStream = ByteArrayOutputStream()
|
return this.getString(line, line + 1, false)
|
||||||
this.writeLine(outputStream, line)
|
|
||||||
return outputStream.toString(Charsets.UTF_8)
|
|
||||||
}
|
}
|
@ -67,41 +67,20 @@ class FormatHunksUseCase @Inject constructor() {
|
|||||||
|
|
||||||
while (oldCurrentLine < oldEndLine || newCurrentLine < newEndLine) {
|
while (oldCurrentLine < oldEndLine || newCurrentLine < newEndLine) {
|
||||||
if (oldCurrentLine < curEdit.beginA || endIdx + 1 < curIdx) {
|
if (oldCurrentLine < curEdit.beginA || endIdx + 1 < curIdx) {
|
||||||
var lineText = oldRawText.lineAt(oldCurrentLine)
|
val lineText = oldRawText.lineAt(oldCurrentLine)
|
||||||
|
|
||||||
if (
|
|
||||||
oldCurrentLine < oldRawText.size() - 1 || // If it's not the last
|
|
||||||
(oldCurrentLine == oldRawText.size() - 1 && !oldRawText.isMissingNewlineAtEnd) // Or is the last and contains new line at the end
|
|
||||||
) {
|
|
||||||
lineText += oldRawText.lineDelimiter.orEmpty()
|
|
||||||
}
|
|
||||||
|
|
||||||
lines.add(Line(lineText, oldCurrentLine, newCurrentLine, LineType.CONTEXT))
|
lines.add(Line(lineText, oldCurrentLine, newCurrentLine, LineType.CONTEXT))
|
||||||
|
|
||||||
oldCurrentLine++
|
oldCurrentLine++
|
||||||
newCurrentLine++
|
newCurrentLine++
|
||||||
} else if (oldCurrentLine < curEdit.endA) {
|
} else if (oldCurrentLine < curEdit.endA) {
|
||||||
var lineText = oldRawText.lineAt(oldCurrentLine)
|
val lineText = oldRawText.lineAt(oldCurrentLine)
|
||||||
|
|
||||||
if (
|
|
||||||
oldCurrentLine < oldRawText.size() - 1 || // If it's not the last
|
|
||||||
(oldCurrentLine == oldRawText.size() - 1 && !oldRawText.isMissingNewlineAtEnd) // Or is the last and contains new line at the end
|
|
||||||
) {
|
|
||||||
lineText += oldRawText.lineDelimiter.orEmpty()
|
|
||||||
}
|
|
||||||
|
|
||||||
lines.add(Line(lineText, oldCurrentLine, newCurrentLine, LineType.REMOVED))
|
lines.add(Line(lineText, oldCurrentLine, newCurrentLine, LineType.REMOVED))
|
||||||
|
|
||||||
oldCurrentLine++
|
oldCurrentLine++
|
||||||
} else if (newCurrentLine < curEdit.endB) {
|
} else if (newCurrentLine < curEdit.endB) {
|
||||||
var lineText = newRawText.lineAt(newCurrentLine)
|
val lineText = newRawText.lineAt(newCurrentLine)
|
||||||
|
|
||||||
if (
|
|
||||||
newCurrentLine < newRawText.size() - 1 || // If it's not the last
|
|
||||||
(newCurrentLine == newRawText.size() - 1 && !newRawText.isMissingNewlineAtEnd) // Or is the last and contains new line at the end
|
|
||||||
) {
|
|
||||||
lineText += newRawText.lineDelimiter.orEmpty()
|
|
||||||
}
|
|
||||||
|
|
||||||
lines.add(Line(lineText, oldCurrentLine, newCurrentLine, LineType.ADDED))
|
lines.add(Line(lineText, oldCurrentLine, newCurrentLine, LineType.ADDED))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user