SlHelpers
SlGit::Diff Class Reference

Diff is a representation of a git diff. More...

#include <Diff.h>

Classes

struct  ForEachCB
 Callbacks for forEach() More...
 

Public Types

using PrintCB = std::function< int(const git_diff_delta &delta, const git_diff_hunk *hunk, const git_diff_line &line)>
 Callback for print()
 

Public Member Functions

size_t numDeltas () const noexcept
 Get count of deltas in this Diff.
 
size_t numDeltas (const git_delta_t &type) const noexcept
 Get count of deltas with the type (GIT_DELTA_ADDED, ...)
 
const git_diff_delta * getDelta (size_t idx) const noexcept
 Get a delta on the idx-th position.
 
bool findSimilar (const git_diff_find_options *options=nullptr) const noexcept
 Find similar files in the Diff (in-place) More...
 
bool isSortedICase () const noexcept
 Return true if ignore-case-sorted.
 
int forEach (const ForEachCB &forEachCB) const
 Invoke forEachCB callbacks for each file, hunk, ... in the diff. More...
 
int print (git_diff_format_t format, const PrintCB &printCB) const
 Invoke forEachCB callbacks for each file, hunk, ... in the diff. More...
 
std::optional< BuftoBuf (git_diff_format_t format) const noexcept
 Convert to Buf.
 
GitTy * diff () const noexcept
 Get the stored pointer to libgit2's git_diff.
 
 operator GitTy * () const noexcept
 Alias for diff() – implicit conversion.
 

Static Public Member Functions

static std::optional< DiffcreateFromBuffer (std::string_view buffer) noexcept
 Create a new Diff from buffer.
 

Friends

class Repo
 

Detailed Description

Diff is a representation of a git diff.

Member Function Documentation

◆ findSimilar()

bool SlGit::Diff::findSimilar ( const git_diff_find_options *  options = nullptr) const
inlinenoexcept

Find similar files in the Diff (in-place)

Parameters
optionsOptions to use (like rename threshold)
Returns
True on success.
git diff -M

◆ forEach()

int SlGit::Diff::forEach ( const ForEachCB forEachCB) const

Invoke forEachCB callbacks for each file, hunk, ... in the diff.

Parameters
forEachCBCallbacks
Returns
0 on success, non-zero callback return value, or error code.

◆ print()

int SlGit::Diff::print ( git_diff_format_t  format,
const PrintCB printCB 
) const

Invoke forEachCB callbacks for each file, hunk, ... in the diff.

Parameters
formatGIT_DIFF_FORMAT_PATCH, GIT_DIFF_FORMAT_PATCH_HEADER, ...
printCBCallback
Returns
0 on success, non-zero callback return value, or error code.

The documentation for this class was generated from the following file: