diff --git a/src/git/Blob.cpp b/src/git/Blob.cpp index 1746c0b79..3af700e89 100644 --- a/src/git/Blob.cpp +++ b/src/git/Blob.cpp @@ -26,6 +26,10 @@ Blob::operator git_blob *() const { bool Blob::isBinary() const { return git_blob_is_binary(*this); } +bool Blob::isBinary(const QByteArray &data) { + return git_blob_data_is_binary(data.constData(), data.length()); +} + QByteArray Blob::content() const { const char *content = static_cast(git_blob_rawcontent(*this)); return QByteArray(content, git_blob_rawsize(*this)); diff --git a/src/git/Blob.h b/src/git/Blob.h index 9020c22d5..e947e46e7 100644 --- a/src/git/Blob.h +++ b/src/git/Blob.h @@ -20,7 +20,17 @@ class Blob : public Object { Blob(); Blob(const Object &rhs); + /// @brief Check if the Blob object points to binary data + /// @return True if Blob oject is for a binary blob bool isBinary() const; + + /// @brief Check if given QByteArray contains binary data according to libgit2 + /// @param data QByteArray to do a binary test on + /// @return True if data is binary + static bool isBinary(const QByteArray &data); + + /// @brief Grab the content of the blob + /// @return QByteArray of the blob QByteArray content() const; private: diff --git a/src/git/Buffer.cpp b/src/git/Buffer.cpp deleted file mode 100644 index 4bd8cff8e..000000000 --- a/src/git/Buffer.cpp +++ /dev/null @@ -1,19 +0,0 @@ -// -// Copyright (c) 2016, Scientific Toolworks, Inc. -// -// This software is licensed under the MIT License. The LICENSE.md file -// describes the conditions under which this software may be distributed. -// -// Author: Jason Haslam -// - -#include "Buffer.h" -#include "git2/blob.h" - -namespace git { - -Buffer::Buffer(const char *data, int size) : data(data), size(size) {} - -bool Buffer::isBinary() const { return git_blob_data_is_binary(data, size); } - -} // namespace git diff --git a/src/git/Buffer.h b/src/git/Buffer.h deleted file mode 100644 index 77c69f174..000000000 --- a/src/git/Buffer.h +++ /dev/null @@ -1,28 +0,0 @@ -// -// Copyright (c) 2016, Scientific Toolworks, Inc. -// -// This software is licensed under the MIT License. The LICENSE.md file -// describes the conditions under which this software may be distributed. -// -// Author: Jason Haslam -// - -#ifndef BUFFER_H -#define BUFFER_H - -namespace git { - -class Buffer { -public: - Buffer(const char *data, int size); - - bool isBinary() const; - -private: - const char *data; - const int size; -}; - -} // namespace git - -#endif diff --git a/src/git/CMakeLists.txt b/src/git/CMakeLists.txt index a8638b32a..3ccb42f91 100644 --- a/src/git/CMakeLists.txt +++ b/src/git/CMakeLists.txt @@ -4,7 +4,6 @@ add_library( Blame.cpp Blob.cpp Branch.cpp - Buffer.cpp Command.cpp Commit.cpp Config.cpp diff --git a/src/ui/BlameEditor.cpp b/src/ui/BlameEditor.cpp index 1f68cb409..d3c4d4d64 100644 --- a/src/ui/BlameEditor.cpp +++ b/src/ui/BlameEditor.cpp @@ -16,7 +16,6 @@ #include "editor/TextEditor.h" #include "git/Blame.h" #include "git/Blob.h" -#include "git/Buffer.h" #include "git/Commit.h" #include "git/Index.h" #include "git/Repository.h" @@ -145,8 +144,7 @@ bool BlameEditor::load(const QString &name, const git::Blob &blob, // Limit the read to kMaxReadBinary to determine if the file is binary content = file.read(kMaxReadBinary); - git::Buffer buffer(content.constData(), content.length()); - if (buffer.isBinary()) + if (git::Blob::isBinary(content)) return false; // Okay, not a binary file. Now we need to grab the rest if needed else if (content.length() == kMaxReadBinary) diff --git a/src/ui/DiffView/FileWidget.cpp b/src/ui/DiffView/FileWidget.cpp index fb1e6d783..c73895f24 100644 --- a/src/ui/DiffView/FileWidget.cpp +++ b/src/ui/DiffView/FileWidget.cpp @@ -18,8 +18,6 @@ #include "ui/FileContextMenu.h" #include "git/Repository.h" -#include "git/Buffer.h" - #include #include #include @@ -358,8 +356,7 @@ FileWidget::FileWidget(DiffView *view, const git::Diff &diff, // Limit the read to kMaxReadBinary number of bytes to determine if the // file is binary or not QByteArray content = dev.read(kMaxReadBinary); - git::Buffer buffer(content.constData(), content.length()); - binary = buffer.isBinary(); + binary = git::Blob::isBinary(content); } }