Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add libgit2 lib with source #3

Merged
merged 9 commits into from Aug 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
13 changes: 13 additions & 0 deletions .gitignore
Expand Up @@ -12,11 +12,24 @@ api.json

# Binaries
bin/
intermediate/
build/
*.dll
*.obj
*.so
*.dylib
*.pdb
*.ilk
*.exe
*.os
*.out
.import/

# Binaries for distribution
!/demo/bin/
!libgitapi.dll
!libgitapi.so
!libgitapi.dylib
!git2.lib
!libgit.a

13 changes: 9 additions & 4 deletions SConstruct
Expand Up @@ -18,6 +18,8 @@ opts.Add(PathVariable('target_name', 'The library name.', 'libgitapi', PathVaria
godot_headers_path = "godot-cpp/godot_headers/"
cpp_bindings_path = "godot-cpp/"
cpp_library = "libgodot-cpp"
libgit2_lib_path = "demo/bin/"
libgit2_include_path = "godot-git-plugin/thirdparty/libgit2/include/"

# only support 64 at this time..
bits = 64
Expand All @@ -41,6 +43,7 @@ if env['platform'] == '':
if env['platform'] == "osx":
env['target_path'] += 'osx/'
cpp_library += '.osx'
libgit2_lib_path += 'osx/'
if env['target'] in ('debug', 'd'):
env.Append(CCFLAGS = ['-g','-O2', '-arch', 'x86_64'])
env.Append(LINKFLAGS = ['-arch', 'x86_64'])
Expand All @@ -51,6 +54,7 @@ if env['platform'] == "osx":
elif env['platform'] in ('x11', 'linux'):
env['target_path'] += 'x11/'
cpp_library += '.linux'
libgit2_lib_path += 'x11/'
if env['target'] in ('debug', 'd'):
env.Append(CCFLAGS = ['-fPIC', '-g3','-Og', '-std=c++17'])
else:
Expand All @@ -59,6 +63,7 @@ elif env['platform'] in ('x11', 'linux'):
elif env['platform'] == "windows":
env['target_path'] += 'win64/'
cpp_library += '.windows'
libgit2_lib_path += 'win64/'
# This makes sure to keep the session environment variables on windows,
# that way you can run scons in a vs 2017 prompt and it will find all the required tools
env.Append(ENV = os.environ)
Expand All @@ -76,13 +81,13 @@ else:

cpp_library += '.' + str(bits)

# make sure our binding library is properly includes
# make sure our binding library properly includes
env.Append(CPPPATH=['.', godot_headers_path, cpp_bindings_path + 'include/', cpp_bindings_path + 'include/core/', cpp_bindings_path + 'include/gen/'])
env.Append(LIBPATH=[cpp_bindings_path + 'bin/'])
env.Append(LIBS=[cpp_library])
env.Append(LIBPATH=[cpp_bindings_path + 'bin/', libgit2_lib_path])
env.Append(LIBS=[cpp_library, 'git2'])

# tweak this if you want to use different folders, or more folders, to store your source code in.
env.Append(CPPPATH=['godot-git-plugin/src/'])
env.Append(CPPPATH=['godot-git-plugin/src/', libgit2_include_path])
sources = Glob('godot-git-plugin/src/*.cpp')

library = env.SharedLibrary(target=env['target_path'] + env['target_name'] , source=sources)
Expand Down
Binary file added demo/bin/win64/git2.lib
Binary file not shown.
Binary file added demo/bin/win64/libgitapi.dll
Binary file not shown.
Binary file added demo/bin/win64/libgitapi.exp
Binary file not shown.
Binary file added demo/bin/win64/libgitapi.lib
Binary file not shown.
Binary file added demo/bin/x11/libgit2.a
Binary file not shown.
Binary file added demo/bin/x11/libgitapi.so
Binary file not shown.
1 change: 1 addition & 0 deletions demo/git_api.gdns
Expand Up @@ -3,6 +3,7 @@
[ext_resource path="res://git_api.gdnlib" type="GDNativeLibrary" id=1]

[resource]
resource_name = "GitAPI"
class_name = "GitAPI"
library = ExtResource( 1 )
script_class_name = "GitAPI"
1 change: 0 additions & 1 deletion demo/project.godot
Expand Up @@ -21,7 +21,6 @@ _global_script_class_icons={
[application]

config/name="demo"
run/main_scene="res://demo.tscn"
config/icon="res://icon.png"

[gdnative]
Expand Down
6 changes: 3 additions & 3 deletions godot-git-plugin/godot-git-plugin.vcxproj
Expand Up @@ -70,8 +70,8 @@
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<IncludePath>.\src\;..\godot-cpp\godot_headers\;..\godot-cpp\include\gen;..\godot-cpp\include\core\;..\godot-cpp\include\;$(IncludePath)</IncludePath>
<LibraryPath>..\godot-cpp\bin;$(LibraryPath)</LibraryPath>
<IncludePath>D:\CPP Projects\godot-git-plugin\godot-git-plugin\thirdparty\libgit2\include;.\src\;..\godot-cpp\godot_headers\;..\godot-cpp\include\gen;..\godot-cpp\include\core\;..\godot-cpp\include\;$(IncludePath)</IncludePath>
<LibraryPath>D:\CPP Projects\godot-git-plugin\demo\bin\win64;..\godot-cpp\bin;$(LibraryPath)</LibraryPath>
<SourcePath>.\src\;$(VC_SourcePath);</SourcePath>
<OutDir>$(SolutionDir)..\demo\bin\win64\</OutDir>
<IntDir>$(SolutionDir)..\demo\bin\win64\intermediate\</IntDir>
Expand All @@ -93,7 +93,7 @@
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<AdditionalDependencies>libgodot-cpp.windows.debug.64.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>libgodot-cpp.windows.debug.64.lib;git2.lib;%(AdditionalDependencies)</AdditionalDependencies>
<SubSystem>Console</SubSystem>
<OutputFile>$(SolutionDir)..\demo\bin\win64\libgitapi.dll</OutputFile>
</Link>
Expand Down
3 changes: 0 additions & 3 deletions godot-git-plugin/src/gdlibrary.cpp
Expand Up @@ -7,9 +7,6 @@ extern "C" void GDN_EXPORT godot_gdnative_init(godot_gdnative_init_options *o) {
godot::Godot::gdnative_init(o);
}

extern "C" void GDN_EXPORT godot_gdnative_singleton(godot_gdnative_init_options *o) {
}

extern "C" void GDN_EXPORT godot_gdnative_terminate(godot_gdnative_terminate_options *o) {

godot::Godot::gdnative_terminate(o);
Expand Down
27 changes: 22 additions & 5 deletions godot-git-plugin/src/git_api.cpp
@@ -1,14 +1,14 @@
#include "git_api.h"

#include <ClassDB.hpp>

namespace godot {

bool GitAPI::is_initialized = false;

void GitAPI::_register_methods() {

register_method("_process", &GitAPI::_process);

register_method("_initialiaze", &GitAPI::_initialize);
register_method("_initialize", &GitAPI::_initialize);
register_method("_get_vcs_name", &GitAPI::_get_vcs_name);
register_method("_get_project_name", &GitAPI::_get_project_name);
register_method("_get_commit_dock_panel_container", &GitAPI::_get_commit_dock_panel_container);
Expand All @@ -18,7 +18,7 @@ void GitAPI::_register_methods() {

Variant GitAPI::_get_commit_dock_panel_container() {

return init_settings_panel_container;
return NULL;
}

Variant GitAPI::_get_initialization_settings_panel_container() {
Expand All @@ -41,7 +41,24 @@ String GitAPI::_get_vcs_name() {
return "Git";
}

bool GitAPI::_initialize(const String project_root_path) {
bool GitAPI::_initialize(const String p_project_root_path) {

ERR_FAIL_COND_V(p_project_root_path == "", false);

if (is_initialized == false) {

GIT2_CALL(git_libgit2_init() == 1, false);
is_initialized = true;
} else {

return true;
}

git_repository_init_options opts = GIT_REPOSITORY_INIT_OPTIONS_INIT;
opts.flags |= GIT_REPOSITORY_INIT_NO_REINIT;
GIT2_CALL(git_repository_init_ext(&repo, p_project_root_path.alloc_c_string(), &opts) == 0, false);

GIT2_CALL(git_repository_open(&repo, p_project_root_path.alloc_c_string()) == 0, false);

return true;
}
Expand Down
22 changes: 20 additions & 2 deletions godot-git-plugin/src/git_api.h
Expand Up @@ -7,26 +7,44 @@
#include <Godot.hpp>
#include <PanelContainer.hpp>

#include <git2.h>

#define memnew(m_Class) new m_Class()
#define memdelete(m_pointer) delete m_pointer

// NULL objects are not being handled to discourage lazy destruction of objects
#define memdelete(m_pointer) m_pointer ? WARN_PRINT("GIT API tried to delete a NULL object") : delete m_pointer;

#define GIT2_CALL(m_libgit2_function_check, m_fail_return) \
{ \
bool res = m_libgit2_function_check; \
if (!res) { \
const git_error *e = giterr_last(); \
WARN_PRINT(e->message); \
return m_fail_return; \
} \
}

namespace godot {

class GitAPI : public EditorVCSInterface {

GODOT_CLASS(GitAPI, EditorVCSInterface)

static bool is_initialized;

godot::PanelContainer *init_settings_panel_container;
godot::Button *init_settings_button;

git_repository *repo;

public:
static void _register_methods();

Variant _get_commit_dock_panel_container();
Variant _get_initialization_settings_panel_container();
String _get_project_name();
String _get_vcs_name();
bool _initialize(const String project_root_path);
bool _initialize(const String p_project_root_path);
bool _shut_down();

void _init();
Expand Down
3 changes: 3 additions & 0 deletions godot-git-plugin/thirdparty/VERSIONS
@@ -0,0 +1,3 @@
# This file lists all thirdparty libraries used in this plugin with the latest commit link of when source was picked up

libgit2: https://github.com/libgit2/libgit2/commit/f039c836438f96407abc08cbd238b9102318deb2
24 changes: 24 additions & 0 deletions godot-git-plugin/thirdparty/libgit2/.HEADER
@@ -0,0 +1,24 @@
/*
* This file is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License, version 2,
* as published by the Free Software Foundation.
*
* In addition to the permissions in the GNU General Public License,
* the authors give you unlimited permission to link the compiled
* version of this file into combinations with other programs,
* and to distribute those combinations without any restriction
* coming from the use of this file. (The General Public License
* restrictions do apply in other respects; for example, they cover
* modification of the file, and distribution when not linked into
* a combined executable.)
*
* This file is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; see the file COPYING. If not, write to
* the Free Software Foundation, 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
15 changes: 15 additions & 0 deletions godot-git-plugin/thirdparty/libgit2/.editorconfig
@@ -0,0 +1,15 @@
; Check http://editorconfig.org/ for more informations
; Top-most EditorConfig file
root = true

; tab indentation
[*]
indent_style = tab
trim_trailing_whitespace = true
insert_final_newline = true

; 4-column space indentation
[*.md]
indent_style = space
indent_size = 4
trim_trailing_whitespace = false
1 change: 1 addition & 0 deletions godot-git-plugin/thirdparty/libgit2/.gitattributes
@@ -0,0 +1 @@
* text=auto
19 changes: 19 additions & 0 deletions godot-git-plugin/thirdparty/libgit2/.github/ISSUE_TEMPLATE
@@ -0,0 +1,19 @@
You are opening a _bug report_ against the libgit2 project: we use
GitHub Issues for tracking bug reports and feature requests. If you
have a question about an API or usage, please ask on StackOverflow:
http://stackoverflow.com/questions/tagged/libgit2. If you want to
have high-level discussions about the libgit2 project itself, visit
https://github.com/libgit2/discussions.

Otherwise, to report a bug, please fill out the reproduction steps
(below) and delete these introductory paragraphs. Thanks!

### Reproduction steps

### Expected behavior

### Actual behavior

### Version of libgit2 (release number or SHA1)

### Operating system(s) tested
37 changes: 37 additions & 0 deletions godot-git-plugin/thirdparty/libgit2/.gitignore
@@ -0,0 +1,37 @@
/tests/clar.suite
/tests/clar.suite.rule
/tests/.clarcache
/apidocs
/trash-*.exe
/libgit2.pc
/config.mak
*.o
*.a
*.exe
*.gcda
*.gcno
*.gcov
.lock-wafbuild
.waf*
build/
build-amiga/
tests/tmp/
msvc/Debug/
msvc/Release/
*.sln
*.suo
*.vc*proj*
*.sdf
*.opensdf
*.aps
*.cmake
!cmake/Modules/*.cmake
.DS_Store
*~
.*.swp
tags
mkmf.log
*.profdata
*.profraw
CMakeSettings.json
.vs
22 changes: 22 additions & 0 deletions godot-git-plugin/thirdparty/libgit2/.mailmap
@@ -0,0 +1,22 @@
Vicent Martí <vicent@github.com> Vicent Marti <tanoku@gmail.com>
Vicent Martí <vicent@github.com> Vicent Martí <tanoku@gmail.com>
Michael Schubert <schu@schu.io> schu <schu-github@schulog.org>
Ben Straub <bs@github.com> Ben Straub <ben@straubnet.net>
Ben Straub <bs@github.com> Ben Straub <bstraub@github.com>
Carlos Martín Nieto <cmn@dwim.me> <carlos@cmartin.tk>
Carlos Martín Nieto <cmn@dwim.me> <cmn@elego.de>
nulltoken <emeric.fermas@gmail.com> <emeric.fermas@gmail.com>
Scott J. Goldman <scottjg@github.com> <scottjgo@gmail.com>
Martin Woodward <martin.woodward@microsoft.com> <martinwo@microsoft.com>
Peter Drahoš <drahosp@gmail.com> <drahosp@gmail.com>
Adam Roben <adam@github.com> <adam@roben.org>
Adam Roben <adam@github.com> <adam@github.com>
Xavier L. <xavier.l@afrosoft.tk> <xavier.l@afrosoft.ca>
Xavier L. <xavier.l@afrosoft.tk> <xavier.l@afrosoft.tk>
Sascha Cunz <sascha@babbelbox.org> <Sascha@BabbelBox.org>
Authmillenon <authmillenon@googlemail.com> <martin@ucsmail.de>
Authmillenon <authmillenon@googlemail.com> <authmillenon@googlemail.com>
Edward Thomson <ethomson@edwardthomson.com> <ethomson@microsoft.com>
Edward Thomson <ethomson@edwardthomson.com> <ethomson@github.com>
J. David Ibáñez <jdavid.ibp@gmail.com> <jdavid@itaapy.com>
Russell Belfer <rb@github.com> <arrbee@arrbee.com>