Skip to content

Commit

Permalink
#5662: Add global version control interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Jul 17, 2021
1 parent b346c5a commit 877b1a8
Show file tree
Hide file tree
Showing 8 changed files with 150 additions and 1 deletion.
2 changes: 1 addition & 1 deletion include/imodule.h
Expand Up @@ -31,7 +31,7 @@
* As long as no external module/plugin files are removed this number is safe to stay
* as it is. Keep this number compatible to std::size_t, i.e. unsigned.
*/
#define MODULE_COMPATIBILITY_LEVEL 20201026
#define MODULE_COMPATIBILITY_LEVEL 20210717

// A function taking an error title and an error message string, invoked in debug builds
// for things like ASSERT_MESSAGE and ERROR_MESSAGE
Expand Down
60 changes: 60 additions & 0 deletions include/iversioncontrol.h
@@ -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;
}
1 change: 1 addition & 0 deletions radiantcore/CMakeLists.txt
Expand Up @@ -277,6 +277,7 @@ add_library(radiantcore MODULE
shaders/textures/TextureManipulator.cpp
skins/Doom3SkinCache.cpp
undo/UndoSystem.cpp
versioncontrol/VersionControlManager.cpp
vfs/DeflatedInputStream.cpp
vfs/DirectoryArchive.cpp
vfs/Doom3FileSystem.cpp
Expand Down
50 changes: 50 additions & 0 deletions radiantcore/versioncontrol/VersionControlManager.cpp
@@ -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;

}
26 changes: 26 additions & 0 deletions radiantcore/versioncontrol/VersionControlManager.h
@@ -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;
};

}
2 changes: 2 additions & 0 deletions tools/msvc/DarkRadiantCore.vcxproj
Expand Up @@ -673,6 +673,7 @@
<ClCompile Include="..\..\radiantcore\shaders\textures\TextureManipulator.cpp" />
<ClCompile Include="..\..\radiantcore\skins\Doom3SkinCache.cpp" />
<ClCompile Include="..\..\radiantcore\undo\UndoSystem.cpp" />
<ClCompile Include="..\..\radiantcore\versioncontrol\VersionControlManager.cpp" />
<ClCompile Include="..\..\radiantcore\vfs\DeflatedInputStream.cpp" />
<ClCompile Include="..\..\radiantcore\vfs\DirectoryArchive.cpp" />
<ClCompile Include="..\..\radiantcore\vfs\Doom3FileSystem.cpp" />
Expand Down Expand Up @@ -1028,6 +1029,7 @@
<ClInclude Include="..\..\radiantcore\undo\Stack.h" />
<ClInclude Include="..\..\radiantcore\undo\StackFiller.h" />
<ClInclude Include="..\..\radiantcore\undo\UndoSystem.h" />
<ClInclude Include="..\..\radiantcore\versioncontrol\VersionControlManager.h" />
<ClInclude Include="..\..\radiantcore\vfs\AssetsList.h" />
<ClInclude Include="..\..\radiantcore\vfs\DeflatedArchiveFile.h" />
<ClInclude Include="..\..\radiantcore\vfs\DeflatedArchiveTextFile.h" />
Expand Down
9 changes: 9 additions & 0 deletions tools/msvc/DarkRadiantCore.vcxproj.filters
Expand Up @@ -200,6 +200,9 @@
<Filter Include="src\model\import">
<UniqueIdentifier>{a98a0273-a99f-4a0d-b181-14479a01cecd}</UniqueIdentifier>
</Filter>
<Filter Include="src\versioncontrol">
<UniqueIdentifier>{6e21fce5-68dc-4b21-8856-b219352b5f02}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\radiantcore\modulesystem\ModuleLoader.cpp">
Expand Down Expand Up @@ -1048,6 +1051,9 @@
<ClCompile Include="..\..\radiantcore\log\SegFaultHandler.cpp">
<Filter>src\log</Filter>
</ClCompile>
<ClCompile Include="..\..\radiantcore\versioncontrol\VersionControlManager.cpp">
<Filter>src\versioncontrol</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\radiantcore\modulesystem\ModuleLoader.h">
Expand Down Expand Up @@ -2139,5 +2145,8 @@
<ClInclude Include="..\..\radiantcore\log\SegFaultHandler.h">
<Filter>src\log</Filter>
</ClInclude>
<ClInclude Include="..\..\radiantcore\versioncontrol\VersionControlManager.h">
<Filter>src\versioncontrol</Filter>
</ClInclude>
</ItemGroup>
</Project>
1 change: 1 addition & 0 deletions tools/msvc/include.vcxproj
Expand Up @@ -202,6 +202,7 @@
<ClInclude Include="..\..\include\itransformnode.h" />
<ClInclude Include="..\..\include\iundo.h" />
<ClInclude Include="..\..\include\iuserinterface.h" />
<ClInclude Include="..\..\include\iversioncontrol.h" />
<ClInclude Include="..\..\include\ivolumetest.h" />
<ClInclude Include="..\..\include\iwxgl.h" />
<ClInclude Include="..\..\include\mapfile.h" />
Expand Down

0 comments on commit 877b1a8

Please sign in to comment.