KiCad PCB EDA Suite
Loading...
Searching...
No Matches
KIGIT Namespace Reference

Classes

struct  CHANGED_FILE
 
struct  MERGE_BLOBS
 Decoded ancestor/ours/theirs blob contents for a 3-way merge driver. More...
 
class  PROJECT_GIT_UTILS
 Utility class with helper functions for project level git operations. More...
 

Typedefs

using GitRepositoryPtr
 A unique pointer for git_repository objects with automatic cleanup.
 
using GitReferencePtr
 A unique pointer for git_reference objects with automatic cleanup.
 
using GitObjectPtr
 A unique pointer for git_object objects with automatic cleanup.
 
using GitCommitPtr
 A unique pointer for git_commit objects with automatic cleanup.
 
using GitTreePtr
 A unique pointer for git_tree objects with automatic cleanup.
 
using GitIndexPtr
 A unique pointer for git_index objects with automatic cleanup.
 
using GitRebasePtr
 A unique pointer for git_rebase objects with automatic cleanup.
 
using GitRevWalkPtr
 A unique pointer for git_revwalk objects with automatic cleanup.
 
using GitDiffPtr
 A unique pointer for git_diff objects with automatic cleanup.
 
using GitSignaturePtr
 A unique pointer for git_signature objects with automatic cleanup.
 
using GitConfigPtr
 A unique pointer for git_config objects with automatic cleanup.
 
using GitRemotePtr
 A unique pointer for git_remote objects with automatic cleanup.
 
using GitAnnotatedCommitPtr
 A unique pointer for git_annotated_commit objects with automatic cleanup.
 
using GitOidPtr
 A unique pointer for git_oid objects with automatic cleanup.
 
using GitBufPtr
 A unique pointer for git_buf objects with automatic cleanup.
 
using GitBlamePtr
 A unique pointer for git_blame objects with automatic cleanup.
 
using GitBlobPtr
 A unique pointer for git_blob objects with automatic cleanup.
 
using GitBranchIteratorPtr
 A unique pointer for git_branch_iterator objects with automatic cleanup.
 
using GitConfigEntryPtr
 A unique pointer for git_config_entry objects with automatic cleanup.
 
using GitConfigIteratorPtr
 A unique pointer for git_config_iterator objects with automatic cleanup.
 
using GitCredentialPtr
 A unique pointer for git_credential objects with automatic cleanup.
 
using GitOidArrayPtr
 A unique pointer for git_oidarray objects with automatic cleanup.
 
using GitStrArrayPtr
 A unique pointer for git_strarray objects with automatic cleanup.
 
using GitDescribeResultPtr
 A unique pointer for git_describe_result objects with automatic cleanup.
 
using GitDiffStatsPtr
 A unique pointer for git_diff_stats objects with automatic cleanup.
 
using GitFilterListPtr
 A unique pointer for git_filter_list objects with automatic cleanup.
 
using GitIndexerPtr
 A unique pointer for git_indexer objects with automatic cleanup.
 
using GitIndexIteratorPtr
 A unique pointer for git_index_iterator objects with automatic cleanup.
 
using GitIndexConflictIteratorPtr
 A unique pointer for git_index_conflict_iterator objects with automatic cleanup.
 
using GitStatusListPtr
 A unique pointer for git_status_list objects with automatic cleanup.
 
using MERGE_APPLY_FN
 Signature for a KiCad merge-driver apply function.
 

Enumerations

enum class  FILE_CHANGE_STATUS {
  UNCHANGED , ADDED , REMOVED , MODIFIED ,
  RENAMED , COPIED , TYPECHANGE
}
 

Functions

const char * FileChangeStatusToString (FILE_CHANGE_STATUS aStatus)
 
std::vector< CHANGED_FILECompareRefs (git_repository *aRepo, const wxString &aBaseRef, const wxString &aHeadRef)
 Compare two git refs (branch / tag / commit OID) within a repository and return the per-file change list.
 
git_tree * ResolveRefToTree (git_repository *aRepo, const wxString &aRef)
 Resolve a string ref (branch name, short OID, full OID, tag) to its tree.
 
void CollectDiffDeltas (git_diff *aDiff, const std::function< void(const git_diff_delta &)> &aCallback)
 Walk every delta in a computed diff, invoking aCallback once per delta.
 
bool RegisterMergeDriver (const char *aName, MERGE_APPLY_FN aApply)
 Register a KiCad merge driver with libgit2.
 
std::string BlobToString (git_blob *aBlob)
 Copy a libgit2 blob's raw bytes into a std::string.
 
