gitplugin.h 5.35 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/***************************************************************************
 *   Copyright 2008 Evgeniy Ivanov <powerfox@kde.ru>                       *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or         *
 *   modify it under the terms of the GNU General Public License as        *
 *   published by the Free Software Foundation; either version 2 of        *
 *   the License or (at your option) version 3 or any later version        *
 *   accepted by the membership of KDE e.V. (or its successor approved     *
 *   by the membership of KDE e.V.), which shall act as a proxy            *
 *   defined in Section 14 of version 3 of the license.                    *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>. *
 ***************************************************************************/

#ifndef GIT_PLUGIN_H
#define GIT_PLUGIN_H

#include <vcs/interfaces/idistributedversioncontrol.h>
25
#include <vcs/dvcs/dvcsplugin.h>
26
27
28
#include <QObject>
#include <vcs/vcsstatusinfo.h>

29

30
31
32
33
34
35
namespace KDevelop
{
    class VcsJob;
    class VcsRevision;
}

36
37
38
/**
 * This is the main class of KDevelop's Git plugin.
 *
39
 * It implements the DVCS dependent things not implemented in KDevelop::DistributedVersionControlPlugin
40
41
 * @author Evgeniy Ivanov <powerfox@kde.ru>
 */
42
class GitPlugin: public KDevelop::DistributedVersionControlPlugin
43
44
45
{
    Q_OBJECT
    Q_INTERFACES(KDevelop::IBasicVersionControl KDevelop::IDistributedVersionControl)
46
    friend class GitInitTest;
47
public:
48
    GitPlugin(QObject *parent, const QVariantList & args = QVariantList() );
49
    ~GitPlugin();
50

51
52
53
54
55
56
57
58
59
60
61
62
    QString name() const;

    bool isVersionControlled(const KUrl &path);

    KDevelop::VcsJob* add(const KUrl::List& localLocations,
                          KDevelop::IBasicVersionControl::RecursionMode recursion = KDevelop::IBasicVersionControl::Recursive);
    KDevelop::VcsJob* remove(const KUrl::List& files);
    KDevelop::VcsJob* status(const KUrl::List& localLocations,
                             KDevelop::IBasicVersionControl::RecursionMode recursion = KDevelop::IBasicVersionControl::Recursive);
    KDevelop::VcsJob* commit(const QString& message,
                             const KUrl::List& localLocations,
                             KDevelop::IBasicVersionControl::RecursionMode recursion = KDevelop::IBasicVersionControl::Recursive);
63
64
65
66
67
68
    KDevelop::VcsJob* log(const KUrl& localLocation,
                          const KDevelop::VcsRevision& rev,
                          unsigned long limit);
    KDevelop::VcsJob* log(const KUrl& localLocation,
                          const KDevelop::VcsRevision& rev,
                          const KDevelop::VcsRevision& limit);
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125

    // Begin:  KDevelop::IDistributedVersionControl
    KDevelop::VcsJob* init(const KUrl & directory);
    KDevelop::VcsJob* clone(const KDevelop::VcsLocation & localOrRepoLocationSrc,
                            const KUrl& localRepositoryRoot);

    KDevelop::VcsJob* reset(const KUrl& repository,
                            const QStringList &args,
                            const KUrl::List& files);
    // End:  KDevelop::IDistributedVersionControl

    DVcsJob* var(const QString &directory);

    // Branch management

    DVcsJob* switchBranch(const QString &repository,
                          const QString &branch);
    DVcsJob* branch(const QString &repository,
                    const QString &basebranch = QString(),
                    const QString &branch = QString(),
                    const QStringList &args = QStringList());

    QString curBranch(const QString &repository);
    QStringList branches(const QString &repository);

    //commit dialog helpers, send to main helper the arg for git-ls-files:
    QList<QVariant> getModifiedFiles(const QString &directory);
    QList<QVariant> getCachedFiles(const QString &directory);
    QList<QVariant> getOtherFiles(const QString &directory);

    //graph helpers
    QList<DVcsEvent> getAllCommits(const QString &repo);

    //used in log
    void parseLogOutput(const DVcsJob * job,
                        QList<DVcsEvent>& commits) const;

protected:
    bool isValidDirectory(const KUrl &dirPath);

    DVcsJob* lsFiles(const QString &repository,
                     const QStringList &args);
    DVcsJob* gitRevList(const QString &repository,
                        const QStringList &args);
    DVcsJob* gitRevParse(const QString &repository,
                         const QStringList &args);

private:
    //commit dialog "main" helper
    QStringList getLsFiles(const QString &directory, const QStringList &args = QStringList());

    void initBranchHash(const QString &repo);

    static KDevelop::VcsStatusInfo::State charToState(const char ch);
    static KDevelop::VcsStatusInfo::State lsTagToState(const char ch);

    QList<QStringList> branchesShas;
126
127
128
};

#endif