From b18e445810815cd19678fd673a936e2f4d4a996a Mon Sep 17 00:00:00 2001 From: Thomas Zander Date: Fri, 2 May 2008 23:04:10 +0200 Subject: [PATCH] Fix usecases when there is no newline at end of file --- hunks/Hunk.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/hunks/Hunk.cpp b/hunks/Hunk.cpp index b5f5812..0a400cf 100644 --- a/hunks/Hunk.cpp +++ b/hunks/Hunk.cpp @@ -82,8 +82,13 @@ void Hunk::addLine(const QByteArray &line) return; } if (line[0] == '\\') { // "\ No newline at end of file" - if (d->diff.size()) + if (d->diff.size()) { + // check if we removed something from the last hunk and adjust its size + SubHunk *last = d->subhunks[d->subhunks.count()-1]; + if (last->start + last->length == d->diff.size()) + --last->length; d->diff.chop(1); // TODO should that be 2 on Windows? + } return; } else if (line[0] != ' ') { @@ -249,7 +254,12 @@ QByteArray Hunk::Private::patchForAccepted(bool inverse) } offsetInDiff = sh->start + sh->length; } + Q_ASSERT(offsetInDiff <= diff.size()); out.writeRawData(myDiff + offsetInDiff, diff.size() - offsetInDiff); + if (patch[patch.size() -1] != '\n') { + const char *noNewLine = "\n\\ No newline at end of file\n";; + out.writeRawData(noNewLine, strlen(noNewLine)); + } // create header QString header = "@@ -"+ QString::number(lineNumber) +","+ QString::number(before) -- 2.11.4.GIT