int WriteToGitBuf (git_buf *aBuf, const std::string &aContent)
 Allocate a libgit2-owned buffer big enough for aContent and copy the bytes plus a trailing NUL.
 
int LoadMergeBlobs (const git_merge_driver_source *aSource, MERGE_BLOBS &aBlobs)
 Look up the ancestor/ours/theirs blobs of a merge-driver source and decode them into aBlobs.
 
bool TryTrivialMerge (const MERGE_BLOBS &aBlobs, git_buf *aResult, int *aRc)
 Resolve the trivial 3-way cases (identical sides, or one side unchanged from the ancestor).
 
template<typename DRIVER>
int ApplyMergeDriver (const git_merge_driver_source *aSrc, const char **aPathOut, unsigned int *aModeOut, git_buf *aMergedOut)
 Shared libgit2 merge-driver apply callback shim.
 

Typedef Documentation

◆ GitAnnotatedCommitPtr

Initial value:
std::unique_ptr<git_annotated_commit,
decltype([](git_annotated_commit* aCommit) {
git_annotated_commit_free(aCommit);
})>

A unique pointer for git_annotated_commit objects with automatic cleanup.

Definition at line 120 of file kicad_git_memory.h.

◆ GitBlamePtr

Initial value:
std::unique_ptr<git_blame,
decltype([](git_blame* aBlame) {
git_blame_free(aBlame);
})>

A unique pointer for git_blame objects with automatic cleanup.

Definition at line 144 of file kicad_git_memory.h.

◆ GitBlobPtr

Initial value:
std::unique_ptr<git_blob,
decltype([](git_blob* aBlob) {
git_blob_free(aBlob);
})>

A unique pointer for git_blob objects with automatic cleanup.

Definition at line 152 of file kicad_git_memory.h.

◆ GitBranchIteratorPtr

Initial value:
std::unique_ptr<git_branch_iterator,
decltype([](git_branch_iterator* aIter) {
git_branch_iterator_free(aIter);
})>

A unique pointer for git_branch_iterator objects with automatic cleanup.

Definition at line 160 of file kicad_git_memory.h.

◆ GitBufPtr

Initial value:
std::unique_ptr<git_buf,
decltype([](git_buf* aBuf) {
git_buf_free(aBuf);
})>

A unique pointer for git_buf objects with automatic cleanup.

Definition at line 136 of file kicad_git_memory.h.

◆ GitCommitPtr

Initial value:
std::unique_ptr<git_commit,
decltype([](git_commit* aCommit) {
git_commit_free(aCommit);
})>

A unique pointer for git_commit objects with automatic cleanup.

Definition at line 48 of file kicad_git_memory.h.

◆ GitConfigEntryPtr

Initial value:
std::unique_ptr<git_config_entry,
decltype([](git_config_entry* aEntry) {
git_config_entry_free(aEntry);
})>

A unique pointer for git_config_entry objects with automatic cleanup.

Definition at line 168 of file kicad_git_memory.h.

◆ GitConfigIteratorPtr

Initial value:
std::unique_ptr<git_config_iterator,
decltype([](git_config_iterator* aIter) {
git_config_iterator_free(aIter);
})>

A unique pointer for git_config_iterator objects with automatic cleanup.

Definition at line 176 of file kicad_git_memory.h.

◆ GitConfigPtr

Initial value:
std::unique_ptr<git_config,
decltype([](git_config* aConfig) {
git_config_free(aConfig);
})>

A unique pointer for git_config objects with automatic cleanup.

Definition at line 104 of file kicad_git_memory.h.

◆ GitCredentialPtr

Initial value:
std::unique_ptr<git_credential,
decltype([](git_credential* aCred) {
git_credential_free(aCred);
})>

A unique pointer for git_credential objects with automatic cleanup.

Definition at line 184 of file kicad_git_memory.h.

◆ GitDescribeResultPtr

Initial value:
std::unique_ptr<git_describe_result,
decltype([](git_describe_result* aResult) {
git_describe_result_free(aResult);
})>

A unique pointer for git_describe_result objects with automatic cleanup.

Definition at line 208 of file kicad_git_memory.h.

◆ GitDiffPtr

Initial value:
std::unique_ptr<git_diff,
decltype([](git_diff* aDiff) {
git_diff_free(aDiff);
})>

A unique pointer for git_diff objects with automatic cleanup.

Definition at line 88 of file kicad_git_memory.h.

◆ GitDiffStatsPtr

