Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cache blobs #392

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions src/git/Patch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,15 @@ bool Patch::isLfsPointer() const {
return false;
}

Blob Patch::blob(Diff::File file) const {
Blob Patch::blob(Diff::File file) {
if (file == Diff::File::NewFile) {
if (mNewBlob.isValid())
return mNewBlob;
} else {
if (mOldBlob.isValid())
return mOldBlob;
}

git_repository *repo = git_patch_owner(d.data());
if (!repo)
return Blob();
Expand All @@ -146,7 +154,15 @@ Blob Patch::blob(Diff::File file) const {

git_object *obj = nullptr;
git_object_lookup(&obj, repo, &id, GIT_OBJECT_BLOB);
return Blob(reinterpret_cast<git_blob *>(obj));

auto b = Blob(reinterpret_cast<git_blob *>(obj));
if (file == Diff::File::NewFile) {
mNewBlob = b;
} else {
mOldBlob = b;
}

return b;
}

Patch::LineStats Patch::lineStats() const {
Expand All @@ -161,7 +177,7 @@ Patch::LineStats Patch::lineStats() const {
return stats;
}

QList<QString> Patch::print() const {
QList<QString> Patch::print() {
if (!this->d) {
// can occur, when the object is created with the default
// constructor.
Expand Down Expand Up @@ -290,7 +306,7 @@ void Patch::setConflictResolution(int hidx, ConflictResolution resolution) {
writeConflictResolutions(repo, map);
}

void Patch::populatePreimage(QList<QList<QByteArray>> &image) const {
void Patch::populatePreimage(QList<QList<QByteArray>> &image) {
// Populate preimage.
// image holds the text and changes are made in this list
// this list is written afterwards back into the file
Expand Down Expand Up @@ -335,8 +351,7 @@ QByteArray Patch::generateResult(QList<QList<QByteArray>> &image,
return filtered;
}

QByteArray Patch::apply(const QBitArray &hunks,
const FilterList &filters) const {
QByteArray Patch::apply(const QBitArray &hunks, const FilterList &filters) {
QList<QList<QByteArray>> image;
populatePreimage(image);

Expand Down
11 changes: 7 additions & 4 deletions src/git/Patch.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class Patch {
bool isBinary() const;
bool isLfsPointer() const;

Blob blob(Diff::File file) const;
Blob blob(Diff::File file);

LineStats lineStats() const;
/*!
Expand All @@ -54,7 +54,7 @@ class Patch {
* \brief print
* \return
*/
QList<QString> print() const;
QList<QString> print();

/*!
* \brief count
Expand Down Expand Up @@ -106,7 +106,7 @@ class Patch {
* \brief populatePreimage
* \param image Populated preimage
*/
void populatePreimage(QList<QList<QByteArray>> &image) const;
void populatePreimage(QList<QList<QByteArray>> &image);
/*!
* Splits the content of fileContent into lines and stores the content in
* image \brief populatePreimage \param image Populated preimage \param
Expand All @@ -124,7 +124,7 @@ class Patch {
* \return edited file
*/
QByteArray apply(const QBitArray &hunks,
const FilterList &filters = FilterList()) const;
const FilterList &filters = FilterList());
QByteArray apply(int hidx, QByteArray &hunkData, QByteArray fileContent,
const FilterList &filters = FilterList()) const;

Expand Down Expand Up @@ -169,6 +169,9 @@ class Patch {

Patch(git_patch *patch);

Blob mOldBlob;
Blob mNewBlob;

QSharedPointer<git_patch> d;
QList<ConflictHunk> mConflicts;

Expand Down
6 changes: 3 additions & 3 deletions src/ui/DiffView/EditButton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
#include "ui/RepoView.h"
#include <QPainterPath>

EditButton::EditButton(const git::Patch &patch, int index, bool binary,
bool lfs, QWidget *parent)
EditButton::EditButton(git::Patch &patch, int index, bool binary, bool lfs,
QWidget *parent)
: Button(parent) {
setObjectName("EditButton");

Expand All @@ -24,7 +24,7 @@ EditButton::EditButton(const git::Patch &patch, int index, bool binary,
setVisible(!binary && !lfs);
}

void EditButton::updatePatch(const git::Patch &patch, int index, bool init) {
void EditButton::updatePatch(git::Patch &patch, int index, bool init) {
if ((!isEnabled() || !isVisible()) && !init)
return;

Expand Down
4 changes: 2 additions & 2 deletions src/ui/DiffView/EditButton.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ class EditButton : public Button {
Q_OBJECT

public:
EditButton(const git::Patch &patch, int index, bool binary, bool lfs,
EditButton(git::Patch &patch, int index, bool binary, bool lfs,
QWidget *parent = nullptr);

void updatePatch(const git::Patch &patch, int index, bool init = false);
void updatePatch(git::Patch &patch, int index, bool init = false);

protected:
void paintEvent(QPaintEvent *event) override;
Expand Down
16 changes: 8 additions & 8 deletions src/ui/DiffView/FileWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace {
bool disclosure = false;
}

_FileWidget::Header::Header(const git::Diff &diff, const git::Patch &patch,
_FileWidget::Header::Header(const git::Diff &diff, git::Patch &patch,
bool binary, bool lfs, bool submodule,
QWidget *parent)
: QFrame(parent), mDiff(diff), mPatch(patch), mSubmodule(submodule) {
Expand Down Expand Up @@ -184,7 +184,7 @@ _FileWidget::Header::Header(const git::Diff &diff, const git::Patch &patch,
updateCheckState();
}

void _FileWidget::Header::updatePatch(const git::Patch &patch) {
void _FileWidget::Header::updatePatch(git::Patch &patch) {
auto status = patch.status();
QList<Badge::Label> labels = {
Badge::Label(QChar(git::Diff::statusChar(status)))};
Expand Down Expand Up @@ -333,10 +333,10 @@ void _FileWidget::Header::updateCheckState() {
//############### FileWidget ###########################################
//###############################################################################

FileWidget::FileWidget(DiffView *view, const git::Diff &diff,
const git::Patch &patch, const git::Patch &staged,
const QModelIndex modelIndex, const QString &name,
const QString &path, bool submodule, QWidget *parent)
FileWidget::FileWidget(DiffView *view, const git::Diff &diff, git::Patch &patch,
const git::Patch &staged, const QModelIndex modelIndex,
const QString &name, const QString &path, bool submodule,
QWidget *parent)
: QWidget(parent), mView(view), mDiff(diff), mPatch(patch),
mModelIndex(modelIndex) {
auto stageState = static_cast<git::Index::StagedState>(
Expand Down Expand Up @@ -520,7 +520,7 @@ git::Patch::ConflictResolution _FileWidget::Header::resolution() const {
return mResolution;
}

void FileWidget::updatePatch(const git::Patch &patch, const git::Patch &staged,
void FileWidget::updatePatch(git::Patch &patch, const git::Patch &staged,
const QString &name, const QString &path,
bool submodule) {
mHeader->updatePatch(patch);
Expand Down Expand Up @@ -578,7 +578,7 @@ QWidget *FileWidget::addImage(DisclosureButton *button, const git::Patch patch,
return images;
}

HunkWidget *FileWidget::addHunk(const git::Diff &diff, const git::Patch &patch,
HunkWidget *FileWidget::addHunk(const git::Diff &diff, git::Patch &patch,
const git::Patch &staged, int index, bool lfs,
bool submodule) {
HunkWidget *hunk =
Expand Down
10 changes: 5 additions & 5 deletions src/ui/DiffView/FileWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ class Header : public QFrame {
Q_OBJECT

public:
Header(const git::Diff &diff, const git::Patch &patch, bool binary, bool lfs,
Header(const git::Diff &diff, git::Patch &patch, bool binary, bool lfs,
bool submodule, QWidget *parent = nullptr);
void updatePatch(const git::Patch &patch);
void updatePatch(git::Patch &patch);
QCheckBox *check() const;

DisclosureButton *disclosureButton() const;
Expand Down Expand Up @@ -86,12 +86,12 @@ class FileWidget : public QWidget {
Q_OBJECT

public:
FileWidget(DiffView *view, const git::Diff &diff, const git::Patch &patch,
FileWidget(DiffView *view, const git::Diff &diff, git::Patch &patch,
const git::Patch &staged, const QModelIndex modelIndex,
const QString &name, const QString &path, bool submodule,
QWidget *parent = nullptr);
bool isEmpty();
void updatePatch(const git::Patch &patch, const git::Patch &staged,
void updatePatch(git::Patch &patch, const git::Patch &staged,
const QString &name, const QString &path, bool submodule);
/*!
* Update hunks after index change and emits the current stage state of the
Expand All @@ -105,7 +105,7 @@ class FileWidget : public QWidget {

QWidget *addImage(DisclosureButton *button, const git::Patch patch,
bool lfs = false);
HunkWidget *addHunk(const git::Diff &diff, const git::Patch &patch,
HunkWidget *addHunk(const git::Diff &diff, git::Patch &patch,
const git::Patch &staged, int index, bool lfs,
bool submodule);
void setStageState(git::Index::StagedState state);
Expand Down
11 changes: 5 additions & 6 deletions src/ui/DiffView/HunkWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,8 @@ const QString noNewLineAtEndOfFile =
HunkWidget::tr("No newline at end of file");
} // namespace

_HunkWidget::Header::Header(const git::Diff &diff, const git::Patch &patch,
int index, bool lfs, bool submodule,
QWidget *parent)
_HunkWidget::Header::Header(const git::Diff &diff, git::Patch &patch, int index,
bool lfs, bool submodule, QWidget *parent)
: QFrame(parent) {
setObjectName("HunkHeader");
mCheck = new QCheckBox(this);
Expand Down Expand Up @@ -178,9 +177,9 @@ void _HunkWidget::Header::mouseDoubleClickEvent(QMouseEvent *event) {
//########## HunkWidget ###############################################
//#############################################################################

HunkWidget::HunkWidget(DiffView *view, const git::Diff &diff,
const git::Patch &patch, const git::Patch &staged,
int index, bool lfs, bool submodule, QWidget *parent)
HunkWidget::HunkWidget(DiffView *view, const git::Diff &diff, git::Patch &patch,
const git::Patch &staged, int index, bool lfs,
bool submodule, QWidget *parent)
: QFrame(parent), mView(view), mPatch(patch), mStaged(staged),
mIndex(index), mLfs(lfs) {
setObjectName("HunkWidget");
Expand Down
4 changes: 2 additions & 2 deletions src/ui/DiffView/HunkWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace _HunkWidget {
class Header : public QFrame {
Q_OBJECT
public:
Header(const git::Diff &diff, const git::Patch &patch, int index, bool lfs,
Header(const git::Diff &diff, git::Patch &patch, int index, bool lfs,
bool submodule, QWidget *parent = nullptr);
QCheckBox *check() const;

Expand Down Expand Up @@ -61,7 +61,7 @@ class HunkWidget : public QFrame {
Q_OBJECT

public:
HunkWidget(DiffView *view, const git::Diff &diff, const git::Patch &patch,
HunkWidget(DiffView *view, const git::Diff &diff, git::Patch &patch,
const git::Patch &staged, int index, bool lfs, bool submodule,
QWidget *parent = nullptr);
_HunkWidget::Header *header() const;
Expand Down