File indexing completed on 2024-04-28 16:01:34
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 "qgittreeentry.h" 0022 #include "qgitrepository.h" 0023 #include "qgitexception.h" 0024 0025 #include "private/pathcodec.h" 0026 0027 namespace LibQGit2 0028 { 0029 0030 TreeEntry::TreeEntry(const git_tree_entry* treeEntry) 0031 : d(treeEntry) 0032 { 0033 } 0034 0035 TreeEntry::TreeEntry(const TreeEntry& other) 0036 : d(other.d) 0037 { 0038 } 0039 0040 TreeEntry::~TreeEntry() 0041 { 0042 } 0043 0044 bool TreeEntry::isNull() const 0045 { 0046 return d == 0; 0047 } 0048 0049 unsigned int TreeEntry::attributes() const 0050 { 0051 return git_tree_entry_filemode(d); 0052 } 0053 0054 const QString TreeEntry::name() const 0055 { 0056 return PathCodec::fromLibGit2(git_tree_entry_name(d)); 0057 } 0058 0059 OId TreeEntry::oid() const 0060 { 0061 return OId(git_tree_entry_id(d)); 0062 } 0063 0064 Object::Type TreeEntry::type() const 0065 { 0066 if (isNull()) { 0067 throw Exception("TreeEntry::type(): unknown type since this tree entry is null."); 0068 } 0069 0070 return Object::resolveType(git_tree_entry_type(d)); 0071 } 0072 0073 Object TreeEntry::toObject(const Repository& repo) 0074 { 0075 git_object *obj; 0076 qGitThrow(git_tree_entry_to_object(&obj, repo.data(), d)); 0077 return Object(obj); 0078 } 0079 0080 const git_tree_entry* TreeEntry::data() const 0081 { 0082 return d; 0083 } 0084 0085 } // namespace LibQGit2