Initial value:
std::unique_ptr<git_diff_stats,
decltype([](git_diff_stats* aStats) {
git_diff_stats_free(aStats);
})>

A unique pointer for git_diff_stats objects with automatic cleanup.

Definition at line 216 of file kicad_git_memory.h.

◆ GitFilterListPtr

Initial value:
std::unique_ptr<git_filter_list,
decltype([](git_filter_list* aFilters) {
git_filter_list_free(aFilters);
})>

A unique pointer for git_filter_list objects with automatic cleanup.

Definition at line 224 of file kicad_git_memory.h.

◆ GitIndexConflictIteratorPtr

Initial value:
std::unique_ptr<git_index_conflict_iterator,
decltype([](git_index_conflict_iterator* aIterator) {
git_index_conflict_iterator_free(aIterator);
})>

A unique pointer for git_index_conflict_iterator objects with automatic cleanup.

Definition at line 248 of file kicad_git_memory.h.

◆ GitIndexerPtr

Initial value:
std::unique_ptr<git_indexer,
decltype([](git_indexer* aIdx) {
git_indexer_free(aIdx);
})>

A unique pointer for git_indexer objects with automatic cleanup.

Definition at line 232 of file kicad_git_memory.h.

◆ GitIndexIteratorPtr

Initial value:
std::unique_ptr<git_index_iterator,
decltype([](git_index_iterator* aIterator) {
git_index_iterator_free(aIterator);
})>

A unique pointer for git_index_iterator objects with automatic cleanup.

Definition at line 240 of file kicad_git_memory.h.

◆ GitIndexPtr

Initial value:
std::unique_ptr<git_index,
decltype([](git_index* aIndex) {
git_index_free(aIndex);
})>

A unique pointer for git_index objects with automatic cleanup.

Definition at line 64 of file kicad_git_memory.h.

◆ GitObjectPtr

Initial value:
std::unique_ptr<git_object,
decltype([](git_object* aObject) {
git_object_free(aObject);
})>

A unique pointer for git_object objects with automatic cleanup.

Definition at line 41 of file kicad_git_memory.h.

◆ GitOidArrayPtr

Initial value:
std::unique_ptr<git_oidarray,
decltype([](git_oidarray* aArray) {
git_oidarray_free(aArray);
})>

A unique pointer for git_oidarray objects with automatic cleanup.

Definition at line 192 of file kicad_git_memory.h.

◆ GitOidPtr

Initial value:
std::unique_ptr<git_oid,
decltype([](git_oid* aOid) {
delete aOid;
})>

A unique pointer for git_oid objects with automatic cleanup.

Definition at line 128 of file kicad_git_memory.h.

◆ GitRebasePtr

Initial value:
std::unique_ptr<git_rebase,
decltype([](git_rebase* aRebase) {
git_rebase_free(aRebase);
})>

A unique pointer for git_rebase objects with automatic cleanup.

Definition at line 72 of file kicad_git_memory.h.

◆ GitReferencePtr

Initial value:
std::unique_ptr<git_reference,
decltype([](git_reference* aRef) {
git_reference_free(aRef);
})>

A unique pointer for git_reference objects with automatic cleanup.

Definition at line 33 of file kicad_git_memory.h.

◆ GitRemotePtr

Initial value:
std::unique_ptr<git_remote,
decltype([](git_remote* aRemote) {
git_remote_free(aRemote);
})>

A unique pointer for git_remote objects with automatic cleanup.

Definition at line 112 of file kicad_git_memory.h.

◆ GitRepositoryPtr

Initial value:
std::unique_ptr<git_repository,
decltype([](git_repository* aRepo) {
git_repository_free(aRepo);
})>

A unique pointer for git_repository objects with automatic cleanup.

Definition at line 25 of file kicad_git_memory.h.

◆ GitRevWalkPtr

Initial value:
std::unique_ptr<git_revwalk,
decltype([](git_revwalk* aWalker) {
git_revwalk_free(aWalker);
})>

A unique pointer for git_revwalk objects with automatic cleanup.

Definition at line 80 of file kicad_git_memory.h.

◆ GitSignaturePtr

Initial value:
std::unique_ptr<git_signature,
decltype([](git_signature* aSignature) {
git_signature_free(aSignature);
})>

A unique pointer for git_signature objects with automatic cleanup.

Definition at line 96 of file kicad_git_memory.h.

◆ GitStatusListPtr

Initial value:
std::unique_ptr<git_status_list,
decltype([](git_status_list* aList) {
git_status_list_free(aList);
})>

