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 "qgitrebase.h"
0020 #include "qgitoid.h"
0021 #include "qgitexception.h"
0022 
0023 namespace LibQGit2
0024 {
0025 
0026 struct Rebase::Private {
0027     Private(git_rebase *rebase)
0028         : mRebase(rebase, git_rebase_free)
0029     {
0030     }
0031 
0032     void abort()
0033     {
0034         qGitThrow(git_rebase_abort(data()));
0035     }
0036 
0037     OId commit(const Signature &committer, const Signature &author, const QString &message)
0038     {
0039         git_oid oid;
0040         qGitThrow(git_rebase_commit(&oid, data(), author.data(), committer.data(), NULL, message.isNull() ? NULL : message.toUtf8().constData()));
0041         return OId(&oid);
0042     }
0043 
0044     void finish(const Signature &signature)
0045     {
0046         qGitThrow(git_rebase_finish(data(), signature.data()));
0047     }
0048 
0049     bool next()
0050     {
0051         git_rebase_operation *op;
0052         int error = git_rebase_next(&op, data());
0053         if (error == GIT_ITEROVER) {
0054             return false;
0055         } else {
0056             qGitThrow(error);
0057             return true;
0058         }
0059     }
0060 
0061     git_rebase *data() const
0062     {
0063         return mRebase.data();
0064     }
0065 
0066     const git_rebase *constData() const
0067     {
0068         return mRebase.data();
0069     }
0070 
0071 private:
0072     QSharedPointer<git_rebase> mRebase;
0073 };
0074 
0075 Rebase::Rebase(git_rebase *rebase)
0076     : d_ptr(new Private(rebase))
0077 {
0078 }
0079 
0080 void Rebase::abort()
0081 {
0082     return d_ptr->abort();
0083 }
0084 
0085 OId Rebase::commit(const Signature &committer, const Signature &author, const QString &message)
0086 {
0087     return d_ptr->commit(committer, author, message);
0088 }
0089 
0090 void Rebase::finish(const Signature &signature)
0091 {
0092     d_ptr->finish(signature);
0093 }
0094 
0095 bool Rebase::next()
0096 {
0097     return d_ptr->next();
0098 }
0099 
0100 git_rebase *Rebase::data() const
0101 {
0102     return d_ptr->data();
0103 }
0104 
0105 git_rebase *Rebase::constData() const
0106 {
0107     return d_ptr->data();
0108 }
0109 }