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 The 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; }
93
94 void SetUsername( const wxString& aUsername ) { m_username = aUsername; }
95 void SetPassword( const wxString& aPassword ) { m_password = aPassword; }
96 void SetSSHKey( const wxString& aSSHKey );
97
98 void SetConnType( GIT_CONN_TYPE aConnType ) { m_connType = aConnType; }
99 void SetConnType( unsigned aConnType )
100 {
101 if( aConnType < static_cast<unsigned>( GIT_CONN_TYPE::GIT_CONN_LAST ) )
102 m_connType = static_cast<GIT_CONN_TYPE>( aConnType );
103 }
104
105 // Holds a temporary variable that can be used by the authentication callback
106 // to remember which types of authentication have been tested so that we
107 // don't loop forever.
108 unsigned& TestedTypes() { return m_testedTypes; }
109
110 // Returns true if the repository has local commits that have not been pushed
111 bool HasLocalCommits() const;
112
113 // Returns true if the repository has a remote that can be pushed to pulled from
114 bool HasPushAndPullRemote() const;
115
116 // Updates the password and remote information for the repository given the current branch
118
119 wxString GetRemotename() const;
120
122
124 {
125 if( m_nextPublicKey >= static_cast<int>( m_publicKeys.size() ) )
126 return wxEmptyString;
127
129 }
130
131protected:
132 git_repository* m_repo;
133
135 wxString m_remote; // This is the full connection string
136 wxString m_hostname; // This is just the hostname without the protocol, username, or password
137 wxString m_username;
138 wxString m_password;
139
141
142private:
143 void updatePublicKeys();
145
146 std::vector<wxString> m_publicKeys;
148
149};
150
151
152extern "C" int progress_cb( const char* str, int len, void* data );
153extern "C" void clone_progress_cb( const char* str, size_t len, size_t total, void* data );
154extern "C" int transfer_progress_cb( const git_transfer_progress* aStats, void* aPayload );
155extern "C" int update_cb( const char* aRefname, const git_oid* aFirst, const git_oid* aSecond,
156 void* aPayload );
157extern "C" int push_transfer_progress_cb( unsigned int aCurrent, unsigned int aTotal,
158 size_t aBytes, void* aPayload );
159extern "C" int push_update_reference_cb( const char* aRefname, const char* aStatus,
160 void* aPayload );
161
162extern "C" int fetchhead_foreach_cb( const char*, const char*,
163 const git_oid* aOID, unsigned int aIsMerge, void* aPayload );
164extern "C" int credentials_cb( git_cred** aOut, const char* aUrl, const char* aUsername,
165 unsigned int aAllowedTypes, void* aPayload );
166
167#endif // _GIT_COMMON_H_
wxString m_username
git_repository * m_repo
std::vector< wxString > GetBranchNames() const
void updateConnectionType()
unsigned m_testedTypes
void SetConnType(GIT_CONN_TYPE aConnType)
wxString GetCurrentBranchName() 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_hostname
wxString m_password
wxString GetNextPublicKey()
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 ...
std::vector< wxString > m_publicKeys
bool HasPushAndPullRemote() const
wxString GetUsername() const
GIT_CONN_TYPE m_connType
void UpdateCurrentBranchInfo()
bool HasLocalCommits() const
void SetConnType(unsigned aConnType)
unsigned & TestedTypes()
void SetPassword(const wxString &aPassword)
virtual void UpdateProgress(int aCurrent, int aTotal, const wxString &aMessage)
wxString GetRemotename() const
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)