From fc81a6249c58e2d4b492bff9eb8fba2c987c9d29 Mon Sep 17 00:00:00 2001 From: Thomas Zander Date: Thu, 23 Jul 2009 21:43:04 +0300 Subject: [PATCH] Make reverting/unreverting a binary file work. Make writing out a patch for a binary file work partly. It now writes a header with all the sha1s etc, but not the file data. At least for a revert (i.e. git apply) this is enough :) --- src/hunks/ChangeSet.cpp | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/src/hunks/ChangeSet.cpp b/src/hunks/ChangeSet.cpp index 0624016..7f7b9ce 100644 --- a/src/hunks/ChangeSet.cpp +++ b/src/hunks/ChangeSet.cpp @@ -538,7 +538,6 @@ void ChangeSet::writeDiff(QIODevice &outDevice, ChangeSet::Selection selection) outDevice.open(QIODevice::WriteOnly | QIODevice::Truncate); QDataStream diff(&outDevice); foreach(File file, d->files) { - bool fileHeaderWritten = false; if ((selection == AllHunks || (selection == UserSelection && file.renameAcceptance() == Vng::Accepted)) && !file.oldFileName().isEmpty() && !file.fileName().isEmpty() @@ -546,7 +545,40 @@ void ChangeSet::writeDiff(QIODevice &outDevice, ChangeSet::Selection selection) writeRenameDiff(diff, file); continue; } + if (file.isBinary() && (selection == AllHunks || (selection == UserSelection + && file.binaryChangeAcceptance() == Vng::Accepted))) { + diff.writeRawData("diff --git a/", 13); + QByteArray fileName = file.oldFileName(); + if (fileName.isEmpty()) + fileName = file.fileName(); + diff.writeRawData(fileName.data(), fileName.size()); + diff.writeRawData(" b/", 3); + fileName = file.fileName(); + if (fileName.isEmpty()) + fileName = file.oldFileName(); + diff.writeRawData(fileName.data(), fileName.size()); + if (file.oldFileName().isEmpty()) { + diff.writeRawData("\nnew file mode ", 15); + QByteArray protection = file.protection().toLatin1(); + diff.writeRawData(protection.data(), protection.size()); + } else if (file.fileName().isEmpty()) { + diff.writeRawData("\ndeleted file mode ", 19); + QByteArray protection = file.oldProtection().toLatin1(); + diff.writeRawData(protection.data(), protection.size()); + } + diff.writeRawData("\nindex ", 7); + QByteArray sha1 = file.oldSha1().toLatin1(); + diff.writeRawData(sha1.data(), sha1.size()); + diff.writeRawData("..", 2); + sha1 = file.sha1().toLatin1(); + diff.writeRawData(sha1.data(), sha1.size()); + diff.writeRawData("\nGIT binary patch\n", 18); + //file.writeBinaryDataAsPatch(outDevice); // TODO :) + diff.writeRawData("literal 0\nHcmV?d00001\n\n", 23); + continue; + } + bool fileHeaderWritten = false; foreach(Hunk hunk, file.hunks()) { if (selection == AllHunks || (selection == UserSelection -- 2.11.4.GIT