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

0001 /******************************************************************************
0002  * This file is part of the libqgit2 library
0003  * Copyright (c) 2011 Laszlo Papp <djszapi@archlinux.us>
0004  * Copyright (C) 2013 Leonardo Giordani
0005  *
0006  * This library is free software; you can redistribute it and/or
0007  * modify it under the terms of the GNU Lesser General Public
0008  * License as published by the Free Software Foundation; either
0009  * version 2.1 of the License, or (at your option) any later version.
0010  *
0011  * This library is distributed in the hope that it will be useful,
0012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0014  * Lesser General Public License for more details.
0015  *
0016  * You should have received a copy of the GNU Lesser General Public
0017  * License along with this library; if not, write to the Free Software
0018  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
0019  */
0020 
0021 #include "qgitref.h"
0022 
0023 #include "qgitoid.h"
0024 #include "qgitrepository.h"
0025 #include "qgitexception.h"
0026 #include "private/pathcodec.h"
0027 
0028 namespace LibQGit2
0029 {
0030 
0031 Reference::Reference(git_reference *ref)
0032     : d(ref, git_reference_free)
0033 {
0034 }
0035 
0036 Reference::Reference(const Reference& other)
0037     : d(other.d)
0038 {
0039 }
0040 
0041 Reference::~Reference()
0042 {
0043 }
0044 
0045 OId Reference::target() const
0046 {
0047     return OId(git_reference_target(d.data()));
0048 }
0049 
0050 QString Reference::symbolicTarget() const
0051 {
0052     return QString::fromUtf8(git_reference_symbolic_target(d.data()));
0053 }
0054 
0055 bool Reference::isDirect() const
0056 {
0057     return git_reference_type(d.data()) == GIT_REF_OID;
0058 }
0059 
0060 bool Reference::isSymbolic() const
0061 {
0062     return git_reference_type(d.data()) == GIT_REF_SYMBOLIC;
0063 }
0064 
0065 QString Reference::name() const
0066 {
0067     return QString::fromUtf8(git_reference_name(d.data()));
0068 }
0069 
0070 Reference Reference::resolve() const
0071 {
0072     git_reference *ref;
0073     qGitThrow(git_reference_resolve(&ref, d.data()));
0074     return Reference(ref);
0075 }
0076 
0077 Repository Reference::owner() const
0078 {
0079     return Repository(git_reference_owner(d.data()));
0080 }
0081 
0082 void Reference::setSymbolicTarget(const QString& target, const QString &message)
0083 {
0084     git_reference* rp;
0085     qGitThrow(git_reference_symbolic_set_target(&rp, data(), PathCodec::toLibGit2(target), message.toUtf8()));
0086     d = ptr_type(rp, git_reference_free);
0087 }
0088 
0089 void Reference::setTarget(const OId& oid, const QString &message)
0090 {
0091     git_reference* rp;
0092     qGitThrow(git_reference_set_target(&rp, data(), oid.constData(), message.toUtf8()));
0093     d = ptr_type(rp, git_reference_free);
0094 }
0095 
0096 bool Reference::isNull() const
0097 {
0098     return data() == 0;
0099 }
0100 
0101 git_reference* Reference::data() const
0102 {
0103     return d.data();
0104 }
0105 
0106 const git_reference* Reference::constData() const
0107 {
0108     return d.data();
0109 }
0110 
0111 } // namespace LibQGit2