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 #ifndef LIBQGIT2_COMMIT_H
0022 #define LIBQGIT2_COMMIT_H
0023 
0024 #include "qgitobject.h"
0025 #include "qgittree.h"
0026 #include "qgitsignature.h"
0027 
0028 #include <QtCore/QDateTime>
0029 
0030 namespace LibQGit2
0031 {
0032     class OId;
0033     class Repository;
0034 
0035     /**
0036      * @brief Wrapper class for git_commit.
0037      *
0038      * This class represents a Git commit object.
0039      *
0040      * @ingroup LibQGit2
0041      * @{
0042      */
0043     class LIBQGIT2_EXPORT Commit : public Object
0044     {
0045         public:
0046 
0047             /**
0048              * Creates a Commit that points to commit. The pointer object becomes managed by
0049              * this Commit, and must not be passed to another Commit or closed outside this
0050              * object.
0051              */
0052             explicit Commit(git_commit *commit = 0);
0053 
0054             /**
0055              * Copy constructor; creates a copy of the object, sharing the same underlaying data
0056              * structure.
0057              */
0058             Commit(const Commit& other);
0059 
0060             /**
0061              * Destroys the object.
0062              */
0063             ~Commit();
0064 
0065             /**
0066             * Get the id of a commit.
0067             */
0068             OId oid() const;
0069 
0070             /**
0071              * Get the full message of a commit.
0072              */
0073             QString message() const;
0074 
0075             /**
0076              * Get the short commit message.
0077              *
0078              * Get the first part of the commit message (similar to
0079              * git log --oneline). The string is further cut when a
0080              * linebreak is found.
0081              *
0082              * @param maxLen maximal length of the resulting string.
0083              * Default is 80 characters.
0084              *
0085              * @return the short message
0086              */
0087             QString shortMessage(int maxLen = 80) const;
0088 
0089             /**
0090              * Get the commit time (i.e. committer time) of this commit.
0091              */
0092             QDateTime dateTime() const;
0093 
0094             /**
0095              * Get the timezone offset.
0096              *
0097              * Get the timezone offset (i.e. committer's preferred timezone)
0098              * of this commit.
0099              *
0100              * @return positive or negative timezone offset, in minutes from UTC
0101              */
0102             int timeOffset() const;
0103 
0104             /**
0105              * Get the committer signature of this commit.
0106              */
0107             Signature committer() const;
0108 
0109             /**
0110              * Get the author signature of this commit.
0111              */
0112             Signature author() const;
0113 
0114             /**
0115              * Get the tree pointed to by this commit.
0116              *
0117              * @throws Exception
0118              */
0119             Tree tree() const;
0120 
0121             /**
0122              * Get the number of parents of this commit
0123              */
0124             unsigned int parentCount() const;
0125 
0126             /**
0127              * Get the specified parent of the commit.
0128              *
0129              * This method returns the nth parent of this commit or, if no
0130              * parent can be found, an empty commit.
0131              *
0132              * @param n the position of the parent
0133              * @return the parent commit or an empty commit
0134              * @throws Exception
0135              */
0136             Commit parent(unsigned n) const;
0137 
0138             /**
0139              * Get the OId of the specified parent of the commit.
0140              *
0141              * This method returns the Oid of the nth parent of this commit or,
0142              * if no parent can be found, an empty OId.
0143              *
0144              * @param n the position of the parent
0145              * @return the OId of the parent commit or an empty OId
0146              * @throws Exception
0147              */
0148             OId parentId(unsigned n) const;
0149 
0150             /**
0151              * Amends an existing commit.
0152              *
0153              * Only the arguments that are provided are used. Arguments left to their default values
0154              * mean that the property in the Commit is not changed.
0155              *
0156              * @param tree The Tree to be used to amend the Commit.
0157              * @param ref Name of the reference that will be updated to point to the amended Commit.
0158              *        See Repository::createCommit.
0159              * @param message The message for the amended Commit.
0160              * @param author Author signature.
0161              * @param committer Committer signature.
0162              * @return The OId of the amended Commit.
0163              *
0164              * @see Repository::createCommit
0165              */
0166             OId amend(const Tree& tree = Tree(), const QString& ref = QString(), const QString& message = QString(), const Signature& author = Signature(), const Signature& committer = Signature());
0167 
0168             git_commit* data() const;
0169             const git_commit* constData() const;
0170     };
0171 
0172     /**@}*/
0173 }
0174 
0175 #endif // LIBQGIT2_COMMIT_H