From 94c6f72aa96e3818caf2359de253785430271dc6 Mon Sep 17 00:00:00 2001 From: OrbitZore Date: Mon, 2 Nov 2026 02:37:50 +0800 Subject: [PATCH] =?UTF-8?q?build:=20=E7=BC=96=E8=AF=91=E6=9C=9F=E6=8B=92?= =?UTF-8?q?=E7=BB=9D=E5=AE=9E=E9=AA=8C=E6=9E=84=E5=BB=BA=20libgit2=20?= =?UTF-8?q?=E5=B9=B6=E4=BF=AE=E6=AD=A3=E6=9C=80=E4=BD=8E=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E5=A3=B0=E6=98=8E(1.4=E2=86=921.7)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 问题(#8): - 链接以 GIT_EXPERIMENTAL_SHA256 构建的 libgit2 时,gitmount恰在两处 git_oid_fromstr 调用点(src/rawobj.cpp 的 oid_from_hex、 src/gitmount.cpp 的 /commit 命名空间解析)以裸的 "too few arguments" 编译失败——实验构建下该函数为三参签名且 git_oid 结构体布局更大 (20→33 字节),v0.1 不支持,但使用者无从得知这是"不支持"而非"待适配"。 - CMakeLists.txt 声明 libgit2>=1.4,但 src/gitrepo.cpp 使用的 git_repository_oid_type 与 rawobj 使用的 git_oid_t 均首见于 libgit2 v1.7.0,1.4–1.6 的系统库在编译阶段必然失败,声明失真。 实现: - 新建 src/git_compat.hpp(GPL-3.0-or-later):全程序统一的 git2 头文件 入口,包含 后以 #ifdef GIT_OID_SHA256_HEXSIZE 探测实验头文件 分支(该宏只在实验构建的 oid.h 中定义;手动定义 GIT_EXPERIMENTAL_SHA256 会与库的 git_oid ABI 脱钩,故用结果宏探测而非原因宏),触发带指引的 #error。仓库内 4 处直接 #include (src/rawobj.hpp、 src/gitrepo.hpp、src/errmap.cpp、tests/unit/test_errmap.cpp)全部改为 包含 git_compat.hpp,守卫由此覆盖每一个接触到 git2 头的翻译单元。 - CMakeLists.txt:系统 libgit2 最低版本 1.4→1.7,注释注明依据 (git_repository_oid_type/git_oid_t 首见于 v1.7.0);vendored 固定 v1.9.7 不受影响。 - rfc/0000-gitmount.md §1.3(非目标)补记一条:SHA-256 对象格式仓库 (v0.1;需 libgit2 实验构建,编译期守卫先行拒绝),使规格口径与 能力一致。 - CHANGELOG.md 新增 [Unreleased]/Changed 三条对应记录。 rawobj 中参数化的 64 位分支(oid_type == GIT_OID_SHA1 ? 40 : 64 等)是 正确的未来铺垫,保留不动——待真正支持时删守卫 + 适配两处 fromstr + 补 CI 矩阵即可。 验证: - 负向:在 /tmp 定义 GIT_OID_SHA256_HEXSIZE=64 模拟实验头文件后包含 git_compat.hpp,g++ -std=c++17 编译失败并输出指引 #error;不定义时 编译通过。 - cmake -DGITMOUNT_WERROR=ON 全量构建 + ctest(unit + integration)全绿。 Closes #8 --- CHANGELOG.md | 19 +++++++++++++++++++ CMakeLists.txt | 7 +++++-- rfc/0000-gitmount.md | 2 ++ src/errmap.cpp | 2 +- src/git_compat.hpp | 17 +++++++++++++++++ src/gitrepo.hpp | 2 +- src/rawobj.hpp | 2 +- tests/unit/test_errmap.cpp | 2 +- 8 files changed, 47 insertions(+), 6 deletions(-) create mode 100644 src/git_compat.hpp diff --git a/CHANGELOG.md b/CHANGELOG.md index b96f654..0e1b491 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,25 @@ All notable changes to this project are documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [Unreleased] + +### Changed +- Building against a libgit2 compiled with `GIT_EXPERIMENTAL_SHA256` is + now rejected at compile time with an actionable `#error` message via + the new `src/git_compat.hpp` (the single include point for git2 + headers, probing `GIT_OID_SHA256_HEXSIZE`): the experimental build's + 3-argument `git_oid_fromstr` and larger `git_oid` ABI are unsupported + in v0.1, and the previous failure was a bare "too few arguments" at + two call sites with no guidance. +- The system libgit2 minimum is now 1.7 (was 1.4, a declaration that did + not match reality): `git_repository_oid_type` and the `git_oid_t` enum + first appeared in libgit2 v1.7.0, so 1.4–1.6 system libraries failed + to compile. The vendored path pins v1.9.7 and is unaffected. +- RFC 0000 §1.3 (non-goals) now records SHA-256 object-format + repositories as out of scope for v0.1 — they require an experimental + libgit2 build, which the compile-time guard rejects until properly + supported. + ## [0.0.4] - 2026-09-26 ### Fixed diff --git a/CMakeLists.txt b/CMakeLists.txt index f178ad1..71fe0d0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,14 +25,17 @@ find_package(PkgConfig REQUIRED) pkg_check_modules(FUSE3 REQUIRED IMPORTED_TARGET fuse3>=3.10) find_package(Threads REQUIRED) -# System libgit2 (>= 1.4) by default; a pinned vendored copy (v1.9.7, +# System libgit2 (>= 1.7) by default; a pinned vendored copy (v1.9.7, # static, network backends disabled) is used when the system version is # too old — e.g. Ubuntu 22.04 ships libgit2 1.1. The vendored path also # produces release binaries with one less runtime dependency. option(GITMOUNT_USE_SYSTEM_LIBGIT2 "Link the system libgit2 (pkg-config); OFF builds a pinned vendored copy" ON) if(GITMOUNT_USE_SYSTEM_LIBGIT2) - pkg_check_modules(LIBGIT2 REQUIRED IMPORTED_TARGET libgit2>=1.4) + # git_repository_oid_type (gitrepo.cpp) and the git_oid_t enum (rawobj) + # first appeared in libgit2 v1.7.0 — older system libraries fail to + # compile. The vendored path pins v1.9.7 and is unaffected. + pkg_check_modules(LIBGIT2 REQUIRED IMPORTED_TARGET libgit2>=1.7) set(GITMOUNT_LIBGIT2_TARGET PkgConfig::LIBGIT2) else() include(FetchContent) diff --git a/rfc/0000-gitmount.md b/rfc/0000-gitmount.md index 2d70fbe..c2386cd 100644 --- a/rfc/0000-gitmount.md +++ b/rfc/0000-gitmount.md @@ -101,6 +101,8 @@ commit 解析为一个 commit 对象, - 稀疏检出、部分克隆(partial clone)。 - macOS(osxfuse/macFUSE)与 BSD 移植(接口层预留抽象)。 - 工作区(index)视图、stash 视图。 +- SHA-256 对象格式仓库(v0.1;需 libgit2 实验构建,编译期守卫先行 + 拒绝)。 ## 2. 术语与要求用语 diff --git a/src/errmap.cpp b/src/errmap.cpp index 21b6163..3da8e8e 100644 --- a/src/errmap.cpp +++ b/src/errmap.cpp @@ -5,7 +5,7 @@ #include -#include +#include "git_compat.hpp" namespace gitmount { diff --git a/src/git_compat.hpp b/src/git_compat.hpp new file mode 100644 index 0000000..7f97a3b --- /dev/null +++ b/src/git_compat.hpp @@ -0,0 +1,17 @@ +// gitmount — read-only git-to-FUSE filesystem (RFC 0000). +// SPDX-FileCopyrightText: 2026 The gitmount authors +// SPDX-License-Identifier: GPL-3.0-or-later +// +// Unified libgit2 include point (issue #8): every translation unit that +// needs git2 headers includes this file instead of directly, so +// the compile-time guard below is enforced for the whole program — not +// just the TUs that happen to include themselves. +#pragma once + +#include + +#ifdef GIT_OID_SHA256_HEXSIZE +// 该宏仅在 libgit2 以 GIT_EXPERIMENTAL_SHA256 构建的头文件分支中定义。 +#error \ + "gitmount v0.1 does not support libgit2 built with GIT_EXPERIMENTAL_SHA256: the git_oid API/ABI differs (3-argument git_oid_fromstr, larger git_oid). See RFC 0000 §1.3." +#endif diff --git a/src/gitrepo.hpp b/src/gitrepo.hpp index 02bbd21..07bff87 100644 --- a/src/gitrepo.hpp +++ b/src/gitrepo.hpp @@ -17,7 +17,7 @@ #include #include -#include +#include "git_compat.hpp" namespace gitmount { diff --git a/src/rawobj.hpp b/src/rawobj.hpp index 7d34a26..2e3a1c2 100644 --- a/src/rawobj.hpp +++ b/src/rawobj.hpp @@ -18,7 +18,7 @@ #include #include -#include +#include "git_compat.hpp" namespace gitmount::rawobj { diff --git a/tests/unit/test_errmap.cpp b/tests/unit/test_errmap.cpp index b0ae296..96ab711 100644 --- a/tests/unit/test_errmap.cpp +++ b/tests/unit/test_errmap.cpp @@ -7,7 +7,7 @@ #include "errmap.hpp" -#include +#include "git_compat.hpp" using gitmount::git_to_errno;