Skip to content

Commit

Permalink
update libgit2
Browse files Browse the repository at this point in the history
  • Loading branch information
Murmele committed Sep 7, 2022
1 parent 33db52a commit 04f1ef5
Show file tree
Hide file tree
Showing 28 changed files with 190 additions and 124 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ jobs:
run: |
mkdir -p build/release
cd build/release
cmake -G Ninja -DCMAKE_BUILD_TYPE=Release ${{ env.CMAKE_FLAGS }} ${{ matrix.env.cmake_flags }} ../..
cmake -G Ninja -DUSE_BUNDLED_ZLIB:BOOL=ON -DCMAKE_BUILD_TYPE=Release ${{ env.CMAKE_FLAGS }} ${{ matrix.env.cmake_flags }} ../..
- name: Build Information
run: |
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ build
.project
.vscode/
CMakeLists.txt.user
build*
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[submodule "dep/libgit2/libgit2"]
path = dep/libgit2/libgit2
url = https://github.com/stinb/libgit2.git
url = https://github.com/Murmele/libgit2.git
[submodule "dep/libssh2/libssh2"]
path = dep/libssh2/libssh2
url = https://github.com/libssh2/libssh2.git
Expand Down
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ endif()
set(BUILD_SHARED_LIBS OFF)

option(FLATPAK "Building for flatpak" OFF)
option(BUILD_GITTYUP_TEST "Building unittests of Gittyup" ON)

# Require C++17.
set(CMAKE_CXX_STANDARD 17)
Expand Down Expand Up @@ -98,5 +99,8 @@ endif()
add_subdirectory(dep)
add_subdirectory(src)
add_subdirectory(l10n)
add_subdirectory(test)

if (BUILD_GITTYUP_TEST)
add_subdirectory(test)
endif()
add_subdirectory(pack)
4 changes: 4 additions & 0 deletions dep/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ find_package(PkgConfig)
add_subdirectory(openssl)
add_subdirectory(libssh2)
add_subdirectory(libgit2)
# otherwise the zlib is not available in the src/git
set(LIBGIT2_DEPENDENCY_OBJECTS ${LIBGIT2_DEPENDENCY_OBJECTS} PARENT_SCOPE)
set(LIBGIT2_SYSTEM_LIBS ${LIBGIT2_SYSTEM_LIBS} PARENT_SCOPE)
set(LIBGIT2_INCLUDES ${LIBGIT2_INCLUDES} PARENT_SCOPE)

add_subdirectory(cmark)
add_subdirectory(lua)
Expand Down
6 changes: 4 additions & 2 deletions dep/libgit2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,7 @@ if(WIN32)
endif()

add_subdirectory(libgit2)
target_include_directories(
git2 INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/libgit2/include)
# otherwise the zlib is not available in the src/git
set(LIBGIT2_DEPENDENCY_OBJECTS ${LIBGIT2_DEPENDENCY_OBJECTS} PARENT_SCOPE)
set(LIBGIT2_SYSTEM_LIBS ${LIBGIT2_SYSTEM_LIBS} PARENT_SCOPE)
set(LIBGIT2_INCLUDES ${LIBGIT2_INCLUDES} PARENT_SCOPE)
27 changes: 27 additions & 0 deletions dep/libgit2/rebaseGittyupLibgit2.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
declare -a branches=("fetch_annotated_tags" "blame_abort" "disableRenameDetection" "checkout_deletion_notification" "diff_checkout" "fix_push_callback_issues" "disable_mmap" "context_line_accessor´" "disableRenameDetection" "submodule" "hash" "callback_connect_disconnect" "blame_buffer" "libgit2_includes_public")

cd libgit2

git remote remove origin
git remote remove upstream
git remote add origin https://github.com/Murmele/libgit2.git
git remote add upstream https://github.com/libgit2/libgit2.git

git fetch --all

for branch in ${branches[@]}; do
echo $branch
git checkout -B $branch "origin/$branch"
git rebase upstream/main
done

git checkout Gittyup
git reset --hard upstream/main

for branch in ${branches[@]}; do
git merge --no-edit $branch
done

git push --force origin

echo "Script finished. Check if all branches are rebased correctly and push them to origin!"
8 changes: 7 additions & 1 deletion src/app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,13 @@ target_compile_definitions(
PRIVATE QT_TRANSLATIONS_DIR="${QT_TRANSLATIONS_DIR}"
BUILD_DESCRIPTION="${BUILD_DESCRIPTION}")

target_link_libraries(app conf git ui update Qt5::Widgets)
target_link_libraries(app
conf
git
ui
update
Qt5::Widgets
)

set_target_properties(app PROPERTIES AUTOMOC ON)

