gitplugin.h 6.46 KB
Newer Older
1
2
/***************************************************************************
 *   Copyright 2008 Evgeniy Ivanov <powerfox@kde.ru>                       *
3
 *   Copyright 2009 Hugo Parente Lima <hugo.pl@gmail.com>                  *
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
 *                                                                         *
 *   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>
26
#include <vcs/dvcs/dvcsplugin.h>
27
28
#include <QObject>
#include <vcs/vcsstatusinfo.h>
29
#include <outputview/outputjob.h>
30

31

32
33
34
35
36
37
namespace KDevelop
{
    class VcsJob;
    class VcsRevision;
}

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

55
56
57
58
59
60
    QString name() const;

    bool isVersionControlled(const KUrl &path);

    KDevelop::VcsJob* add(const KUrl::List& localLocations,
                          KDevelop::IBasicVersionControl::RecursionMode recursion = KDevelop::IBasicVersionControl::Recursive);
61
62
63
    KDevelop::VcsJob* createWorkingCopy(const KDevelop::VcsLocation & localOrRepoLocationSrc,
                            const KUrl& localRepositoryRoot, KDevelop::IBasicVersionControl::RecursionMode);

64
65
66
67
68
69
    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);
70

71
72
    virtual KDevelop::VcsJob* diff(const KUrl& fileOrDirectory, const KDevelop::VcsRevision& srcRevision, const KDevelop::VcsRevision& dstRevision,
                                   KDevelop::VcsDiff::Type, RecursionMode recursion);
73
74
    using KDevelop::DistributedVersionControlPlugin::log;

75
76
77
    KDevelop::VcsJob* log(const KUrl& localLocation,
                          const KDevelop::VcsRevision& rev,
                          unsigned long limit);
78
    KDevelop::VcsJob* annotate(const KUrl &localLocation, const KDevelop::VcsRevision &rev);
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101

    // Begin:  KDevelop::IDistributedVersionControl
    KDevelop::VcsJob* init(const KUrl & directory);
    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:
102
103
104
    QList<QVariant> getModifiedFiles(const QString &directory, KDevelop::OutputJob::OutputJobVerbosity verbosity = KDevelop::OutputJob::Verbose);
    QList<QVariant> getCachedFiles(const QString &directory, KDevelop::OutputJob::OutputJobVerbosity verbosity = KDevelop::OutputJob::Verbose);
    QList<QVariant> getOtherFiles(const QString &directory, KDevelop::OutputJob::OutputJobVerbosity verbosity = KDevelop::OutputJob::Verbose);
105
106
107
108
109
110
111
112
113
114
115
116

    //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,
117
118
                     const QStringList &args,
                     KDevelop::OutputJob::OutputJobVerbosity verbosity = KDevelop::OutputJob::Verbose);
119
120
121
    DVcsJob* gitRevList(const QString &repository,
                        const QStringList &args);
    DVcsJob* gitRevParse(const QString &repository,
122
123
                         const QStringList &args,
                         KDevelop::OutputJob::OutputJobVerbosity verbosity = KDevelop::OutputJob::Verbose);
124

125
126
protected slots:
    void parseGitBlameOutput(DVcsJob *job);
127
    void parseGitLogOutput(DVcsJob *job);
128
    void parseGitDiffOutput(DVcsJob* job);
129

130
131
private:
    //commit dialog "main" helper
132
133
    QStringList getLsFiles(const QString &directory, const QStringList &args = QStringList(),
        KDevelop::OutputJob::OutputJobVerbosity verbosity = KDevelop::OutputJob::Verbose);
134
135
136
137
138
139
140

    void initBranchHash(const QString &repo);

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

    QList<QStringList> branchesShas;
141
    KUrl m_lastRepoRoot;
142
143
144
};

#endif