KiCad PCB EDA Suite
Loading...
Searching...
No Matches
kicad_git_common.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2023 KiCad Developers, see AUTHORS.TXT for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 3
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, you may find one here:
18 * http://www.gnu.org/licenses/gpl-3.0.html
19 * or you may search the http://www.gnu.org website for the version 3 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
24#ifndef _GIT_COMMON_H_
25#define _GIT_COMMON_H_
26
28
29#include <git2.h>
30#include <set>
31
32#include <wx/string.h>
33
35{
36
37public:
38 KIGIT_COMMON( git_repository* aRepo );
40
41 git_repository* GetRepo() const;
42
43 void SetRepo( git_repository* aRepo )
44 {
45 m_repo = aRepo;
46 }
47
48 wxString GetCurrentBranchName() const;
49
50 std::vector<wxString> GetBranchNames() const;
51
52 virtual void UpdateProgress( int aCurrent, int aTotal, const wxString& aMessage ) {};
53
60 std::vector<wxString> GetProjectDirs();
61
67 std::pair<std::set<wxString>,std::set<wxString>> GetDifferentFiles() const;
68
69 enum class GIT_STATUS
70 {
73 GIT_STATUS_MODIFIED, // File changed but not committed to local repository
76 GIT_STATUS_BEHIND, // File changed in remote repository but not in local
77 GIT_STATUS_AHEAD, // File changed in local repository but not in remote
80 };
81
82 enum class GIT_CONN_TYPE
83 {
88 };
89
90 wxString GetUsername() const { return m_username; }
91 wxString GetPassword() const { return m_password; }
92 wxString GetSSHKey() const { return m_sshKey; }
94
95 void SetUsername( const wxString& aUsername ) { m_username = aUsername; }
96 void SetPassword( const wxString& aPassword ) { m_password = aPassword; }
97 void SetSSHKey( const wxString& aSSHKey ) { m_sshKey = aSSHKey; }
98
99 void SetConnType( GIT_CONN_TYPE aConnType ) { m_connType = aConnType; }
100 void SetConnType( unsigned aConnType )
101 {
102 if( aConnType < static_cast<unsigned>( GIT_CONN_TYPE::GIT_CONN_LAST ) )
103 m_connType = static_cast<GIT_CONN_TYPE>( aConnType );
104 }
105
106 // Holds a temporary variable that can be used by the authentication callback
107 // to remember which types of authentication have been tested so that we
108 // don't loop forever.
109 unsigned& TestedTypes() { return m_testedTypes; }
110
111 // Returns true if the repository has local commits that have not been pushed
112 bool HasLocalCommits() const;
113
114 // Returns true if the repository has a remote that can be pushed to pulled from
115 bool HasPushAndPullRemote() const;
116
117protected:
118 git_repository* m_repo;
119
121 wxString m_username;
122 wxString m_password;
123 wxString m_sshKey;
124
126
127};
128
129
130extern "C" int progress_cb( const char* str, int len, void* data );
131extern "C" void clone_progress_cb( const char* str, size_t len, size_t total, void* data );
132extern "C" int transfer_progress_cb( const git_transfer_progress* aStats, void* aPayload );
133extern "C" int update_cb( const char* aRefname, const git_oid* aFirst, const git_oid* aSecond,
134 void* aPayload );
135extern "C" int push_transfer_progress_cb( unsigned int aCurrent, unsigned int aTotal,
136 size_t aBytes, void* aPayload );
137extern "C" int push_update_reference_cb( const char* aRefname, const char* aStatus,
138 void* aPayload );
139
140extern "C" int fetchhead_foreach_cb( const char*, const char*,
141 const git_oid* aOID, unsigned int aIsMerge, void* aPayload );
142extern "C" int credentials_cb( git_cred** aOut, const char* aUrl, const char* aUsername,
143 unsigned int aAllowedTypes, void* aPayload );
144
145#endif // _GIT_COMMON_H_
wxString m_username
git_repository * m_repo
std::vector< wxString > GetBranchNames() const
unsigned m_testedTypes
void SetConnType(GIT_CONN_TYPE aConnType)
wxString GetCurrentBranchName() const
wxString GetSSHKey() const
void SetSSHKey(const wxString &aSSHKey)
void SetUsername(const wxString &aUsername)
std::vector< wxString > GetProjectDirs()
Return a vector of project files in the repository.
GIT_CONN_TYPE GetConnType() const
wxString GetPassword() const
git_repository * GetRepo() const
wxString m_password
std::pair< std::set< wxString >, std::set< wxString > > GetDifferentFiles() const
Return a pair of sets of files that differ locally from the remote repository The first set is files ...
bool HasPushAndPullRemote() const
wxString GetUsername() const
GIT_CONN_TYPE m_connType
bool HasLocalCommits() const
void SetConnType(unsigned aConnType)
unsigned & TestedTypes()
void SetPassword(const wxString &aPassword)
virtual void UpdateProgress(int aCurrent, int aTotal, const wxString &aMessage)
void SetRepo(git_repository *aRepo)
int fetchhead_foreach_cb(const char *, const char *, const git_oid *aOID, unsigned int aIsMerge, void *aPayload)
int push_update_reference_cb(const char *aRefname, const char *aStatus, void *aPayload)
int update_cb(const char *aRefname, const git_oid *aFirst, const git_oid *aSecond, void *aPayload)
int transfer_progress_cb(const git_transfer_progress *aStats, void *aPayload)
int credentials_cb(git_cred **aOut, const char *aUrl, const char *aUsername, unsigned int aAllowedTypes, void *aPayload)
void clone_progress_cb(const char *str, size_t len, size_t total, void *data)
int push_transfer_progress_cb(unsigned int aCurrent, unsigned int aTotal, size_t aBytes, void *aPayload)
int progress_cb(const char *str, int len, void *data)