Expand Down
2 changes: 1 addition & 1 deletion src/dialogs/SubmoduleTableModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ bool SubmoduleTableModel::setData(const QModelIndex &index,
QMessageBox::Warning, tr("Deinitialize Submodule?"), text,
QMessageBox::Cancel, qobject_cast<QWidget *>(parent()));

if (GIT_SUBMODULE_STATUS_IS_WD_DIRTY(submodule.status()))
if (GIT_SUBMODULE_STATUS_IS_WD_DIRTY(mRepo.submoduleStatus(submodule.name())))
mb->setInformativeText(
tr("The submodule working directory contains uncommitted "
"changes that will be lost if you continue."));
Expand Down
2 changes: 1 addition & 1 deletion src/git/Branch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ Remote Branch::remote() const {
return up.isValid() ? up.remote() : Remote();
}

git_buf buf = GIT_BUF_INIT_CONST(nullptr, 0);
git_buf buf = GIT_BUF_INIT;
git_repository *repo = git_reference_owner(d.data());
if (git_branch_remote_name(&buf, repo, qualifiedName().toUtf8()))
return Remote();
Expand Down
9 changes: 7 additions & 2 deletions src/git/Buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,17 @@
//

#include "Buffer.h"
#include "git2/blob.h"

namespace git {

Buffer::Buffer(const char *data, int size)
: d(GIT_BUF_INIT_CONST(data, size)) {}
: data(data), size(size)
{}

bool Buffer::isBinary() const { return git_buf_is_binary(&d); }
bool Buffer::isBinary() const
{
return git_blob_data_is_binary(data, size);
}

} // namespace git
5 changes: 2 additions & 3 deletions src/git/Buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
#ifndef BUFFER_H
#define BUFFER_H

#include "git2/buffer.h"

