File indexing completed on 2024-04-21 04:34:35
0001 /*************************************************************************** 0002 * This file was taken from KDevelop's git plugin * 0003 * Copyright 2008 Evgeniy Ivanov <powerfox@kde.ru> * 0004 * * 0005 * Adapted for Mercurial * 0006 * Copyright 2009 Fabian Wiesel <fabian.wiesel@fu-berlin.de> * 0007 * Copyright 2011 Andrey Batyiev <batyiev@gmail.com> * 0008 * * 0009 * This program is free software; you can redistribute it and/or * 0010 * modify it under the terms of the GNU General Public License as * 0011 * published by the Free Software Foundation; either version 2 of * 0012 * the License or (at your option) version 3 or any later version * 0013 * accepted by the membership of KDE e.V. (or its successor approved * 0014 * by the membership of KDE e.V.), which shall act as a proxy * 0015 * defined in Section 14 of version 3 of the license. * 0016 * * 0017 * This program is distributed in the hope that it will be useful, * 0018 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0019 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0020 * GNU General Public License for more details. * 0021 * * 0022 * You should have received a copy of the GNU General Public License * 0023 * along with this program. If not, see <http://www.gnu.org/licenses/>. * 0024 ***************************************************************************/ 0025 0026 #ifndef MERCURIAL_PLUGIN_H 0027 #define MERCURIAL_PLUGIN_H 0028 0029 #include <vcs/interfaces/idistributedversioncontrol.h> 0030 #include <vcs/dvcs/dvcsplugin.h> 0031 #include <QObject> 0032 #include <QDir> 0033 #include <vcs/vcsstatusinfo.h> 0034 0035 class QAction; 0036 class KDirWatch; 0037 0038 namespace KDevelop 0039 { 0040 class VcsJob; 0041 class VcsRevision; 0042 } 0043 0044 class MercurialExecutor; 0045 0046 /** 0047 * This is the main class of KDevelop's Mercurial plugin. 0048 * 0049 * It implements the DVCS dependent things not implemented in KDevelop::DistributedVersionControlPlugin 0050 * @author Fabian Wiesel <fabian.wiesel@googlemail.com> 0051 */ 0052 0053 class MercurialPlugin 0054 : public KDevelop::DistributedVersionControlPlugin 0055 { 0056 Q_OBJECT 0057 Q_INTERFACES(KDevelop::IBasicVersionControl KDevelop::IDistributedVersionControl) 0058 0059 public: 0060 explicit MercurialPlugin(QObject *parent, const QVariantList &args = QVariantList()); 0061 ~MercurialPlugin(); 0062 0063 bool isValidDirectory(const QUrl &dirPath) override; 0064 bool isValidRemoteRepositoryUrl(const QUrl& remoteLocation) override; 0065 bool isVersionControlled(const QUrl &path) override; 0066 QString name() const override; 0067 0068 KDevelop::VcsJob *init(const QUrl &directory) override; 0069 KDevelop::VcsJob *repositoryLocation(const QUrl &directory) override; // Not implemented. 0070 KDevelop::VcsJob *createWorkingCopy(const KDevelop::VcsLocation &localOrRepoLocationSrc, const QUrl &repository, IBasicVersionControl::RecursionMode = KDevelop::IBasicVersionControl::Recursive) override; 0071 KDevelop::VcsJob *add(const QList<QUrl> &localLocations, 0072 KDevelop::IBasicVersionControl::RecursionMode recursion = KDevelop::IBasicVersionControl::Recursive) override; 0073 KDevelop::VcsJob *copy(const QUrl &localLocationSrc, 0074 const QUrl &localLocationDst) override; 0075 KDevelop::VcsJob *move(const QUrl &localLocationSrc, 0076 const QUrl &localLocationDst) override; 0077 0078 KDevelop::VcsJob *commit(const QString &message, 0079 const QList<QUrl> &localLocations, 0080 KDevelop::IBasicVersionControl::RecursionMode recursion) override; 0081 KDevelop::VcsJob *diff(const QUrl &fileOrDirectory, 0082 const KDevelop::VcsRevision &srcRevision, 0083 const KDevelop::VcsRevision &dstRevision, 0084 KDevelop::IBasicVersionControl::RecursionMode recursionMode) override; 0085 0086 KDevelop::VcsJob *remove(const QList<QUrl> &files) override; 0087 KDevelop::VcsJob *status(const QList<QUrl> &localLocations, 0088 KDevelop::IBasicVersionControl::RecursionMode recursion) override; 0089 KDevelop::VcsJob *revert(const QList<QUrl> &localLocations, 0090 KDevelop::IBasicVersionControl::RecursionMode recursion) override; 0091 KDevelop::VcsJob *update(const QList<QUrl> &localLocations, 0092 const KDevelop::VcsRevision &rev, KDevelop::IBasicVersionControl::RecursionMode recursion) override; 0093 KDevelop::VcsJob *resolve(const QList<QUrl> &files, KDevelop::IBasicVersionControl::RecursionMode recursion) override; 0094 0095 KDevelop::VcsJob *log(const QUrl &localLocation, 0096 const KDevelop::VcsRevision &rev, 0097 unsigned long limit) override; 0098 KDevelop::VcsJob *log(const QUrl &localLocation, 0099 const KDevelop::VcsRevision &rev, 0100 const KDevelop::VcsRevision &limit) override; 0101 0102 KDevelop::VcsJob *log(const QUrl &localLocation, 0103 const KDevelop::VcsRevision &to, 0104 const KDevelop::VcsRevision &from, 0105 unsigned long limit); 0106 KDevelop::VcsJob *annotate(const QUrl &localLocation, 0107 const KDevelop::VcsRevision &rev) override; 0108 0109 KDevelop::VcsJob* mergeBranch(const QUrl &repository, const QString &branchName) override; 0110 0111 // mercurial specific stuff 0112 KDevelop::VcsJob *heads(const QUrl &localLocation); 0113 KDevelop::VcsJob *identify(const QUrl &localLocation); 0114 KDevelop::VcsJob *checkoutHead(const QUrl &localLocation, const KDevelop::VcsRevision &rev); 0115 KDevelop::VcsJob *mergeWith(const QUrl &localLocation, const KDevelop::VcsRevision &rev); 0116 0117 // mercurial queues stuff 0118 KDevelop::VcsJob *mqNew(const QUrl &localLocation, const QString &name, const QString &message); 0119 KDevelop::VcsJob *mqPush(const QUrl &localLocation); 0120 KDevelop::VcsJob *mqPushAll(const QUrl &localLocation); 0121 KDevelop::VcsJob *mqPop(const QUrl &localLocation); 0122 KDevelop::VcsJob *mqPopAll(const QUrl &localLocation); 0123 KDevelop::VcsJob *mqApplied(const QUrl &localLocation); 0124 KDevelop::VcsJob *mqUnapplied(const QUrl &localLocation); 0125 0126 KDevelop::VcsJob *push(const QUrl &localRepositoryLocation, 0127 const KDevelop::VcsLocation &localOrRepoLocationDst) override; 0128 KDevelop::VcsJob *pull(const KDevelop::VcsLocation &localOrRepoLocationSrc, 0129 const QUrl &localRepositoryLocation) override; 0130 0131 KDevelop::VcsLocationWidget *vcsLocation(QWidget *parent) const override; 0132 0133 //parsers for branch: 0134 KDevelop::VcsJob *branch(const QUrl &repository, const KDevelop::VcsRevision &rev, const QString &branchName) override; 0135 KDevelop::VcsJob *branches(const QUrl &repository) override; 0136 KDevelop::VcsJob *currentBranch(const QUrl &repository) override; 0137 KDevelop::VcsJob *deleteBranch(const QUrl &repository, const QString &branchName) override; 0138 KDevelop::VcsJob *renameBranch(const QUrl &repository, const QString &oldBranchName, const QString &newBranchName) override; 0139 KDevelop::VcsJob *switchBranch(const QUrl &repository, const QString &branchName) override; 0140 KDevelop::VcsJob *tag(const QUrl &repository, const QString &commitMessage, const KDevelop::VcsRevision &rev, const QString &tagName) override; 0141 0142 //graph helpers 0143 QVector<KDevelop::DVcsEvent> allCommits(const QString& repo) override; 0144 0145 /** 0146 * Find out where is default remote located. 0147 * @param directory inside working directory 0148 */ 0149 QUrl remotePushRepositoryLocation(QDir &directory); 0150 0151 void registerRepositoryForCurrentBranchChanges(const QUrl &repository) override; 0152 0153 QString toMercurialRevision(const KDevelop::VcsRevision &vcsrev); 0154 0155 private slots: 0156 void parseLogOutputBasicVersionControl(KDevelop::DVcsJob *job) const; 0157 bool parseStatus(KDevelop::DVcsJob *job) const; 0158 void parseDiff(KDevelop::DVcsJob *job); 0159 void parseMultiLineOutput(KDevelop::DVcsJob *job) const; 0160 0161 /* 0162 * mercurial specific stuff 0163 */ 0164 void parseIdentify(KDevelop::DVcsJob *job) const; 0165 0166 void fileChanged(const QString& file); 0167 /* 0168 * ui helpers 0169 */ 0170 void showHeads(); 0171 void showMercurialQueuesManager(); 0172 0173 signals: 0174 void repositoryBranchChanged(const QUrl& repository); 0175 0176 private: 0177 KDirWatch* m_watcher; 0178 QList<QUrl> m_branchesChange; 0179 0180 void parseLogOutput(const KDevelop::DVcsJob* job, QVector<KDevelop::DVcsEvent>& commits) const override; 0181 0182 /** 0183 * Remove directories from @p locations. 0184 */ 0185 static void filterOutDirectories(QList<QUrl> &locations); 0186 0187 static KDevelop::VcsStatusInfo::State charToState(const char ch); 0188 static QDir findWorkingDir(const QUrl &location); 0189 0190 QUrl m_lastRepoRoot; 0191 0192 // actions 0193 QAction *m_headsAction; 0194 0195 QAction *m_mqNew, 0196 *m_mqPushAction, 0197 *m_mqPushAllAction, 0198 *m_mqPopAction, 0199 *m_mqPopAllAction, 0200 *m_mqManagerAction; 0201 QList<QUrl> m_urls; 0202 void additionalMenuEntries(QMenu *menu, const QList<QUrl> &urls) override; 0203 }; 0204 0205 //class MercurialQueues 0206 0207 #endif