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 "qgitindex.h" 0022 #include "qgitindexentry.h" 0023 #include "qgittree.h" 0024 #include "qgitexception.h" 0025 0026 #include "qgitrepository.h" 0027 0028 #include "private/pathcodec.h" 0029 0030 namespace LibQGit2 0031 { 0032 0033 Index::Index(git_index *index) 0034 : d(index, git_index_free) 0035 { 0036 } 0037 0038 Index::Index(const Index& other) 0039 : d(other.d) 0040 { 0041 } 0042 0043 Index::~Index() 0044 { 0045 } 0046 0047 void Index::open(const QString& indexPath) 0048 { 0049 d.clear(); 0050 git_index *index = 0; 0051 qGitThrow(git_index_open(&index, PathCodec::toLibGit2(indexPath))); 0052 d = ptr_type(index, git_index_free); 0053 } 0054 0055 OId Index::createTree() 0056 { 0057 OId oid; 0058 qGitThrow(git_index_write_tree(oid.data(), data())); 0059 return oid; 0060 } 0061 0062 void Index::clear() 0063 { 0064 qGitThrow(git_index_clear(data())); 0065 } 0066 0067 void Index::read(bool force) const 0068 { 0069 qGitThrow(git_index_read(data(), force ? 1 : 0)); 0070 } 0071 0072 void Index::write() 0073 { 0074 qGitThrow(git_index_write(data())); 0075 } 0076 0077 int Index::find(const QString& path) 0078 { 0079 return git_index_find(NULL, data(), PathCodec::toLibGit2(path)); 0080 } 0081 0082 void Index::addByPath(const QString& path) 0083 { 0084 qGitThrow(git_index_add_bypath(data(), PathCodec::toLibGit2(path))); 0085 } 0086 0087 void Index::remove(const QString& path, int stage) 0088 { 0089 qGitThrow(git_index_remove(data(), PathCodec::toLibGit2(path), stage)); 0090 } 0091 0092 void Index::add(const IndexEntry &source_entry) 0093 { 0094 qGitThrow(git_index_add(data(), source_entry.data())); 0095 } 0096 0097 void Index::updateAll() 0098 { 0099 qGitThrow(git_index_update_all(data(), NULL, NULL, NULL)); 0100 } 0101 0102 IndexEntry Index::getByIndex(int n) const 0103 { 0104 return IndexEntry(git_index_get_byindex(data(), n)); 0105 } 0106 0107 unsigned int Index::entryCount() const 0108 { 0109 return git_index_entrycount(data()); 0110 } 0111 0112 bool Index::hasConflicts() const 0113 { 0114 return !d.isNull() && git_index_has_conflicts(d.data()); 0115 } 0116 0117 git_index* Index::data() const 0118 { 0119 return d.data(); 0120 } 0121 0122 const git_index* Index::constData() const 0123 { 0124 return d.data(); 0125 } 0126 0127 } // namespace LibQGit2