From e30996994997754117061dc43c6d22390fdb9b8b Mon Sep 17 00:00:00 2001 From: WrinklyNinja Date: Fri, 20 Jun 2014 16:34:57 +0100 Subject: [PATCH] Updated libgit2 usage for v0.21.0. --- docs/BUILD.MSVC.md | 26 ++++++++++++++------------ src/backend/network.cpp | 22 ++++++++++++---------- 2 files changed, 26 insertions(+), 22 deletions(-) diff --git a/docs/BUILD.MSVC.md b/docs/BUILD.MSVC.md index 481cb5ce..2c0501c5 100644 --- a/docs/BUILD.MSVC.md +++ b/docs/BUILD.MSVC.md @@ -30,24 +30,26 @@ Example CMake keys: `-DCMAKE_RUNTIME_OUTPUT_DIRECTORY=build -DCMAKE_ARCHIVE_OUTP #### Libgit2 -1. Configure CMake and generate a build system for Visual Studio by running CMake with keys `-DCMAKE_ARCHIVE_OUTPUT_DIRECTORY=build -DCMAKE_RUNTIME_OUTPUT_DIRECTORY=build -DBUILD_SHARED_LIBS=OFF -DSTATIC_CRT=OFF`. +1. Configure CMake and generate a build system for Visual Studio by running CMake with keys `-DCMAKE_ARCHIVE_OUTPUT_DIRECTORY=build -DCMAKE_RUNTIME_OUTPUT_DIRECTORY=build -DBUILD_SHARED_LIBS=OFF -DSTATIC_CRT=ON`. 2. Open the generated solution file, and build it with `Release` configuration. #### LOOT LOOT uses the following CMake variables to set build parameters: -Parameter | Values | Description -----------|--------|------------ -`BUILD_SHARED_LIBS` | `ON`, `OFF` | Whether or not to build a shared libloot. Defaults to `OFF`. -`PROJECT_STATIC_RUNTIME` | `ON`, `OFF` | Whether to link the C++ runtime statically or not. This also affects the Boost libraries used. Defaults to `ON`. -`PROJECT_ARCH` | `32`, `64` | Whether to build 32 or 64 bit LOOT binaries. Defaults to `32`. -`ALPHANUM_ROOT` | path | Path to the folder containing `alphanum.hpp`. Defaults to `../../alphanum`, relative to LOOT's CMakeLists.txt. -`LIBESPM_ROOT` | path | Path to the root of the libespm repository folder. Defaults to `../../libespm`, relative to LOOT's CMakeLists.txt. -`LIBGIT2_ROOT` | path | Path to the root of the libgit2 repository folder. Defaults to `../../libgit2`, relative to LOOT's CMakeLists.txt. -`LIBLOADORDER_ROOT` | path | Path to the root of the libloadorder repository folder. Defaults to `../../libloadorder`, relative to LOOT's CMakeLists.txt. -`YAMLCPP_ROOT` | path | Path to the root of the yaml-cpp folder. Defaults to `../../yaml-cpp`, relative to LOOT's CMakeLists.txt. -`WXWIDGETS_ROOT` | path | Path to the root of the wxWidgets folder. Defaults to `../../wxWidgets`, relative to LOOT's CMakeLists.txt. +Parameter | Values | Default |Description +----------|--------|---------|----------- +`BUILD_SHARED_LIBS` | `ON`, `OFF` | `OFF` | Whether or not to build a shared libloot. +`PROJECT_STATIC_RUNTIME` | `ON`, `OFF` | `ON` | Whether to link the C++ runtime statically or not. This also affects the Boost libraries used. +`PROJECT_ARCH` | `32`, `64` | `32` | Whether to build 32 or 64 bit LOOT binaries. +`ALPHANUM_ROOT` | path | `../../alphanum` | Path to the folder containing `alphanum.hpp`. +`LIBESPM_ROOT` | path | `../../libespm` | Path to the root of the libespm repository folder. +`LIBGIT2_ROOT` | path | `../../libgit2` | Path to the root of the libgit2 repository folder. +`LIBLOADORDER_ROOT` | path | `../../libloadorder` | Path to the root of the libloadorder repository folder. +`YAMLCPP_ROOT` | path | `../../yaml-cpp` | Path to the root of the yaml-cpp folder. +`WXWIDGETS_ROOT` | path | `../../wxWidgets` | Path to the root of the wxWidgets folder. + +The default paths given in the table above are relative to LOOT's `CMakeLists.txt`. 1. Set CMake up so that it builds the binaries in the `build` subdirectory of the LOOT folder. 2. Define any necessary parameters. diff --git a/src/backend/network.cpp b/src/backend/network.cpp index ed1e38d2..32a6ebeb 100644 --- a/src/backend/network.cpp +++ b/src/backend/network.cpp @@ -224,6 +224,9 @@ namespace loot { git.call(git_remote_create(&git.remote, git.repo, "origin", game.RepoURL().c_str())); } + //Now that repo is loaded, create a reflog signature for any changes. + git.call(git_signature_new(&git.sig, "LOOT", "loot@placeholder.net", 0, 0)); + //WARNING: This is generally a very bad idea, since it makes HTTPS a little bit pointless, but in this case because we're only reading data and not really concerned about its integrity, it's acceptable. A better solution would be to figure out why GitHub's certificate appears to be invalid to OpenSSL. #ifndef _WIN32 git_remote_check_cert(git.remote, 0); @@ -236,7 +239,7 @@ namespace loot { //Fetch from remote. BOOST_LOG_TRIVIAL(trace) << "Fetching from remote."; - git.call(git_remote_fetch(git.remote)); + git.call(git_remote_fetch(git.remote, git.sig, NULL)); const git_transfer_progress * stats = git_remote_stats(git.remote); BOOST_LOG_TRIVIAL(info) << "Received " << stats->indexed_objects << " of " << stats->total_objects << " objects in " << stats->received_bytes << " bytes."; @@ -246,7 +249,7 @@ namespace loot { char * paths[] = { "masterlist.yaml" }; - git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT; + git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT; opts.checkout_strategy = GIT_CHECKOUT_FORCE; //Make sure the existing file gets overwritten. opts.paths.strings = paths; opts.paths.count = 1; @@ -276,15 +279,14 @@ namespace loot { BOOST_LOG_TRIVIAL(info) << "Getting the Git object for the tree at " << filespec; git.call(git_revparse_single(&git.obj, git.repo, filespec.c_str())); - BOOST_LOG_TRIVIAL(trace) << "Getting the Git object ID."; - const git_oid * oid = git_object_id(git.obj); - - BOOST_LOG_TRIVIAL(trace) << "Generating hex string for Git object ID."; - char sha1[10]; - git_oid_tostr(sha1, 10, oid); - revision = sha1; + BOOST_LOG_TRIVIAL(trace) << "Generating hex string for the Git object."; + git_buf buffer; + git.call(git_object_short_id(&buffer, git.obj)); + revision = string(buffer.ptr, buffer.size); + git_buf_free(&buffer); BOOST_LOG_TRIVIAL(trace) << "Getting date for Git object ID."; + const git_oid * oid = git_object_id(git.obj); git.call(git_commit_lookup(&git.commit, git.repo, oid)); git_time_t time = git_commit_time(git.commit); boost::locale::date_time dateTime(time); @@ -293,7 +295,7 @@ namespace loot { date = out.str(); BOOST_LOG_TRIVIAL(trace) << "Recreating HEAD as a direct reference (overwriting it) to the desired revision."; - git.call(git_reference_create(&git.ref, git.repo, "HEAD", oid, 1)); + git.call(git_reference_create(&git.ref, git.repo, "HEAD", oid, 1, git.sig, "Updated HEAD.")); BOOST_LOG_TRIVIAL(trace) << "Performing a Git checkout of HEAD."; git.call(git_checkout_head(git.repo, &opts));