File indexing completed on 2025-01-05 05:14:45
0001 /* 0002 SPDX-FileCopyrightText: 2022 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: GPL-3.0-or-later 0005 */ 0006 0007 #include "fetchobserver.h" 0008 #include <git2/oid.h> 0009 0010 namespace Git 0011 { 0012 0013 namespace FetchObserverCallbacks 0014 { 0015 0016 int git_helper_update_tips_cb(const char *refname, const git_oid *a, const git_oid *b, void *data) 0017 { 0018 auto observer = reinterpret_cast<Git::FetchObserver *>(data); 0019 0020 return 0; 0021 } 0022 0023 int git_helper_sideband_progress_cb(const char *str, int len, void *payload) 0024 { 0025 auto observer = reinterpret_cast<Git::FetchObserver *>(payload); 0026 0027 if (!observer) 0028 return 0; 0029 0030 Q_EMIT observer->message(QString::fromLocal8Bit(str, len)); 0031 0032 return 0; 0033 } 0034 0035 int git_helper_transfer_progress_cb(const git_indexer_progress *stats, void *payload) 0036 { 0037 auto observer = reinterpret_cast<Git::FetchObserver *>(payload); 0038 0039 if (!observer) 0040 return 0; 0041 0042 observer->setTotalObjects(stats->total_objects); 0043 observer->setIndexedObjects(stats->indexed_objects); 0044 observer->setReceivedObjects(stats->received_objects); 0045 observer->setLocalObjects(stats->local_objects); 0046 observer->setTotalDeltas(stats->total_deltas); 0047 observer->setIndexedDeltas(stats->indexed_deltas); 0048 return 0; 0049 } 0050 0051 int git_helper_credentials_cb(git_credential **out, const char *url, const char *username_from_url, unsigned int allowed_types, void *payload) 0052 { 0053 auto observer = reinterpret_cast<Git::FetchObserver *>(payload); 0054 0055 if (!observer) 0056 return 0; 0057 0058 Credential cred; 0059 0060 cred.setUsername(username_from_url); 0061 0062 Credential::AllowedTypes credAllowedType{}; 0063 if (allowed_types & GIT_CREDENTIAL_USERPASS_PLAINTEXT) 0064 credAllowedType |= Credential::AllowedType::UserpassPlaintext; 0065 if (allowed_types & GIT_CREDENTIAL_SSH_KEY) 0066 credAllowedType |= Credential::AllowedType::SshKey; 0067 if (allowed_types & GIT_CREDENTIAL_SSH_CUSTOM) 0068 credAllowedType |= Credential::AllowedType::SshCustom; 0069 if (allowed_types & GIT_CREDENTIAL_DEFAULT) 0070 credAllowedType |= Credential::AllowedType::Defaut; 0071 if (allowed_types & GIT_CREDENTIAL_SSH_INTERACTIVE) 0072 credAllowedType |= Credential::AllowedType::SshInteractive; 0073 if (allowed_types & GIT_CREDENTIAL_USERNAME) 0074 credAllowedType |= Credential::AllowedType::Username; 0075 if (allowed_types & GIT_CREDENTIAL_SSH_MEMORY) 0076 credAllowedType |= Credential::AllowedType::SshMemory; 0077 0078 cred.setAllowedTypes(credAllowedType); 0079 0080 Q_EMIT observer->credentialRequeted(QString{url}, &cred); 0081 0082 git_credential_userpass_plaintext_new(out, observer->username().toLocal8Bit().data(), observer->password().toLocal8Bit().data()); 0083 // git_credential_username_new(out, observer->username().toLocal8Bit().data()); 0084 return 0; 0085 } 0086 0087 int git_helper_packbuilder_progress(int stage, uint32_t current, uint32_t total, void *payload) 0088 { 0089 return 0; 0090 } 0091 0092 int git_helper_transport_cb(git_transport **out, git_remote *owner, void *param) 0093 { 0094 return 0; 0095 } 0096 0097 } 0098 0099 FetchObserver::FetchObserver(QObject *parent) 0100 : QObject{parent} 0101 { 0102 } 0103 0104 unsigned int FetchObserver::totalObjects() const 0105 { 0106 return mTotalObjects; 0107 } 0108 0109 void FetchObserver::setTotalObjects(unsigned int totalObjects) 0110 { 0111 if (mTotalObjects == totalObjects) 0112 return; 0113 mTotalObjects = totalObjects; 0114 emit totalObjectsChanged(totalObjects); 0115 } 0116 0117 unsigned int FetchObserver::indexedObjects() const 0118 { 0119 return mIndexedObjects; 0120 } 0121 0122 void FetchObserver::setIndexedObjects(unsigned int indexedObjects) 0123 { 0124 if (mIndexedObjects == indexedObjects) 0125 return; 0126 mIndexedObjects = indexedObjects; 0127 emit indexedObjectsChanged(); 0128 } 0129 0130 unsigned int FetchObserver::receivedObjects() const 0131 { 0132 return mReceivedObjects; 0133 } 0134 0135 void FetchObserver::setReceivedObjects(unsigned int receivedObjects) 0136 { 0137 if (mReceivedObjects == receivedObjects) 0138 return; 0139 mReceivedObjects = receivedObjects; 0140 emit receivedObjectsChanged(receivedObjects); 0141 } 0142 0143 unsigned int FetchObserver::localObjects() const 0144 { 0145 return mLocalObjects; 0146 } 0147 0148 void FetchObserver::setLocalObjects(unsigned int localObjects) 0149 { 0150 if (mLocalObjects == localObjects) 0151 return; 0152 mLocalObjects = localObjects; 0153 emit localObjectsChanged(); 0154 } 0155 0156 unsigned int FetchObserver::totalDeltas() const 0157 { 0158 return mTotalDeltas; 0159 } 0160 0161 void FetchObserver::setTotalDeltas(unsigned int totalDeltas) 0162 { 0163 if (mTotalDeltas == totalDeltas) 0164 return; 0165 mTotalDeltas = totalDeltas; 0166 emit totalDeltasChanged(); 0167 } 0168 0169 unsigned int FetchObserver::indexedDeltas() const 0170 { 0171 return mIndexedDeltas; 0172 } 0173 0174 void FetchObserver::setIndexedDeltas(unsigned int indexedDeltas) 0175 { 0176 if (mIndexedDeltas == indexedDeltas) 0177 return; 0178 mIndexedDeltas = indexedDeltas; 0179 emit indexedDeltasChanged(); 0180 } 0181 0182 void FetchObserver::setCredential(const QString &username, const QString &password) 0183 { 0184 mUsername = username; 0185 mPassword = password; 0186 } 0187 0188 QString FetchObserver::username() const 0189 { 0190 return mUsername; 0191 } 0192 0193 QString FetchObserver::password() const 0194 { 0195 return mPassword; 0196 } 0197 0198 QString Credential::username() const 0199 { 0200 return mUsername; 0201 } 0202 0203 void Credential::setUsername(const QString &username) 0204 { 0205 mUsername = username; 0206 } 0207 0208 QString Credential::password() const 0209 { 0210 return mPassword; 0211 } 0212 0213 void Credential::setPassword(const QString &password) 0214 { 0215 mPassword = password; 0216 } 0217 0218 Credential::AllowedTypes Credential::allowedTypes() const 0219 { 0220 return mAllowedTypes; 0221 } 0222 0223 void Credential::setAllowedTypes(const AllowedTypes &allowedTypes) 0224 { 0225 mAllowedTypes = allowedTypes; 0226 } 0227 }