1 | #pragma once |
2 | |
3 | /**************************************************************************************** |
4 | ** GitQlient is an application to manage and operate one or several Git repositories. With |
5 | ** GitQlient you will be able to add commits, branches and manage all the options Git provides. |
6 | ** Copyright (C) 2021 Francesc Martinez |
7 | ** |
8 | ** LinkedIn: www.linkedin.com/in/cescmm/ |
9 | ** Web: www.francescmm.com |
10 | ** |
11 | ** This program is free software; you can redistribute it and/or |
12 | ** modify it under the terms of the GNU Lesser General Public |
13 | ** License as published by the Free Software Foundation; either |
14 | ** version 2 of the License, or (at your option) any later version. |
15 | ** |
16 | ** This program is distributed in the hope that it will be useful, |
17 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of |
18 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
19 | ** Lesser General Public License for more details. |
20 | ** |
21 | ** You should have received a copy of the GNU Lesser General Public |
22 | ** License along with this library; if not, write to the Free Software |
23 | ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
24 | ***************************************************************************************/ |
25 | |
26 | #include <QDateTime> |
27 | #include <QStringList> |
28 | #include <QVector> |
29 | |
30 | #include <chrono> |
31 | |
32 | #include <Lane.h> |
33 | #include <References.h> |
34 | |
35 | class CommitInfo |
36 | { |
37 | public: |
38 | enum class Field |
39 | { |
40 | SHA, |
41 | PARENTS_SHA, |
42 | COMMITER, |
43 | AUTHOR, |
44 | DATE, |
45 | SHORT_LOG, |
46 | LONG_LOG |
47 | }; |
48 | |
49 | CommitInfo() = default; |
50 | ~CommitInfo() = default; |
51 | CommitInfo(QByteArray commitData); |
52 | CommitInfo(QByteArray commitData, const QString &gpg, bool goodSignature); |
53 | explicit CommitInfo(const QString &sha, const QStringList &parents, std::chrono::seconds commitDate, |
54 | const QString &log); |
55 | bool operator==(const CommitInfo &commit) const; |
56 | bool operator!=(const CommitInfo &commit) const; |
57 | |
58 | bool isValid() const; |
59 | bool contains(const QString &value); |
60 | |
61 | int parentsCount() const; |
62 | QString firstParent() const; |
63 | QStringList parents() const; |
64 | bool isInWorkingBranch() const; |
65 | |
66 | void setLanes(QVector<Lane> lanes); |
67 | QVector<Lane> lanes() const { return mLanes; } |
68 | int lanesCount() const { return mLanes.count(); } |
69 | Lane laneAt(int i) const { return mLanes.at(i); } |
70 | int getActiveLane() const; |
71 | |
72 | void appendChild(CommitInfo *commit) { mChilds.append(commit); } |
73 | void removeChild(CommitInfo *commit); |
74 | bool hasChilds() const { return !mChilds.empty(); } |
75 | QString getFirstChildSha() const; |
76 | int getChildsCount() const { return mChilds.count(); } |
77 | |
78 | bool isSigned() const { return !gpgKey.isEmpty(); } |
79 | bool verifiedSignature() const { return mGoodSignature && !gpgKey.isEmpty(); } |
80 | |
81 | static const QString ZERO_SHA; |
82 | static const QString INIT_SHA; |
83 | |
84 | uint pos = 0; |
85 | QString sha; |
86 | QString committer; |
87 | QString author; |
88 | std::chrono::seconds dateSinceEpoch; |
89 | QString shortLog; |
90 | QString longLog; |
91 | QString gpgKey; |
92 | |
93 | private: |
94 | bool mGoodSignature = false; |
95 | QVector<Lane> mLanes; |
96 | QStringList mParentsSha; |
97 | QVector<CommitInfo *> mChilds; |
98 | |
99 | friend class GitCache; |
100 | |
101 | void parseDiff(QByteArray &data, int startingField); |
102 | }; |
103 | |