File indexing completed on 2024-04-21 05:40:58
0001 /* 0002 SPDX-FileCopyrightText: 2010 Sebastian Doerner <sebastian@sebastian-doerner.de> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef GITWRAPPER_H 0008 #define GITWRAPPER_H 0009 0010 #include <QProcess> 0011 #include <QStringList> 0012 #include <QSet> 0013 0014 class QTextCodec; 0015 0016 /** 0017 * @brief A git wrapper class to access git functions conveniently using a Singleton interface. 0018 */ 0019 class GitWrapper 0020 { 0021 private: 0022 GitWrapper(); 0023 static GitWrapper* m_instance; 0024 ///size of the line buffers when parsing git output 0025 static const int BUFFER_SIZE; 0026 ///size of the line buffers when parsing shorter git output 0027 static const int SMALL_BUFFER_SIZE; 0028 QProcess m_process; 0029 QTextCodec * m_localCodec; 0030 /** 0031 * Gets a list of all remote hosts, whose entry ends with \a lineEnd 0032 * @param lineEnd The end of the lines, which should be returned as entries. 0033 * Should be "(pull)" or "(push)". 0034 */ 0035 QStringList remotes(QLatin1String lineEnd); 0036 public: 0037 static GitWrapper* instance(); 0038 static void freeInstance(); 0039 void setWorkingDirectory(const QString& workingDirectory) { 0040 m_process.setWorkingDirectory(workingDirectory); 0041 } 0042 0043 /** 0044 * @returns The configured user.name of the repository, 0045 the empty String (which is NOT null) if not configured. 0046 */ 0047 QString userName(); 0048 /** 0049 * @returns The configured user.email of the repository, 0050 the empty String (which is NOT null) if not configured. 0051 */ 0052 QString userEmail(); 0053 /** 0054 * Gets a list of all branches in the repository. 0055 * @param currentBranchIndex 0056 * Pointer to the location in which to store the index of the current branch 0057 * within the returned QStringList. Set to -1 if currently not on any branch. 0058 * @returns A StringList containing the names of all local and remote branches. 0059 */ 0060 QStringList branches(int * currentBranchIndex = nullptr); 0061 0062 /** 0063 * Gets a list of all tags in the repository. 0064 * @returns A list containing the tag names 0065 */ 0066 QStringList tags(); 0067 /** 0068 * Gets a set of all tags in the repository. 0069 * @param result Set to store the results in. 0070 */ 0071 void tagSet(QSet<QString>& result); 0072 0073 /** 0074 * Gets a list of all remote hosts we can pull from. 0075 * @returns The list containing the remote hosts. 0076 */ 0077 QStringList pullRemotes(); 0078 0079 /** 0080 * Gets a list of all remote hosts we can push to. 0081 * @returns The list containing the remote hosts. 0082 */ 0083 QStringList pushRemotes(); 0084 0085 /** 0086 * @returns The last commit message. Null-String if there is no last commit. 0087 */ 0088 QString lastCommitMessage(); 0089 }; 0090 0091 #endif // GITWRAPPER_H