File indexing completed on 2024-04-28 16:01:31

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 "qgitcheckoutoptions.h"
0020 #include "private/pathcodec.h"
0021 #include "private/strarray.h"
0022 
0023 namespace LibQGit2
0024 {
0025 
0026 class CheckoutOptions::Private
0027 {
0028 public:
0029     Private(Strategy strategy, Flags flags)
0030     {
0031         git_checkout_options temp = GIT_CHECKOUT_OPTIONS_INIT;
0032         native = temp;
0033 
0034         switch (strategy) {
0035         case Safe:
0036             native.checkout_strategy |= GIT_CHECKOUT_SAFE;
0037             break;
0038         case Force:
0039             native.checkout_strategy |= GIT_CHECKOUT_FORCE;
0040             break;
0041         default:
0042             break;
0043         }
0044 
0045         if (flags.testFlag(AllowConflicts)) {
0046             native.checkout_strategy |= GIT_CHECKOUT_ALLOW_CONFLICTS;
0047         }
0048         if (flags.testFlag(RemoveUntracked)) {
0049             native.checkout_strategy |= GIT_CHECKOUT_REMOVE_UNTRACKED;
0050         }
0051         if (flags.testFlag(RemoveIgnored)) {
0052             native.checkout_strategy |= GIT_CHECKOUT_REMOVE_IGNORED;
0053         }
0054         if (flags.testFlag(UpdateOnly)) {
0055             native.checkout_strategy |= GIT_CHECKOUT_UPDATE_ONLY;
0056         }
0057         if (flags.testFlag(DontUpdateIndex)) {
0058             native.checkout_strategy |= GIT_CHECKOUT_DONT_UPDATE_INDEX;
0059         }
0060         if (flags.testFlag(NoRefresh)) {
0061             native.checkout_strategy |= GIT_CHECKOUT_NO_REFRESH;
0062         }
0063         if (flags.testFlag(SkipUnmerged)) {
0064             native.checkout_strategy |= GIT_CHECKOUT_SKIP_UNMERGED;
0065         }
0066         if (flags.testFlag(UnmergedUseOurs)) {
0067             native.checkout_strategy |= GIT_CHECKOUT_USE_OURS;
0068         }
0069         if (flags.testFlag(UnmergedUseTheirs)) {
0070             native.checkout_strategy |= GIT_CHECKOUT_USE_THEIRS;
0071         }
0072         if (flags.testFlag(RecreateMissing)) {
0073             native.checkout_strategy |= GIT_CHECKOUT_RECREATE_MISSING;
0074         }
0075     }
0076 
0077     void setTargetDirectory(const QString &dir)
0078     {
0079         m_target_directory = PathCodec::toLibGit2(dir);
0080         native.target_directory = m_target_directory.constData();
0081     }
0082 
0083     void setPaths(const QList<QString> &paths)
0084     {
0085         QList<QByteArray> pathByteArrays;
0086         pathByteArrays.reserve(paths.size());
0087         foreach (const QString &path, paths) {
0088             pathByteArrays.append(PathCodec::toLibGit2(path));
0089         }
0090         m_paths = internal::StrArray(pathByteArrays);
0091 
0092         native.paths = m_paths.data();
0093     }
0094 
0095     git_checkout_options native;
0096     QByteArray m_target_directory;
0097     internal::StrArray m_paths;
0098 };
0099 
0100 
0101 CheckoutOptions::CheckoutOptions(Strategy strategy, Flags flags)
0102     : d_ptr(new Private(strategy, flags))
0103 {
0104 }
0105 
0106 const git_checkout_options* CheckoutOptions::data() const
0107 {
0108     return &d_ptr->native;
0109 }
0110 
0111 void CheckoutOptions::setTargetDirectory(const QString &dir)
0112 {
0113     d_ptr->setTargetDirectory(dir);
0114 }
0115 
0116 void CheckoutOptions::setPaths(const QList<QString> &paths)
0117 {
0118     d_ptr->setPaths(paths);
0119 }
0120 
0121 }