Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#5662: Add global version control interfaces
- Loading branch information
1 parent
b346c5a
commit 877b1a8
Showing
8 changed files
with
150 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#pragma once | ||
|
||
#include "imodule.h" | ||
|
||
namespace vcs | ||
{ | ||
|
||
/** | ||
* Common interface of a version control module offering | ||
* methods to access its history. | ||
* | ||
* Each module needs to define a unique prefix which are used | ||
* when resolving item URIs. | ||
*/ | ||
class IVersionControlModule | ||
{ | ||
public: | ||
virtual ~IVersionControlModule() {} | ||
|
||
using Ptr = std::shared_ptr<IVersionControlModule>; | ||
|
||
// Returns the prefix which is used to construct URIs | ||
// that refer to a specific point in the VCS history | ||
virtual std::string getUriPrefix() = 0; | ||
}; | ||
|
||
|
||
/** | ||
* Interface which keeps track of the active version control | ||
* modules of this app. | ||
* | ||
* Version Control modules need to register themselves here | ||
* to be accessible by the core modules. | ||
*/ | ||
class IVersionControlManager : | ||
public RegisterableModule | ||
{ | ||
public: | ||
virtual ~IVersionControlManager() {} | ||
|
||
// Register the given module. If a module with the same prefix has already been registered, | ||
// a std::runtime_error exception will be thrown. | ||
virtual void registerModule(const IVersionControlModule::Ptr& vcsModule) = 0; | ||
|
||
virtual void unregisterModule(const IVersionControlModule::Ptr& vcsModule) = 0; | ||
|
||
// Return the source control module for the given prefix, or an empty reference if nothing found | ||
virtual IVersionControlModule::Ptr getModuleForPrefix(const std::string& prefix) = 0; | ||
}; | ||
|
||
constexpr const char* const MODULE_VERSION_CONTROL_MANAGER = "VersionControlManager"; | ||
|
||
} | ||
|
||
// The accessor for the clipper module | ||
inline vcs::IVersionControlManager& GlobalVersionControlManager() | ||
{ | ||
static module::InstanceReference<vcs::IVersionControlManager> _reference(vcs::MODULE_VERSION_CONTROL_MANAGER); | ||
return _reference; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#include "VersionControlManager.h" | ||
|
||
#include "itextstream.h" | ||
#include "module/StaticModule.h" | ||
|
||
namespace vcs | ||
{ | ||
|
||
void VersionControlManager::registerModule(const IVersionControlModule::Ptr& vcsModule) | ||
{ | ||
auto result = _registeredModules.emplace(vcsModule->getUriPrefix(), vcsModule); | ||
|
||
if (!result.second) | ||
{ | ||
throw std::runtime_error("A VCS module with prefix " + vcsModule->getUriPrefix() + " has already been registered."); | ||
} | ||
} | ||
|
||
void VersionControlManager::unregisterModule(const IVersionControlModule::Ptr& vcsModule) | ||
{ | ||
_registeredModules.erase(vcsModule->getUriPrefix()); | ||
} | ||
|
||
IVersionControlModule::Ptr VersionControlManager::getModuleForPrefix(const std::string& prefix) | ||
{ | ||
auto existing = _registeredModules.find(prefix); | ||
|
||
return existing != _registeredModules.end() ? existing->second : IVersionControlModule::Ptr(); | ||
} | ||
|
||
const std::string& VersionControlManager::getName() const | ||
{ | ||
static std::string _name(vcs::MODULE_VERSION_CONTROL_MANAGER); | ||
return _name; | ||
} | ||
|
||
const StringSet& VersionControlManager::getDependencies() const | ||
{ | ||
static StringSet _dependencies; | ||
return _dependencies; | ||
} | ||
|
||
void VersionControlManager::initialiseModule(const IApplicationContext& ctx) | ||
{ | ||
rMessage() << getName() << "::initialiseModule called." << std::endl; | ||
} | ||
|
||
module::StaticModule<VersionControlManager> versionControlManagerModule; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#pragma once | ||
|
||
#include <map> | ||
#include "iversioncontrol.h" | ||
|
||
namespace vcs | ||
{ | ||
|
||
class VersionControlManager final : | ||
public IVersionControlManager | ||
{ | ||
private: | ||
std::map<std::string, IVersionControlModule::Ptr> _registeredModules; | ||
|
||
public: | ||
void registerModule(const IVersionControlModule::Ptr& vcsModule) override; | ||
void unregisterModule(const IVersionControlModule::Ptr& vcsModule) override; | ||
IVersionControlModule::Ptr getModuleForPrefix(const std::string& prefix) override; | ||
|
||
// RegisterableModule implementation | ||
const std::string& getName() const override; | ||
const StringSet& getDependencies() const override; | ||
void initialiseModule(const IApplicationContext& ctx) override; | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters