File indexing completed on 2024-04-28 16:01:32
0001 /****************************************************************************** 0002 * This file is part of the libqgit2 library 0003 * 0004 * This library is free software; you can redistribute it and/or 0005 * modify it under the terms of the GNU Lesser General Public 0006 * License as published by the Free Software Foundation; either 0007 * version 2.1 of the License, or (at your option) any later version. 0008 * 0009 * This library is distributed in the hope that it will be useful, 0010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0012 * Lesser General Public License for more details. 0013 * 0014 * You should have received a copy of the GNU Lesser General Public 0015 * License along with this library; if not, write to the Free Software 0016 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 0017 */ 0018 0019 #include "qgitremote.h" 0020 #include "qgitexception.h" 0021 #include "private/remotecallbacks.h" 0022 #include "private/strarray.h" 0023 0024 0025 namespace LibQGit2 { 0026 0027 struct Remote::Private : public internal::RemoteListener 0028 { 0029 Private(Remote &parent, git_remote *remote, const Credentials &credentials) : 0030 m_data(remote, git_remote_free), 0031 m_parent(parent), 0032 m_callbacks(this, credentials) 0033 { 0034 } 0035 0036 int progress(int transferProgress) 0037 { 0038 emit m_parent.transferProgress(transferProgress); 0039 return 0; 0040 } 0041 0042 void push(const QList<QString> &refSpecs) 0043 { 0044 QList<QByteArray> baRefSpecs; 0045 foreach (const QString &ref, refSpecs) { 0046 baRefSpecs.append(ref.toLatin1()); 0047 } 0048 internal::StrArray refspecs(baRefSpecs); 0049 0050 git_push_options opts = GIT_PUSH_OPTIONS_INIT; 0051 opts.callbacks = m_callbacks.rawCallbacks(); 0052 qGitThrow(git_remote_push(m_data.data(), &refspecs.data(), &opts)); 0053 } 0054 0055 QSharedPointer<git_remote> m_data; 0056 0057 private: 0058 Remote &m_parent; 0059 internal::RemoteCallbacks m_callbacks; 0060 }; 0061 0062 0063 Remote::Remote(git_remote *remote, const Credentials &credentials, QObject *parent) : 0064 QObject(parent), 0065 d_ptr(new Private(*this, remote, credentials)) 0066 { 0067 } 0068 0069 QString Remote::url() const 0070 { 0071 return QString::fromLatin1(git_remote_url(data())); 0072 } 0073 0074 void Remote::push(const QList<QString> &refSpecs) 0075 { 0076 d_ptr->push(refSpecs); 0077 } 0078 0079 git_remote* Remote::data() const 0080 { 0081 return d_ptr->m_data.data(); 0082 } 0083 0084 }