A unique pointer for git_status_list objects with automatic cleanup.

Definition at line 256 of file kicad_git_memory.h.

◆ GitStrArrayPtr

Initial value:
std::unique_ptr<git_strarray,
decltype([](git_strarray* aArray) {
git_strarray_free(aArray);
})>

A unique pointer for git_strarray objects with automatic cleanup.

Definition at line 200 of file kicad_git_memory.h.

◆ GitTreePtr

Initial value:
std::unique_ptr<git_tree,
decltype([](git_tree* aTree) {
git_tree_free(aTree);
})>

A unique pointer for git_tree objects with automatic cleanup.

Definition at line 56 of file kicad_git_memory.h.

◆ MERGE_APPLY_FN

Initial value:
int ( * )( const git_merge_driver_source* src,
const char** path_out,
unsigned int* mode_out,
git_buf* merged_out )

Signature for a KiCad merge-driver apply function.

Mirrors the libgit2 merge driver apply callback, but with simpler args because we only need the source + a target buffer.

src - libgit2 merge driver source (ancestor/ours/theirs blobs) path_out - destination for the resulting path mode_out - destination for the resulting file mode merged_out - destination buffer for the merged blob

Returns 0 on success, GIT_EMERGECONFLICT (-13) on unresolved conflicts, or any other negative git error code on failure. uint32_t for mode_out per libgit2; included via <cstdint> by callers.

Definition at line 47 of file kigit_driver_registry.h.

Enumeration Type Documentation

◆ FILE_CHANGE_STATUS

enum class KIGIT::FILE_CHANGE_STATUS
strong
Enumerator
UNCHANGED 
ADDED 
REMOVED 
MODIFIED 
RENAMED 
COPIED 
TYPECHANGE 

Definition at line 37 of file git_compare_handler.h.

Function Documentation

◆ ApplyMergeDriver()

template<typename DRIVER>
int KIGIT::ApplyMergeDriver ( const git_merge_driver_source * aSrc,
const char ** aPathOut,
unsigned int * aModeOut,
git_buf * aMergedOut )

Shared libgit2 merge-driver apply callback shim.

Constructs DRIVER over the source, runs its Merge(), and on success or conflict copies ours' path and mode to the outputs. DRIVER must expose a (git_merge_driver_source*, git_buf*) constructor and an int Merge() method.

Definition at line 88 of file kigit_merge_blob_utils.h.

Referenced by KIGIT_PCB_MERGE::Apply(), and KIGIT_TRIVIAL_MERGE_BASE< DERIVED >::Apply().

◆ BlobToString()

KICOMMON_API std::string KIGIT::BlobToString ( git_blob * aBlob)

Copy a libgit2 blob's raw bytes into a std::string.

Returns an empty string if the blob is null.

Definition at line 36 of file kigit_merge_blob_utils.cpp.

Referenced by LoadMergeBlobs().

◆ CollectDiffDeltas()

APIEXPORT void KIGIT::CollectDiffDeltas ( git_diff * aDiff,
const std::function< void(const git_diff_delta &)> & aCallback )

Walk every delta in a computed diff, invoking aCallback once per delta.

Centralizes the git_diff_num_deltas / git_diff_get_delta loop. Null deltas are skipped. A null diff is a no-op.

The callback is a std::function rather than a header-inline template because this helper lives behind the APIEXPORT/libkicommon ABI boundary; a template would have to re-expose the git2 loop in the header to every caller.

Definition at line 1186 of file kicad_git_common.cpp.

References delta.

Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), CompareRefs(), KIGIT_COMMON::GetDifferentFiles(), and PROJECT_TREE_PANE::onGitAmendCommit().

◆ CompareRefs()

KICOMMON_API std::vector< CHANGED_FILE > KIGIT::CompareRefs ( git_repository * aRepo,
const wxString & aBaseRef,
const wxString & aHeadRef )

Compare two git refs (branch / tag / commit OID) within a repository and return the per-file change list.

Used by the git PR-review dialog (Phase 10) to populate the "changed files" list a user clicks through to open the file-compare dialog.

aRepo must not be null. Returns an empty vector on error and logs via wxLogTrace( traceGit ).

Definition at line 76 of file git_compare_handler.cpp.

References CollectDiffDeltas(), KIGIT_COMMON::GetLastGitError(), KIGIT::CHANGED_FILE::oldPath, KIGIT::CHANGED_FILE::path, ResolveRefToTree(), result, KIGIT::CHANGED_FILE::status, and traceGit.

Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), and DIALOG_GIT_MR_REVIEW::populateFileList().

