From: Thomas Zander Date: Thu, 23 Jul 2009 18:38:12 +0000 (+0300) Subject: Fix creating a diff for a deleted file. X-Git-Url: https://repo.or.cz/w/vng.git/commitdiff_plain/4dd99dc211803bb3a4dc1b2d59238d03493954c9 Fix creating a diff for a deleted file. --- diff --git a/src/hunks/File.cpp b/src/hunks/File.cpp index 6d00d4d..fd746b6 100644 --- a/src/hunks/File.cpp +++ b/src/hunks/File.cpp @@ -296,17 +296,37 @@ void File::fetchHunks(bool againstHead) AbstractCommand::ReturnCodes rc = runner.start(GitRunner::WaitForStandardOutput); const char * prefix = (added ? "+" : "-"); if (rc == AbstractCommand::Ok) { - char buf[1024]; - Hunk hunk; // its one hunk. - QByteArray header("@@ -1,0 +1,0 @@", 15); - hunk.addLine(header); + QList lines; + char buf[8096]; + int bytesToInspect = 100; while(true) { qint64 lineLength = Vng::readLine(&git, buf, sizeof(buf)); if (lineLength == -1) break; - QByteArray array(prefix, 1); - array.append(buf); - hunk.addLine(array); + if (bytesToInspect > 0) { // detect binary files + const int max = qMin(bytesToInspect, (int) lineLength); + for (int i = 0; i < max; ++i) { + if (buf[i] == 0) { + m_file.setBinary(true); + return; + } + } + bytesToInspect -= max; + } + QByteArray line; + line.reserve(lineLength + 1); + line.append(prefix, 1); + line.append(buf, lineLength); + lines.append(line); + } + + Hunk hunk; // its one hunk. + QByteArray header("@@ -1,", 6); + header.append(QString::number(lines.count()).toLatin1()); + header.append(" +0,0 @@\n", 9); + hunk.addLine(header); + foreach (const QByteArray &line, lines) { + hunk.addLine(line); } m_file.addHunk(hunk); }