diff --git a/plugins/vcs/GitModule.cpp b/plugins/vcs/GitModule.cpp index acfe824e44..aa41cd0b80 100644 --- a/plugins/vcs/GitModule.cpp +++ b/plugins/vcs/GitModule.cpp @@ -1,7 +1,8 @@ #include "GitModule.h" #include "igame.h" -#include "git2/repository.h" +#include "git2.h" +#include "Repository.h" namespace vcs { @@ -22,25 +23,49 @@ void GitModule::initialiseModule(const IApplicationContext& ctx) { rMessage() << getName() << "::initialiseModule called." << std::endl; + // Initialise libgit2 to have the memory handlers etc. set up + git_libgit2_init(); + auto modPath = GlobalGameManager().getModPath(); - git_repository* repository; - if (git_repository_open(&repository, modPath.c_str()) == 0) + git::Repository repository(modPath); + + if (repository.isOk()) { rMessage() << "Opened repository at " << modPath << std::endl; } - else - { - rMessage() << "Failed to open repository at " << modPath << std::endl; - } + +#if 0 + git_commit* commit; + git_oid oid; + git_reference_name_to_id(&oid, repository, "refs/heads/master"); + + git_commit_lookup(&commit, repository, &oid); + + const auto* author = git_commit_author(commit); + auto time = git_commit_time(commit); + rMessage() << "Last commit author: " << author->name << " at " << ctime(&time) << std::endl; + + git_commit_free(commit); +#endif } void GitModule::shutdownModule() { rMessage() << getName() << "::shutdownModule called." << std::endl; + git_libgit2_shutdown(); +} } +/** + * greebo: This is the module entry point which the main binary will look for. + * The symbol RegisterModule is called with the singleton ModuleRegistry as argument. + */ +extern "C" void DARKRADIANT_DLLEXPORT RegisterModule(IModuleRegistry & registry) +{ + module::performDefaultInitialisation(registry); + registry.registerModule(std::make_shared()); } diff --git a/plugins/vcs/Repository.h b/plugins/vcs/Repository.h new file mode 100644 index 0000000000..6ad25c524c --- /dev/null +++ b/plugins/vcs/Repository.h @@ -0,0 +1,52 @@ +#pragma once + +#include +#include "itextstream.h" +#include "git2.h" + +namespace vcs +{ + +namespace git +{ + +/** + * Represents a Git repository at a certain path + */ +class Repository +{ +private: + git_repository* _repository; + bool _isOk; + +public: + Repository(const std::string& path) : + _repository(nullptr), + _isOk(false) + { + if (git_repository_open(&_repository, path.c_str()) == 0) + { + rMessage() << "Opened repository at " << path << std::endl; + _isOk = true; + } + else + { + rMessage() << "Failed to open repository at " << path << std::endl; + } + } + + // Status query of this repository object + bool isOk() const + { + return _isOk; + } + + ~Repository() + { + git_repository_free(_repository); + } +}; + +} + +} diff --git a/plugins/vcs/plugin.cpp b/plugins/vcs/plugin.cpp deleted file mode 100644 index 5af386b6cc..0000000000 --- a/plugins/vcs/plugin.cpp +++ /dev/null @@ -1,14 +0,0 @@ -#include "itextstream.h" - -#include "GitModule.h" - -/** - * greebo: This is the module entry point which the main binary will look for. - * The symbol RegisterModule is called with the singleton ModuleRegistry as argument. - */ -extern "C" void DARKRADIANT_DLLEXPORT RegisterModule(IModuleRegistry & registry) -{ - module::performDefaultInitialisation(registry); - - registry.registerModule(std::make_shared()); -} diff --git a/tools/msvc/vcs.vcxproj b/tools/msvc/vcs.vcxproj index d5b7c7b16a..54e4a5faf6 100644 --- a/tools/msvc/vcs.vcxproj +++ b/tools/msvc/vcs.vcxproj @@ -172,6 +172,7 @@ + diff --git a/tools/msvc/vcs.vcxproj.filters b/tools/msvc/vcs.vcxproj.filters index 243af946d8..ff607c66ca 100644 --- a/tools/msvc/vcs.vcxproj.filters +++ b/tools/msvc/vcs.vcxproj.filters @@ -17,5 +17,8 @@ src + + src + \ No newline at end of file