Skip to content

Commit

Permalink
#5662: Try to open a repository at the mod path to see if there's a V…
Browse files Browse the repository at this point in the history
…CS repo set up
  • Loading branch information
codereader committed Jul 4, 2021
1 parent b0caa9b commit 60c4712
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 21 deletions.
39 changes: 32 additions & 7 deletions 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
{
Expand All @@ -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<vcs::GitModule>());
}
52 changes: 52 additions & 0 deletions plugins/vcs/Repository.h
@@ -0,0 +1,52 @@
#pragma once

#include <string>
#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);
}
};

}

}
14 changes: 0 additions & 14 deletions plugins/vcs/plugin.cpp

This file was deleted.

1 change: 1 addition & 0 deletions tools/msvc/vcs.vcxproj
Expand Up @@ -172,6 +172,7 @@
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\plugins\vcs\GitModule.h" />
<ClInclude Include="..\..\plugins\vcs\Repository.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
Expand Down
3 changes: 3 additions & 0 deletions tools/msvc/vcs.vcxproj.filters
Expand Up @@ -17,5 +17,8 @@
<ClInclude Include="..\..\plugins\vcs\GitModule.h">
<Filter>src</Filter>
</ClInclude>
<ClInclude Include="..\..\plugins\vcs\Repository.h">
<Filter>src</Filter>
</ClInclude>
</ItemGroup>
</Project>

0 comments on commit 60c4712

Please sign in to comment.