◆ FileChangeStatusToString()

KICOMMON_API const char * KIGIT::FileChangeStatusToString ( FILE_CHANGE_STATUS aStatus)

◆ LoadMergeBlobs()

KICOMMON_API int KIGIT::LoadMergeBlobs ( const git_merge_driver_source * aSource,
MERGE_BLOBS & aBlobs )

Look up the ancestor/ours/theirs blobs of a merge-driver source and decode them into aBlobs.

The blobs are freed before returning (only the strings are kept), so callers need no cleanup.

Returns 0 on success, GIT_PASSTHROUGH when ours/theirs are missing, or GIT_ENOTFOUND when a blob lookup fails.

Definition at line 62 of file kigit_merge_blob_utils.cpp.

References KIGIT::MERGE_BLOBS::ancestor, BlobToString(), KIGIT::MERGE_BLOBS::ours, and KIGIT::MERGE_BLOBS::theirs.

Referenced by KIGIT_PCB_MERGE::Merge(), and KIGIT_TRIVIAL_MERGE_BASE< DERIVED >::Merge().

◆ RegisterMergeDriver()

KICOMMON_API bool KIGIT::RegisterMergeDriver ( const char * aName,
MERGE_APPLY_FN aApply )

Register a KiCad merge driver with libgit2.

The driver name must match the merge=<name> attribute set in .gitattributes (e.g. "kicad-pcb", "kicad-sch", "kicad-sym", "kicad-fp-lib").

Idempotent: calling twice with the same name is a no-op. Thread-safety: libgit2's git_merge_driver_register is NOT thread-safe; this function holds an internal mutex around the call, but callers should still ensure it runs once at process init, before any thread fan-out (libgit2 may not tolerate concurrent registration even with our local mutex if its global driver table is read by a parallel merge).

Returns true on success.

Definition at line 80 of file kigit_driver_registry.cpp.

References KIGIT_COMMON::GetLastGitError(), name, and traceGit.

Referenced by PCB::IFACE::OnKifaceStart(), and SCH::IFACE::OnKifaceStart().

◆ ResolveRefToTree()

APIEXPORT git_tree * KIGIT::ResolveRefToTree ( git_repository * aRepo,
const wxString & aRef )

Resolve a string ref (branch name, short OID, full OID, tag) to its tree.

Runs git_revparse_single followed by git_object_peel( GIT_OBJECT_TREE ), so a commit, tag or tree ref all resolve to the underlying tree. Returns nullptr on error and logs via wxLogTrace( traceGit ).

The caller owns the returned tree and must free it with git_tree_free (wrap in KIGIT::GitTreePtr for RAII). The return type is a raw pointer rather than GitTreePtr because the lambda-deleter closure type backing GitTreePtr is distinct per translation unit, so it cannot cross the kicommon ABI boundary.

Definition at line 1157 of file kicad_git_common.cpp.

References KIGIT_COMMON::GetLastGitError(), and traceGit.

Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), CompareRefs(), and DIALOG_GIT_MR_REVIEW::populateFileList().

◆ TryTrivialMerge()

KICOMMON_API bool KIGIT::TryTrivialMerge ( const MERGE_BLOBS & aBlobs,
git_buf * aResult,
int * aRc )

Resolve the trivial 3-way cases (identical sides, or one side unchanged from the ancestor).

On a trivial hit the resolved content is written to aResult, aRc is set to the WriteToGitBuf return code, and true is returned. Returns false when a real merge is required.

Definition at line 99 of file kigit_merge_blob_utils.cpp.

References KIGIT::MERGE_BLOBS::ancestor, KIGIT::MERGE_BLOBS::ours, KIGIT::MERGE_BLOBS::theirs, and WriteToGitBuf().

Referenced by KIGIT_TRIVIAL_MERGE_BASE< DERIVED >::Merge().

◆ WriteToGitBuf()

KICOMMON_API int KIGIT::WriteToGitBuf ( git_buf * aBuf,
const std::string & aContent )

Allocate a libgit2-owned buffer big enough for aContent and copy the bytes plus a trailing NUL.

Uses git_buf_grow so libgit2 disposes the buffer correctly via git_buf_dispose.

Returns 0 on success, -1 on allocation failure.

Definition at line 47 of file kigit_merge_blob_utils.cpp.

Referenced by KIGIT_PCB_MERGE::Merge(), KIGIT_TRIVIAL_MERGE_BASE< DERIVED >::Merge(), and TryTrivialMerge().