1 | #pragma once |
2 | |
3 | #include <QByteArray> |
4 | #include <QStringList> |
5 | #include <QVector> |
6 | |
7 | class RevisionFiles |
8 | { |
9 | public: |
10 | enum StatusFlag |
11 | { |
12 | MODIFIED = 1, |
13 | DELETED = 2, |
14 | NEW = 4, |
15 | RENAMED = 8, |
16 | COPIED = 16, |
17 | UNKNOWN = 32, |
18 | IN_INDEX = 64, |
19 | CONFLICT = 128, |
20 | PARTIALLY_CACHED = 256 |
21 | }; |
22 | |
23 | RevisionFiles() = default; |
24 | ~RevisionFiles(); |
25 | RevisionFiles(const QString &diff, bool cached = false); |
26 | |
27 | bool isValid() const; |
28 | bool operator==(const RevisionFiles &revFiles) const; |
29 | bool operator!=(const RevisionFiles &revFiles) const; |
30 | |
31 | QVector<int> mergeParent; |
32 | QVector<QString> mFiles; |
33 | |
34 | // helper functions |
35 | int count() const { return mFiles.count(); } |
36 | bool statusCmp(int idx, StatusFlag sf) const; |
37 | const QString extendedStatus(int idx) const; |
38 | void setStatus(const QString &rowSt, bool isStaged = false); |
39 | void setStatus(RevisionFiles::StatusFlag flag); |
40 | void setStatus(int pos, RevisionFiles::StatusFlag flag); |
41 | void appendStatus(int pos, RevisionFiles::StatusFlag flag); |
42 | int getStatus(int pos) const { return mFileStatus.at(pos); } |
43 | void setOnlyModified(bool onlyModified) { mOnlyModified = onlyModified; } |
44 | int getFilesCount() const { return mFileStatus.size(); } |
45 | void appendExtStatus(const QString &file) { mRenamedFiles.append(file); } |
46 | QString getFile(int index) const { return mFiles.at(index); } |
47 | QStringList getFiles() const { return mFiles.toList(); } |
48 | bool containsFile(const QString &fileName) { return mFiles.contains(fileName); } |
49 | |
50 | private: |
51 | // Status information is split in a flags vector and in a string |
52 | // vector in 'status' are stored flags according to the info returned |
53 | // by 'git diff-tree' without -C option. |
54 | // In case of a working directory file an IN_INDEX flag is or-ed together in |
55 | // case file is present in git index. |
56 | // If file is renamed or copied an entry in 'extStatus' stores the |
57 | // value returned by 'git diff-tree -C' plus source and destination |
58 | // files info. |
59 | // When status of all the files is 'modified' then onlyModified is |
60 | // set, this let us to do some optimization in this common case |
61 | bool mOnlyModified = true; |
62 | QVector<int> mFileStatus; |
63 | QVector<QString> mRenamedFiles; |
64 | |
65 | void setExtStatus(const QString &rowSt, int parNum); |
66 | }; |
67 | |