git2wrap

C++20 wrapper for libgit2
git clone git://git.dimitrijedobrota.com/git2wrap.git
Log | Files | Refs | README | LICENSE | HACKING | CONTRIBUTING | CODE_OF_CONDUCT | BUILDING

commit 49a2ec4865bc1f3d1c5578f94cf5bb3a3a8fd295
parent e1fdadc52dbd8abfaa899c4e0fdd3cae5ac127d3
author Dimitrije Dobrota < mail@dimitrijedobrota.com >
date Sun, 12 Jan 2025 19:27:39 +0100

Diff_stats class

Diffstat:
M CMakeLists.txt | + -
M include/git2wrap/diff.hpp | +++++++++++++++++
M include/git2wrap/types.hpp | +
M source/diff.cpp | +++++++++++++++++++++++++++++++

4 files changed, 50 insertions(+), 1 deletions(-)


diff --git a/ CMakeLists.txt b/ CMakeLists.txt

@@ -4,7 +4,7 @@ include(cmake/prelude.cmake)


project(
git2wrap
VERSION 0.1.15
VERSION 0.1.16
DESCRIPTION "C++ 20 wrapper for libgit2"
HOMEPAGE_URL "https://git.dimitrijedobrota.com/git2wrap.git"
LANGUAGES CXX

diff --git a/ include/git2wrap/diff.hpp b/ include/git2wrap/diff.hpp

@@ -14,6 +14,10 @@ class GIT2WRAP_EXPORT diff

public:
diff(git_diff* dif, repositoryPtr repo);

operator bool() const { return m_diff != nullptr; } // NOLINT

diff_stats get_stats() const;

int foreach(diff_file_cb file_cb,
diff_binary_cb binary_cb,
diff_hunk_cb hunk_cb,

@@ -29,4 +33,17 @@ private:

repositoryPtr m_repo;
};

class GIT2WRAP_EXPORT diff_stats
{
public:
explicit diff_stats(git_diff_stats* stats);

size_t files_changed() const;
size_t insertions() const;
size_t deletions() const;

private:
diff_statsUPtr m_stats;
};

} // namespace git2wrap

diff --git a/ include/git2wrap/types.hpp b/ include/git2wrap/types.hpp

@@ -23,6 +23,7 @@ class libgit2;

CLASS(branch_iterator)
CLASS(commit)
CLASS(diff)
CLASS(diff_stats)
CLASS(object)
CLASS(oid)
CLASS(reference)

diff --git a/ source/diff.cpp b/ source/diff.cpp

@@ -36,4 +36,35 @@ diff diff::tree_to_tree(const tree& old,

return {dif, old.get_owner()};
}

diff_stats::diff_stats(git_diff_stats* stats)
: m_stats(stats, git_diff_stats_free)
{
}

diff_stats diff::get_stats() const
{
git_diff_stats* stats = nullptr;

if (auto err = git_diff_get_stats(&stats, m_diff.get())) {
throw error(err, git_error_last(), __FILE__, __LINE__);
}

return diff_stats(stats);
}

size_t diff_stats::files_changed() const
{
return git_diff_stats_files_changed(m_stats.get());
}

size_t diff_stats::insertions() const
{
return git_diff_stats_insertions(m_stats.get());
}

size_t diff_stats::deletions() const
{
return git_diff_stats_deletions(m_stats.get());
}

} // namespace git2wrap