gitplugin.h 7.96 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
#include <vcs/vcsjob.h>
31

32

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

39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
class StandardCopyJob : public KDevelop::VcsJob
{
    Q_OBJECT
    public:
        StandardCopyJob(KDevelop::IPlugin* parent, const KUrl& source,
                        const KUrl& dest, OutputJobVerbosity verbosity);
        
        virtual QVariant fetchResults() { return QVariant(); }
        virtual void start();
        virtual JobStatus status() const { return m_status; }
        virtual KDevelop::IPlugin* vcsPlugin() const { return m_plugin; }
        
    public slots:
        void result(KJob*);
    
    private:
        const KUrl m_source, m_dest;
        KDevelop::IPlugin* m_plugin;
        JobStatus m_status;
};

60 61 62
/**
 * This is the main class of KDevelop's Git plugin.
 *
63
 * It implements the DVCS dependent things not implemented in KDevelop::DistributedVersionControlPlugin
64 65
 * @author Evgeniy Ivanov <powerfox@kde.ru>
 */
66
class GitPlugin: public KDevelop::DistributedVersionControlPlugin
67 68 69
{
    Q_OBJECT
    Q_INTERFACES(KDevelop::IBasicVersionControl KDevelop::IDistributedVersionControl)
70
    friend class GitInitTest;
71
public:
72
    GitPlugin(QObject *parent, const QVariantList & args = QVariantList() );
73
    ~GitPlugin();
74 75
   
    virtual void unload();
76

77 78 79
    QString name() const;

    bool isVersionControlled(const KUrl &path);
80 81 82 83 84 85 86 87 88 89
    
    virtual KDevelop::VcsJob* copy(const KUrl& localLocationSrc, const KUrl& localLocationDstn);
    virtual KDevelop::VcsJob* move(const KUrl& localLocationSrc, const KUrl& localLocationDst);
    
    //TODO
    virtual KDevelop::VcsJob* pull(const KDevelop::VcsLocation& localOrRepoLocationSrc, const KUrl& localRepositoryLocation);
    virtual KDevelop::VcsJob* push(const KUrl& localRepositoryLocation, const KDevelop::VcsLocation& localOrRepoLocationDst);
    virtual KDevelop::VcsJob* repositoryLocation(const KUrl& localLocation);
    virtual KDevelop::VcsJob* resolve(const KUrl::List& localLocations, RecursionMode recursion);
    virtual KDevelop::VcsJob* update(const KUrl::List& localLocations, const KDevelop::VcsRevision& rev, RecursionMode recursion);
90
    KDevelop::VcsLocationWidget* vcsLocation(QWidget* parent) const;
91
    //End of
92 93 94

    KDevelop::VcsJob* add(const KUrl::List& localLocations,
                          KDevelop::IBasicVersionControl::RecursionMode recursion = KDevelop::IBasicVersionControl::Recursive);
95 96 97
    KDevelop::VcsJob* createWorkingCopy(const KDevelop::VcsLocation & localOrRepoLocationSrc,
                            const KUrl& localRepositoryRoot, KDevelop::IBasicVersionControl::RecursionMode);

98 99 100 101 102 103
    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);
104

105 106
    virtual KDevelop::VcsJob* diff(const KUrl& fileOrDirectory, const KDevelop::VcsRevision& srcRevision, const KDevelop::VcsRevision& dstRevision,
                                   KDevelop::VcsDiff::Type, RecursionMode recursion);
107 108
    using KDevelop::DistributedVersionControlPlugin::log;

109 110 111
    KDevelop::VcsJob* log(const KUrl& localLocation,
                          const KDevelop::VcsRevision& rev,
                          unsigned long limit);
112
    KDevelop::VcsJob* annotate(const KUrl &localLocation, const KDevelop::VcsRevision &rev);
113
    KDevelop::VcsJob* revert(const KUrl::List& localLocations, RecursionMode recursion);
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136

    // 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:
137 138 139
    QList<QVariant> getModifiedFiles(const QString &directory, KDevelop::OutputJob::OutputJobVerbosity verbosity);
    QList<QVariant> getCachedFiles(const QString &directory, KDevelop::OutputJob::OutputJobVerbosity verbosity);
    QList<QVariant> getOtherFiles(const QString &directory, KDevelop::OutputJob::OutputJobVerbosity verbosity);
140 141 142 143 144 145 146 147 148 149 150 151

    //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,
152 153
                     const QStringList &args,
                     KDevelop::OutputJob::OutputJobVerbosity verbosity = KDevelop::OutputJob::Verbose);
154 155 156
    DVcsJob* gitRevList(const QString &repository,
                        const QStringList &args);
    DVcsJob* gitRevParse(const QString &repository,
157 158
                         const QStringList &args,
                         KDevelop::OutputJob::OutputJobVerbosity verbosity = KDevelop::OutputJob::Verbose);
159

160 161
protected slots:
    void parseGitBlameOutput(DVcsJob *job);
162
    void parseGitLogOutput(DVcsJob *job);
163
    void parseGitDiffOutput(DVcsJob* job);
164
    void parseGitRepoLocationOutput(DVcsJob* job);
165

166 167
private:
    //commit dialog "main" helper
168 169
    QStringList getLsFiles(const QString &directory, const QStringList &args,
        KDevelop::OutputJob::OutputJobVerbosity verbosity);
170
	DVcsJob* errorsFound(const QString& error, KDevelop::OutputJob::OutputJobVerbosity verbosity);
171 172 173

    void initBranchHash(const QString &repo);

174
    static KDevelop::VcsStatusInfo::State charToState(char ch);
175 176

    QList<QStringList> branchesShas;
177
    KUrl m_lastRepoRoot;
178 179 180
};

#endif