File indexing completed on 2024-04-28 16:01:33
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 <iostream> 0022 0023 #include "qgitrevwalk.h" 0024 #include "qgitcommit.h" 0025 #include "qgitref.h" 0026 #include "qgitexception.h" 0027 #include "qgitrepository.h" 0028 0029 0030 namespace LibQGit2 0031 { 0032 0033 RevWalk::RevWalk(const Repository& repository) 0034 { 0035 git_revwalk_new(&m_revWalk, repository.data()); 0036 m_repository = &repository; 0037 } 0038 0039 RevWalk::RevWalk( const RevWalk& other ) 0040 { 0041 m_revWalk = other.m_revWalk; 0042 } 0043 0044 RevWalk::~RevWalk() 0045 { 0046 git_revwalk_free(m_revWalk); 0047 } 0048 0049 void RevWalk::reset() const 0050 { 0051 git_revwalk_reset(m_revWalk); 0052 } 0053 0054 void RevWalk::push(const OId& oid) const 0055 { 0056 qGitThrow(git_revwalk_push(m_revWalk, oid.constData())); 0057 } 0058 0059 void RevWalk::push(const Commit& commit) const 0060 { 0061 qGitThrow(git_revwalk_push(m_revWalk, commit.oid().constData())); 0062 } 0063 0064 void RevWalk::push(const Reference& reference) const 0065 { 0066 qGitThrow(git_revwalk_push(m_revWalk, reference.target().constData())); 0067 } 0068 0069 void RevWalk::push(const QString& glob) const 0070 { 0071 qGitThrow(git_revwalk_push_glob(m_revWalk, glob.toUtf8().constData())); 0072 } 0073 0074 void RevWalk::pushHead() const 0075 { 0076 qGitThrow(git_revwalk_push_head(m_revWalk)); 0077 } 0078 0079 void RevWalk::pushRange(const QString& range) const 0080 { 0081 qGitThrow(git_revwalk_push_range(m_revWalk,range.toUtf8().constData())); 0082 } 0083 0084 void RevWalk::hide(const OId& oid) const 0085 { 0086 qGitThrow(git_revwalk_hide(m_revWalk, oid.constData())); 0087 } 0088 0089 void RevWalk::hide(const Commit& commit) const 0090 { 0091 qGitThrow(git_revwalk_hide(m_revWalk, commit.oid().constData())); 0092 } 0093 0094 void RevWalk::hide(const Reference& reference) const 0095 { 0096 qGitThrow(git_revwalk_hide_glob(m_revWalk, reference.name().toUtf8().data())); 0097 } 0098 0099 void RevWalk::hide(const QString& glob) const 0100 { 0101 qGitThrow(git_revwalk_hide_glob(m_revWalk, glob.toUtf8().data())); 0102 } 0103 0104 void RevWalk::hideHead() const 0105 { 0106 qGitThrow(git_revwalk_hide_head(m_revWalk)); 0107 } 0108 0109 bool RevWalk::next(OId& oid) const 0110 { 0111 int err = git_revwalk_next(oid.data(), m_revWalk); 0112 return (err == GIT_OK); 0113 } 0114 0115 bool RevWalk::next(Commit& commit) 0116 { 0117 OId oid; 0118 int err = git_revwalk_next(oid.data(), m_revWalk); 0119 0120 if ( (err != GIT_OK) || !oid.isValid() ) 0121 commit = Commit(); 0122 else 0123 commit = constRepository()->lookupCommit(oid); 0124 0125 return !commit.isNull(); 0126 } 0127 0128 void RevWalk::setSorting(SortModes sm) 0129 { 0130 git_revwalk_sorting(m_revWalk, sm); 0131 } 0132 0133 Repository* RevWalk::repository() 0134 { 0135 Repository* repo = new Repository(git_revwalk_repository(m_revWalk)); 0136 return repo; 0137 } 0138 0139 const Repository* RevWalk::constRepository() 0140 { 0141 return m_repository; 0142 } 0143 0144 git_revwalk* RevWalk::data() const 0145 { 0146 return m_revWalk; 0147 } 0148 0149 const git_revwalk* RevWalk::constData() const 0150 { 0151 return m_revWalk; 0152 } 0153 0154 } // namespace LibQGit2