From 0b1639f8a817abd13e65e879e6cfe52876553410 Mon Sep 17 00:00:00 2001 From: David Knaack Date: Mon, 9 May 2022 18:01:22 +0200 Subject: [PATCH] Add `EOWNER` and use main libgit2 branch Co-Authored-By: Eric Huss <43198+ehuss@users.noreply.github.com> --- libgit2-sys/build.rs | 48 ++++++++++++++++++++++++++++---------------- libgit2-sys/lib.rs | 1 + libgit2-sys/libgit2 | 2 +- src/error.rs | 3 +++ src/lib.rs | 2 ++ 5 files changed, 38 insertions(+), 18 deletions(-) diff --git a/libgit2-sys/build.rs b/libgit2-sys/build.rs index e655b3ea22..a68f86d58a 100644 --- a/libgit2-sys/build.rs +++ b/libgit2-sys/build.rs @@ -14,11 +14,7 @@ fn main() { let try_to_use_system_libgit2 = !vendored && !zlib_ng_compat; if try_to_use_system_libgit2 { let mut cfg = pkg_config::Config::new(); - if let Ok(lib) = cfg - .range_version("1.4.3".."1.5.0") - .print_system_libs(false) - .probe("libgit2") - { + if let Ok(lib) = cfg.range_version("1.4.3".."1.5.0").probe("libgit2") { for include in &lib.include_paths { println!("cargo:root={}", include.display()); } @@ -45,20 +41,21 @@ fn main() { cp_r("libgit2/include", &include); cfg.include(&include) - .include("libgit2/src") + .include("libgit2/src/libgit2") .include("libgit2/src/util") .out_dir(dst.join("build")) .warnings(false); // Include all cross-platform C files - add_c_files(&mut cfg, "libgit2/src"); - add_c_files(&mut cfg, "libgit2/src/xdiff"); + add_c_files(&mut cfg, "libgit2/src/libgit2"); + add_c_files(&mut cfg, "libgit2/src/util"); + add_c_files(&mut cfg, "libgit2/src/libgit2/xdiff"); // These are activated by features, but they're all unconditionally always // compiled apparently and have internal #define's to make sure they're // compiled correctly. - add_c_files(&mut cfg, "libgit2/src/transports"); - add_c_files(&mut cfg, "libgit2/src/streams"); + add_c_files(&mut cfg, "libgit2/src/libgit2/transports"); + add_c_files(&mut cfg, "libgit2/src/libgit2/streams"); // Always use bundled http-parser for now cfg.include("libgit2/deps/http-parser") @@ -87,11 +84,11 @@ fn main() { // when when COMPILE_PCRE8 is not defined, which is the default. add_c_files(&mut cfg, "libgit2/deps/pcre"); - cfg.file("libgit2/src/allocators/failalloc.c"); - cfg.file("libgit2/src/allocators/stdalloc.c"); + cfg.file("libgit2/src/util/allocators/failalloc.c"); + cfg.file("libgit2/src/util/allocators/stdalloc.c"); if windows { - add_c_files(&mut cfg, "libgit2/src/win32"); + add_c_files(&mut cfg, "libgit2/src/util/win32"); cfg.define("STRSAFE_NO_DEPRECATE", None); cfg.define("WIN32", None); cfg.define("_WIN32_WINNT", Some("0x0600")); @@ -103,7 +100,7 @@ fn main() { cfg.define("__USE_MINGW_ANSI_STDIO", "1"); } } else { - add_c_files(&mut cfg, "libgit2/src/unix"); + add_c_files(&mut cfg, "libgit2/src/util/unix"); cfg.flag("-fvisibility=hidden"); } if target.contains("solaris") || target.contains("illumos") { @@ -161,9 +158,26 @@ fn main() { cfg.define("SHA1DC_NO_STANDARD_INCLUDES", "1"); cfg.define("SHA1DC_CUSTOM_INCLUDE_SHA1_C", "\"common.h\""); cfg.define("SHA1DC_CUSTOM_INCLUDE_UBC_CHECK_C", "\"common.h\""); - cfg.file("libgit2/src/hash/sha1/collisiondetect.c"); - cfg.file("libgit2/src/hash/sha1/sha1dc/sha1.c"); - cfg.file("libgit2/src/hash/sha1/sha1dc/ubc_check.c"); + cfg.file("libgit2/src/util/hash/collisiondetect.c"); + cfg.file("libgit2/src/util/hash/sha1dc/sha1.c"); + cfg.file("libgit2/src/util/hash/sha1dc/ubc_check.c"); + + if https { + if windows { + features.push_str("#define GIT_SHA256_WIN32 1\n"); + cfg.file("libgit2/src/util/hash/win32.c"); + } else if target.contains("apple") { + features.push_str("#define GIT_SHA256_COMMON_CRYPTO 1\n"); + cfg.file("libgit2/src/util/hash/common_crypto.c"); + } else { + features.push_str("#define GIT_SHA256_OPENSSL 1\n"); + cfg.file("libgit2/src/util/hash/openssl.c"); + } + } else { + features.push_str("#define GIT_SHA256_BUILTIN 1\n"); + cfg.file("libgit2/src/util/hash/builtin.c"); + cfg.file("libgit2/src/util/hash/rfc6234/sha224-256.c"); + } if let Some(path) = env::var_os("DEP_Z_INCLUDE") { cfg.include(path); diff --git a/libgit2-sys/lib.rs b/libgit2-sys/lib.rs index 7e468d7d26..18d5680a33 100644 --- a/libgit2-sys/lib.rs +++ b/libgit2-sys/lib.rs @@ -195,6 +195,7 @@ git_enum! { GIT_EMISMATCH = -33, GIT_EINDEXDIRTY = -34, GIT_EAPPLYFAIL = -35, + GIT_EOWNER = -36, } } diff --git a/libgit2-sys/libgit2 b/libgit2-sys/libgit2 index 465bbf88ea..bdab22384c 160000 --- a/libgit2-sys/libgit2 +++ b/libgit2-sys/libgit2 @@ -1 +1 @@ -Subproject commit 465bbf88ea939a965fbcbade72870c61f815e457 +Subproject commit bdab22384cc61d315005a65456a9f9563bb27c8f diff --git a/src/error.rs b/src/error.rs index f3ad9ad0e9..779d785adf 100644 --- a/src/error.rs +++ b/src/error.rs @@ -127,6 +127,7 @@ impl Error { raw::GIT_EMISMATCH => super::ErrorCode::HashsumMismatch, raw::GIT_EINDEXDIRTY => super::ErrorCode::IndexDirty, raw::GIT_EAPPLYFAIL => super::ErrorCode::ApplyFail, + raw::GIT_EOWNER => super::ErrorCode::Owner, _ => super::ErrorCode::GenericError, } } @@ -163,6 +164,7 @@ impl Error { ErrorCode::HashsumMismatch => raw::GIT_EMISMATCH, ErrorCode::IndexDirty => raw::GIT_EINDEXDIRTY, ErrorCode::ApplyFail => raw::GIT_EAPPLYFAIL, + ErrorCode::Owner => raw::GIT_EOWNER, }; } @@ -293,6 +295,7 @@ impl Error { GIT_EMISMATCH, GIT_EINDEXDIRTY, GIT_EAPPLYFAIL, + GIT_EOWNER, ) } diff --git a/src/lib.rs b/src/lib.rs index 11337e3bd9..10f5f5e98b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -214,6 +214,8 @@ pub enum ErrorCode { IndexDirty, /// Patch application failed ApplyFail, + /// The object is not owned by the current user + Owner, } /// An enumeration of possible categories of things that can have