commitdata.h 3.75 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
con's avatar
con committed
2
**
3
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
hjk's avatar
hjk committed
4
** Contact: http://www.qt-project.org/legal
con's avatar
con committed
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
con's avatar
con committed
7
**
hjk's avatar
hjk committed
8
9
10
11
12
13
14
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia.  For licensing terms and
** conditions see http://qt.digia.com/licensing.  For further information
** use the contact form at http://qt.digia.com/contact-us.
15
**
16
** GNU Lesser General Public License Usage
hjk's avatar
hjk committed
17
18
19
20
21
22
23
24
25
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights.  These rights are described in the Digia Qt LGPL Exception
con's avatar
con committed
26
27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
28
****************************************************************************/
hjk's avatar
hjk committed
29

con's avatar
con committed
30
31
32
#ifndef COMMITDATA_H
#define COMMITDATA_H

33
34
#include "gitsettings.h" // CommitType

35
36
#include <QStringList>
#include <QPair>
con's avatar
con committed
37
38
39
40
41
42
43
44

QT_BEGIN_NAMESPACE
class QDebug;
QT_END_NAMESPACE

namespace Git {
namespace Internal {

hjk's avatar
hjk committed
45
46
47
48
49
50
51
// Read-only
struct GitSubmitEditorPanelInfo
{
    void clear();
    QString repository;
    QString branch;
};
con's avatar
con committed
52

hjk's avatar
hjk committed
53
QDebug operator<<(QDebug d, const GitSubmitEditorPanelInfo &);
con's avatar
con committed
54

55
56
57
58
59
60
enum PushAction {
    CommitOnly,
    CommitAndPush,
    CommitAndPushToGerrit
};

hjk's avatar
hjk committed
61
62
63
64
65
struct GitSubmitEditorPanelData
{
    void clear();
    // Format as "John Doe <jdoe@foobar.com>"
    QString authorString() const;
con's avatar
con committed
66

hjk's avatar
hjk committed
67
68
    QString author;
    QString email;
69
    bool bypassHooks;
70
71
    PushAction pushAction;
    bool hasRemotes;
hjk's avatar
hjk committed
72
};
con's avatar
con committed
73

hjk's avatar
hjk committed
74
QDebug operator<<(QDebug d, const GitSubmitEditorPanelData &);
con's avatar
con committed
75

76
enum FileState {
77
    EmptyFileState = 0x00,
78
79
80
81
82
83
84
85
86

    StagedFile   = 0x01,
    ModifiedFile = 0x02,
    AddedFile    = 0x04,
    DeletedFile  = 0x08,
    RenamedFile  = 0x10,
    CopiedFile   = 0x20,
    UnmergedFile = 0x40,

Orgad Shaneh's avatar
Orgad Shaneh committed
87
88
89
    UnmergedUs   = 0x100,
    UnmergedThem = 0x200,

90
    UntrackedFile = 0x400,
91
92
93
94
    UnknownFileState = 0x800
};
Q_DECLARE_FLAGS(FileStates, FileState)

95
class CommitData
hjk's avatar
hjk committed
96
{
97
public:
98
    CommitData(CommitType type = SimpleCommit);
99
    // A pair of state string/file name ('modified', 'file.cpp').
100
    typedef QPair<FileStates, QString> StateFilePair;
101

hjk's avatar
hjk committed
102
    void clear();
103
104
105
106
107
108
    // Parse the files and the branch of panelInfo
    // from a git status output
    bool parseFilesFromStatus(const QString &output);

    // Convenience to retrieve the file names from
    // the specification list. Optionally filter for a certain state
109
    QStringList filterFiles(const FileStates &state) const;
110

111
    static QString stateDisplayName(const FileStates &state);
112

113
    CommitType commitType;
114
    QString amendSHA1;
115
    QString commitEncoding;
hjk's avatar
hjk committed
116
117
    GitSubmitEditorPanelInfo panelInfo;
    GitSubmitEditorPanelData panelData;
118

119
    QList<StateFilePair> files;
120
121
122

private:
    bool checkLine(const QString &stateInfo, const QString &file);
hjk's avatar
hjk committed
123
};
con's avatar
con committed
124

hjk's avatar
hjk committed
125
126
} // namespace Internal
} // namespace Git
con's avatar
con committed
127

128
129
Q_DECLARE_OPERATORS_FOR_FLAGS(Git::Internal::FileStates)

130
131
132
133
134
135
136
137
138
139
namespace Git {
namespace Internal {

// Must appear after Q_DECLARE_OPERATORS_FOR_FLAGS
bool operator<(const CommitData::StateFilePair &a,
               const CommitData::StateFilePair &b);

} // namespace Internal
} // namespace Git

hjk's avatar
hjk committed
140
#endif // COMMITDATA_H