File indexing completed on 2024-04-28 16:01:31
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 "qgitcommit.h" 0022 0023 #include "qgitrepository.h" 0024 #include "qgitsignature.h" 0025 #include "qgittree.h" 0026 #include "qgitexception.h" 0027 0028 #include "private/pathcodec.h" 0029 0030 namespace LibQGit2 0031 { 0032 0033 Commit::Commit(git_commit *commit) 0034 : Object(reinterpret_cast<git_object*>(commit)) 0035 { 0036 } 0037 0038 Commit::Commit(const Commit& other) 0039 : Object(other) 0040 { 0041 } 0042 0043 Commit::~Commit() 0044 { 0045 } 0046 0047 OId Commit::oid() const 0048 { 0049 return OId(git_commit_id(data())); 0050 } 0051 0052 QString Commit::message() const 0053 { 0054 return QString::fromUtf8(git_commit_message(data())); 0055 } 0056 0057 QString Commit::shortMessage(int maxLen) const 0058 { 0059 return message().left(maxLen).split(QRegExp("(\\r|\\n)")).first(); 0060 } 0061 0062 QDateTime Commit::dateTime() const 0063 { 0064 QDateTime dateTime; 0065 dateTime.setTime_t(git_commit_time(data())); 0066 return dateTime; 0067 } 0068 0069 int Commit::timeOffset() const 0070 { 0071 return git_commit_time_offset(data()); 0072 } 0073 0074 Signature Commit::committer() const 0075 { 0076 return Signature(git_commit_committer(data())); 0077 } 0078 0079 Signature Commit::author() const 0080 { 0081 return Signature(git_commit_author(data())); 0082 } 0083 0084 Tree Commit::tree() const 0085 { 0086 git_tree *tree; 0087 qGitThrow(git_commit_tree(&tree, data())); 0088 return Tree(tree); 0089 } 0090 0091 unsigned int Commit::parentCount() const 0092 { 0093 return git_commit_parentcount(data()); 0094 } 0095 0096 Commit Commit::parent(unsigned n) const 0097 { 0098 git_commit *parent; 0099 qGitThrow(git_commit_parent(&parent, data(), n)); 0100 return Commit(parent); 0101 } 0102 0103 OId Commit::parentId(unsigned n) const 0104 { 0105 return OId(git_commit_parent_id(data(), n)); 0106 } 0107 0108 OId Commit::amend(const Tree& tree, const QString& ref, const QString& message, const Signature& author, const Signature& committer) 0109 { 0110 OId oid; 0111 qGitThrow(git_commit_amend(oid.data(), constData(), ref.isEmpty() ? NULL : PathCodec::toLibGit2(ref).constData(), author.data(), committer.data(), 0112 NULL, message.isNull() ? NULL : message.toUtf8().constData(), tree.constData())); 0113 return oid; 0114 } 0115 0116 0117 git_commit* Commit::data() const 0118 { 0119 return reinterpret_cast<git_commit*>(Object::data()); 0120 } 0121 0122 const git_commit* Commit::constData() const 0123 { 0124 return reinterpret_cast<git_commit*>(Object::data()); 0125 } 0126 0127 } // namespace LibQGit2