File indexing completed on 2024-05-12 04:38:53

0001 /*
0002     SPDX-FileCopyrightText: 2007 Andreas Pakulat <apaku@gmx.de>
0003     SPDX-FileCopyrightText: 2007 Matthew Woehlke <mw_triad@users.sourceforge.net>
0004 
0005     SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007 
0008 #ifndef KDEVPLATFORM_IBASICVERSIONCONTROL_H
0009 #define KDEVPLATFORM_IBASICVERSIONCONTROL_H
0010 
0011 #include <QUrl>
0012 #include <QList>
0013 
0014 #include "../vcsrevision.h"
0015 #include "../vcsdiff.h"
0016 
0017 class QString;
0018 class KTextEdit;
0019 
0020 namespace KDevelop
0021 {
0022 
0023 class VcsJob;
0024 class VcsLocation;
0025 class VcsImportMetadataWidget;
0026 class VcsLocationWidget;
0027 
0028 /**
0029  * This is the basic interface that all Version Control or Source Code Management
0030  * plugins need to implement. None of the methods in this interface are optional.
0031  *
0032  * This only works on a local checkout from the repository, if your plugin should
0033  * offer functionality that works solely on the server see the
0034  * IRepositoryVersionControl interface
0035  *
0036  */
0037 
0038 class KDEVPLATFORMVCS_EXPORT IBasicVersionControl
0039 {
0040 public:
0041 
0042     enum RecursionMode
0043     {
0044         Recursive    /**< run recursively through subdirectories */,
0045         NonRecursive /**< don't run recursively through subdirectories */
0046     };
0047     virtual ~IBasicVersionControl(){}
0048 
0049     /**
0050      * return a user-visible string for the version control plugin
0051      * Can be used for example when importing a project into a
0052      * version control system to choose the appropriate system
0053      *
0054      * @returns a translated user-visible name for this version control plugin
0055      */
0056     virtual QString name() const = 0;
0057     /**
0058      * provides a widget that fetches the needed input data from the user
0059      * to import a project into a version control system.
0060      *
0061      * If this returns 0 the plugin will not be available as an option for import
0062      * when creating a new project
0063      *
0064      * @param parent the parent widget for the newly created widget
0065      * @returns a widget to fetch metadata needed to import a project
0066      */
0067     virtual VcsImportMetadataWidget* createImportMetadataWidget( QWidget* parent ) = 0;
0068 
0069     /**
0070      * Checks whether the given @p remoteLocation is a valid remote repository URL.
0071      *
0072      * If the URL is a local filesystem path, the folder will be checked
0073      * if it contains proper repository content.
0074      * For non-local filesystem URLs only the URL properties will be checked,
0075      * no communication to any server is done.
0076      *
0077      * @param remoteLocation the URL used to access a remote repository
0078      * @returns true if the given @p remoteLocation seems valid for this version control system
0079      */
0080     virtual bool isValidRemoteRepositoryUrl(const QUrl& remoteLocation) = 0;
0081 
0082     /**
0083      * These methods rely on a valid vcs-directory with vcs-metadata in it.
0084      *
0085      * revisions can contain a date in format parseable by QDate, a number,
0086      * or the special words HEAD and BASE (whose exact meaning depends on the
0087      * used VCS system)
0088      */
0089 
0090     /**
0091      * Is the given @p localLocation under version control? This checks whether
0092      * the @p localLocation is under control of the versioning system or not.
0093      * It does not only check whether the @p localLocation lies in a version
0094      * controlled directory
0095      *
0096      * @returns true if the version control system knows the given @p localLocation
0097      */
0098     virtual bool isVersionControlled( const QUrl& localLocation ) = 0;
0099 
0100     /**
0101      * Get the repository location of a local file
0102      */
0103     virtual VcsJob* repositoryLocation( const QUrl& localLocation ) = 0;
0104 
0105     /**
0106      * adds a local unversioned file or directory to the list of versioned files.
0107      * @param localLocations a list of files or directories that should be put under version control
0108      * @param recursion whether to add directories and their children or only directories themselves
0109      * @returns a job that executes the addition
0110      */
0111     virtual VcsJob* add( const QList<QUrl>& localLocations,
0112                          RecursionMode recursion = IBasicVersionControl::Recursive ) = 0;
0113 
0114     /**
0115      * removes a local versioned file or directory from the version control system
0116      * @param localLocations the list of files/directories to remove from the VCS
0117      * @returns a job that executes the removal
0118      */
0119     virtual VcsJob* remove( const QList<QUrl>& localLocations ) = 0;
0120 
0121     /**
0122      * executes a copy of a file/dir, preserving history if the VCS system
0123      * allows that, may be implemented by filesystem copy+add
0124      */
0125     virtual VcsJob* copy( const QUrl& localLocationSrc,
0126                           const QUrl& localLocationDstn ) = 0;
0127 
0128     /**
0129      * moves src to dst, preserving history if the VCS system allows that, may
0130      * be implemented by copy+remove
0131      */
0132     virtual VcsJob* move( const QUrl& localLocationSrc,
0133                           const QUrl& localLocationDst ) = 0;
0134 
0135     /**
0136      * Fetches the status of the given local vcs locations.
0137      *
0138      * The returned VcsJob populates a QList<QVariant> that can be fetched
0139      * using fetchResults(). The QVariant inside the list wraps a
0140      * KDevelo::VcsStatusInfo object which contains all the relevant
0141      * information about the status of a specific file or folder
0142      */
0143     virtual VcsJob* status( const QList<QUrl>& localLocations,
0144                             RecursionMode recursion = IBasicVersionControl::Recursive ) = 0;
0145 
0146     /**
0147      * revert all local changes on the given file, making its content equal
0148      * to the version in the repository
0149      * unedit() (if not a no-op) is implied.
0150      */
0151     virtual VcsJob* revert( const QList<QUrl>& localLocations,
0152                             RecursionMode recursion = IBasicVersionControl::Recursive ) = 0;
0153 
0154     /**
0155      * fetches the latest changes from the repository, if there are
0156      * conflicts a merge needs to be executed separately
0157      *
0158      * @param localLocations the local files/dirs that should be updated
0159      * @param rev Update to this revision. The operation will fail if @p rev is
0160      * a range.
0161      * @param recursion defines whether the directories should be updated
0162      * recursively
0163      */
0164     virtual VcsJob* update( const QList<QUrl>& localLocations,
0165                             const VcsRevision& rev = VcsRevision::createSpecialRevision( VcsRevision::Head ),
0166                             RecursionMode recursion = IBasicVersionControl::Recursive ) = 0;
0167 
0168     /**
0169      * Checks in the changes of the given file(s)/dir(s) into the repository
0170      */
0171     virtual VcsJob* commit( const QString& message,
0172                             const QList<QUrl>& localLocations,
0173                             RecursionMode recursion = IBasicVersionControl::Recursive ) = 0;
0174 
0175     /**
0176      * Retrieves a diff between two revisions of a file
0177      *
0178      * The diff is in unified diff format for text files.
0179      */
0180     virtual VcsJob* diff( const QUrl& fileOrDirectory,
0181                           const VcsRevision& srcRevision,
0182                           const VcsRevision& dstRevision,
0183                           IBasicVersionControl::RecursionMode recursion
0184                                        = IBasicVersionControl::Recursive ) = 0;
0185 
0186     /**
0187      * Retrieve the history of a given local url
0188      *
0189      * The resulting VcsJob will emit the resultsReady signal every time new
0190      * log events are available. The fetchResults method will return a QList<QVariant>
0191      * where the QVariant is a KDevelop::VcsEvent.
0192      *
0193      * @param rev List @p rev and earlier.
0194      * @param limit Restrict to the most recent @p limit entries. Note that the
0195      * limit is @e advisory and may be ignored.
0196      */
0197     virtual VcsJob* log( const QUrl& localLocation,
0198                          const VcsRevision& rev,
0199                          unsigned long limit = 0 ) = 0;
0200 
0201     /**
0202      * Retrieve the history of a given local url
0203      *
0204      * The resulting VcsJob will emit the resultsReady signal every time new
0205      * log events are available. The fetchResults method will return a QList<QVariant>
0206      * where the QVariant is a KDevelop::VcsEvent.
0207      *
0208      * @param rev List @p rev and earlier. The default is BASE.
0209      * @param limit Do not show entries earlier than @p limit. Note that the
0210      * limit is @e advisory and may be ignored. The default is the first revision.
0211      */
0212     virtual VcsJob* log( const QUrl& localLocation,
0213                          const VcsRevision& rev = VcsRevision::createSpecialRevision( VcsRevision::Base ),
0214                          const VcsRevision& limit= VcsRevision::createSpecialRevision( VcsRevision::Start ) ) = 0;
0215 
0216     /**
0217      * Annotate each line of the given local url at the given revision
0218      * with information about who changed it and when.
0219      *
0220      * The job should return a QList<QVariant> where the QVariant wraps
0221      * a KDevelop::VcsAnnotationLine. The instance contains all information
0222      * needed for the caller to construct a KDevelop::VcsAnnotation
0223      *
0224      * @see KDevelop::VcsAnnotation
0225      * @see KDevelop::VcsAnnotationLine
0226      *
0227      * @param localLocation local file that should be annotated.
0228      * @param rev Revision that should be annotated.
0229      */
0230     virtual VcsJob* annotate( const QUrl& localLocation,
0231                               const VcsRevision& rev = VcsRevision::createSpecialRevision( VcsRevision::Head ) ) = 0;
0232 
0233     /**
0234      * check for conflicts in the given file and eventually present a
0235      * conflict solving dialog to the user
0236      */
0237     virtual VcsJob* resolve( const QList<QUrl>& localLocations,
0238                              RecursionMode recursion ) = 0;
0239 
0240     /**
0241      * Creates a working copy of the latest revision of the repository sourceRepository in
0242      * the newly created directory destinationDirectory.
0243      * In the case of a decentralized VCSs, there is no working copy without repository,
0244      * therefor checkout() includes the creation of a local copy of the repository.
0245      * 
0246      * @param sourceRepository source of the checkout
0247      * @param destinationDirectory location of the created working copy (local repository)
0248      */
0249     virtual VcsJob* createWorkingCopy(const VcsLocation & sourceRepository, const QUrl & destinationDirectory, RecursionMode recursion = IBasicVersionControl::Recursive) = 0;
0250     
0251     virtual VcsLocationWidget* vcsLocation(QWidget* parent) const=0;
0252 
0253     /**
0254      * Optionally apply VCS specific settings to the commit message editor.
0255      * Overwrite this to set e.g. a default commit message or to setup highlighting or validation.
0256      * The default implementation does nothing.
0257      */
0258     virtual void setupCommitMessageEditor(const QUrl&, KTextEdit* edit) const;
0259 };
0260 
0261 }
0262 
0263 Q_DECLARE_INTERFACE( KDevelop::IBasicVersionControl, "org.kdevelop.IBasicVersionControl" )
0264 
0265 #endif
0266