namespace git {

class Buffer {
Expand All @@ -21,7 +19,8 @@ class Buffer {
bool isBinary() const;

private:
git_buf d;
const char* data;
const int size;
};

} // namespace git
Expand Down
15 changes: 14 additions & 1 deletion src/git/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,19 @@ add_library(
TagRef.cpp
Tree.cpp)

target_link_libraries(git git2 Qt5::Core Qt5::Network util)
target_link_libraries(git
git2
${LIBGIT2_DEPENDENCY_OBJECTS}
${LIBGIT2_SYSTEM_LIBS}
$<TARGET_OBJECTS:libgit2>
$<TARGET_OBJECTS:util>
Qt5::Core
Qt5::Network
)

# needed also by the plugin target so it must be public
target_include_directories(git PUBLIC
${LIBGIT2_INCLUDES}
)

set_target_properties(git PROPERTIES AUTOMOC ON)
4 changes: 2 additions & 2 deletions src/git/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ QString Config::value<QString>(const QString &key,
return defaultValue;
}

git_buf buf = GIT_BUF_INIT_CONST(nullptr, 0);
git_buf buf = GIT_BUF_INIT;
git_config_get_string_buf(&buf, d.data(), key.toUtf8());
QString value = QString::fromUtf8(buf.ptr, buf.size);
git_buf_dispose(&buf);
Expand Down Expand Up @@ -182,7 +182,7 @@ QString Config::globalPath() {
config.remove("global.force");
}

git_buf buf = GIT_BUF_INIT_CONST(nullptr, 0);
git_buf buf = GIT_BUF_INIT;
git_config_find_global(&buf);
QString path = QString::fromUtf8(buf.ptr, buf.size);
git_buf_dispose(&buf);
Expand Down
4 changes: 2 additions & 2 deletions src/git/Diff.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,10 @@ QByteArray Diff::print() {
QByteArray diff;
for (auto file : data.files) {
for (auto hunk : file.hunks) {
diff.append(hunk.header);
diff.append(hunk.header.toUtf8());

for (auto line : hunk.lines)
diff.append(line);
diff.append(line.toUtf8());
}
}
qDebug() << QString(diff);
Expand Down
72 changes: 39 additions & 33 deletions src/git/Filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,38 +38,44 @@ struct FilterInfo {

QString quote(const QString &path) { return QString("\"%1\"").arg(path); }

int apply(git_filter *self, void **payload, git_buf *to, const git_buf *from,
const git_filter_source *src) {
FilterInfo *info = reinterpret_cast<FilterInfo *>(self);
git_filter_mode_t mode = git_filter_source_mode(src);
QString command = (mode == GIT_FILTER_SMUDGE) ? info->smudge : info->clean;

// Substitute path.
command.replace("%f", quote(git_filter_source_path(src)));

QString bash = Command::bashPath();
if (bash.isEmpty())
return info->required ? GIT_EUSER : GIT_PASSTHROUGH;

QProcess process;
git_repository *repo = git_filter_source_repo(src);
process.setWorkingDirectory(git_repository_workdir(repo));

process.start(bash, {"-c", command});
if (!process.waitForStarted())
return info->required ? GIT_EUSER : GIT_PASSTHROUGH;

process.write(from->ptr, from->size);
process.closeWriteChannel();

if (!process.waitForFinished() || process.exitCode()) {
git_error_set_str(GIT_ERROR_FILTER, process.readAllStandardError());
return info->required ? GIT_EUSER : GIT_PASSTHROUGH;
}

QByteArray data = process.readAll();
git_buf_set(to, data.constData(), data.length());
return 0;
int stream(
git_writestream **out,
git_filter *self,
void **payload,
const git_filter_source *src,
git_writestream *next)
{
return -1;
// FilterInfo *info = reinterpret_cast<FilterInfo *>(self);
// git_filter_mode_t mode = git_filter_source_mode(src);
// QString command = (mode == GIT_FILTER_SMUDGE) ? info->smudge : info->clean;

// // Substitute path.
// command.replace("%f", quote(git_filter_source_path(src)));

// QString bash = Command::bashPath();
// if (bash.isEmpty())
// return info->required ? GIT_EUSER : GIT_PASSTHROUGH;

// QProcess process;
// git_repository *repo = git_filter_source_repo(src);
// process.setWorkingDirectory(git_repository_workdir(repo));

// process.start(bash, {"-c", command});
// if (!process.waitForStarted())
// return info->required ? GIT_EUSER : GIT_PASSTHROUGH;

// process.write(from->ptr, from->size);
// process.closeWriteChannel();

// if (!process.waitForFinished() || process.exitCode()) {
// git_error_set_str(GIT_ERROR_FILTER, process.readAllStandardError());
// return info->required ? GIT_EUSER : GIT_PASSTHROUGH;
// }

// QByteArray data = process.readAll();
// git_buf_set(to, data.constData(), data.length());
// return 0;
}

} // namespace
Expand Down Expand Up @@ -101,7 +107,7 @@ void Filter::init() {
info.name = key.toUtf8();
info.attributes = kFilterFmt.arg(key).toUtf8();

info.filter.apply = &apply;
info.filter.stream = &stream;
info.filter.attributes = info.attributes.constData();
git_filter_register(info.name.constData(), &info.filter,
GIT_FILTER_DRIVER_PRIORITY);
Expand Down
8 changes: 4 additions & 4 deletions src/git/Id.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ namespace git {

namespace {

const Id kInvalidId = QByteArray(GIT_OID_RAWSZ, -1);
const Id kInvalidId = QByteArray(GIT_OID_SHA1_SIZE, -1);

} // namespace

Id::Id() { memset(d.id, 0, GIT_OID_RAWSZ); }
Id::Id() { memset(d.id, 0, GIT_OID_SHA1_SIZE); }

Id::Id(const QByteArray &id) {
git_oid_fromraw(&d, reinterpret_cast<const unsigned char *>(id.constData()));
Expand All @@ -31,7 +31,7 @@ Id::Id(const git_oid *id) {
if (id) {
git_oid_cpy(&d, id);
} else {
memset(d.id, 0, GIT_OID_RAWSZ);
memset(d.id, 0, GIT_OID_SHA1_SIZE);
}
}

Expand All @@ -45,7 +45,7 @@ QString Id::toString() const { return toByteArray().toHex(); }

QByteArray Id::toByteArray() const {
const char *data = reinterpret_cast<const char *>(d.id);
return QByteArray::fromRawData(data, GIT_OID_RAWSZ);
return QByteArray::fromRawData(data, GIT_OID_SHA1_SIZE);
}

bool Id::operator<(const Id &rhs) const { return (git_oid_cmp(&d, rhs) < 0); }
Expand Down
5 changes: 3 additions & 2 deletions src/git/Object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ git_object_t Object::type() const { return git_object_type(d.data()); }

Id Object::id() const { return git_object_id(d.data()); }

QString Object::shortId() const {
git_buf buf = GIT_BUF_INIT_CONST(0, 0);
QString Object::shortId() const
{
git_buf buf = GIT_BUF_INIT;
git_object_short_id(&buf, d.data());
QByteArray result(buf.ptr, buf.size);
git_buf_dispose(&buf);
Expand Down
8 changes: 3 additions & 5 deletions src/git/Patch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,11 +324,9 @@ QByteArray Patch::generateResult(QList<QList<QByteArray>> &image,
if (!filters.isValid())
return result;

// Apply filters.
git_buf out = GIT_BUF_INIT_CONST(nullptr, 0);
git_buf raw = GIT_BUF_INIT_CONST(result.constData(), result.length());
(&out, filters, &raw);
git_buf_dispose(&raw);
// Apply filters.
git_buf out = GIT_BUF_INIT;
git_filter_list_apply_to_buffer(&out, filters, result.data(), result.length());

QByteArray filtered(out.ptr, out.size);
git_buf_dispose(&out);
Expand Down
Loading

0 comments on commit 04f1ef5

Please sign in to comment.