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 #ifndef LIBQGIT2_REF_H 0022 #define LIBQGIT2_REF_H 0023 0024 #include <QtCore/QSharedPointer> 0025 #include <QtCore/QString> 0026 0027 #include "git2.h" 0028 0029 #include "libqgit2_export.h" 0030 0031 namespace LibQGit2 0032 { 0033 class Repository; 0034 class OId; 0035 0036 /** 0037 * @brief Wrapper class for git_refs. 0038 * Represents a Git reference. Reference objects are branches, tags, etc. 0039 * 0040 * @ingroup LibQGit2 0041 * @{ 0042 */ 0043 class LIBQGIT2_EXPORT Reference 0044 { 0045 public: 0046 0047 /** 0048 * Create an new ref object 0049 */ 0050 explicit Reference(git_reference *ref = 0); 0051 0052 /** 0053 * Copy constructor 0054 */ 0055 Reference(const Reference& other); 0056 0057 /** 0058 * Free an existing reference object. 0059 */ 0060 ~Reference(); 0061 0062 public: 0063 0064 /** 0065 * Get the OID pointed to by a reference. 0066 * 0067 * Only available if the reference is direct (i.e. not symbolic) 0068 * 0069 * @return a pointer to the oid if available, NULL otherwise 0070 */ 0071 OId target() const; 0072 0073 /** 0074 * Get full name to the reference pointed by this reference 0075 * 0076 * Only available if the reference is symbolic 0077 * 0078 * @return a pointer to the name if available, NULL otherwise 0079 */ 0080 QString symbolicTarget() const; 0081 0082 /** 0083 * Return true if the reference is direct (i.e. a reference to an OID) 0084 */ 0085 bool isDirect() const; 0086 0087 /** 0088 * Return true if the reference is symbolig (i.e. a reference to another ref) 0089 */ 0090 bool isSymbolic() const; 0091 0092 /** 0093 * Get the full name of a reference 0094 * 0095 * @return the full name for the ref 0096 */ 0097 QString name() const; 0098 0099 /** 0100 * Resolve a symbolic reference 0101 * 0102 * Thie method iteratively peels a symbolic reference 0103 * until it resolves to a direct reference to an OID. 0104 * 0105 * If a direct reference is passed as an argument, 0106 * that reference is returned immediately 0107 * 0108 * @param resolvedRef Pointer to the peeled reference 0109 * @return 0 on success; error code otherwise 0110 * @throws LibQGit2::Exception 0111 */ 0112 Reference resolve() const; 0113 0114 /** 0115 * Get the repository where a reference resides 0116 * 0117 * @return a pointer to the repository 0118 */ 0119 Repository owner() const; 0120 0121 /** 0122 * Set the name of a reference. 0123 * 0124 * This marks the reference as modified; changes 0125 * won't take effect until it is manually written back 0126 * to disk. 0127 * 0128 * @param name The new name for the reference 0129 */ 0130 void setName(const QString& name); 0131 0132 /** 0133 * Set the target reference of a reference. 0134 * 0135 * This converts the reference into a symbolic 0136 * reference. 0137 * 0138 * This marks the reference as modified; changes 0139 * won't take effect until it is manually written back 0140 * to disk. 0141 * 0142 * @param target The new target for the reference 0143 * @param message The one line long message to be appended to the reflog 0144 * @throws LibQGit2::Exception 0145 */ 0146 void setSymbolicTarget(const QString& target, const QString &message = QString()); 0147 0148 /** 0149 * Set the OID target of a reference. 0150 * 0151 * This converts the reference into a direct 0152 * reference. 0153 * 0154 * This marks the reference as modified; changes 0155 * won't take effect until it is manually written back 0156 * to disk. 0157 * 0158 * @param target The new target OID for the reference 0159 * @param message The one line long message to be appended to the reflog 0160 * @throws LibQGit2::Exception 0161 */ 0162 void setTarget(const OId& oid, const QString &message = QString()); 0163 0164 bool isNull() const; 0165 0166 git_reference* data() const; 0167 const git_reference* constData() const; 0168 0169 private: 0170 typedef QSharedPointer<git_reference> ptr_type; 0171 ptr_type d; 0172 }; 0173 0174 /**@}*/ 0175 } 0176 0177 #endif // LIBQGIT2_REF_H