Commit Graph

82350 Commits (fdb8395264f8971fc659c3d9f90b7f1b73e75145)

Author SHA1 Message Date
Junio C Hamano fdb8395264 Merge branch 'ps/ref-storage-format' into jch
The terminology regarding reference storage formats has been unified
across command-line options, environment variables, configuration
variables, and source code, standardizing on the phrase "ref storage
format" (e.g., `--ref-storage-format`, `'GIT_REF_STORAGE_FORMAT'`).
Additionally, the `--ref-storage-format` option has been updated to
accept payloads in the form `<format>://<payload>`.

* ps/ref-storage-format:
  setup: allow "--ref-storage-format=" to specify a payload
  setup: rename "init.defaultRefFormat" to "init.defaultRefStorageFormat"
  t: rename GIT_TEST_DEFAULT_REF_FORMAT
  setup: rename ref storage format environment variables
  setup: refactor how we configure the ref storage format
  refs: expose function to parse reference URIs
  help: rename "default-ref-format" to "default-ref-storage-format"
  builtin/rev-parse: rename "--show-ref-format" to "--show-ref-storage-format"
  builtin/submodule: rename "--ref-format=" to "--ref-storage-format="
  builtin/refs: rename "--ref-format=" to "--ref-storage-format="
  builtin/clone: rename "--ref-format=" to "--ref-storage-format="
  builtin/init: rename "--ref-format=" to "--ref-storage-format="
  parse-options: allow for hidden aliases
2026-09-17 12:54:15 -07:00
Junio C Hamano 608bf298b4 Merge branch 'ak/refs-files-root-ref-lock' into jch
The files backend has been updated to avoid unconditionally locking
the 'packed-refs' file when deleting a root ref (which are never
packed).

* ak/refs-files-root-ref-lock:
  refs/files: avoid packed-refs lock for root ref deletion
2026-09-17 12:54:14 -07:00
Junio C Hamano 10957a12d2 Merge branch 'jc/cocci-free-updates' into jch
Updates to Coccinelle semantic patches to correctly handle the
'FREE_AND_NULL()' macro and avoid generating broken transformations
for negated pointer checks.

* jc/cocci-free-updates:
  cocci: FREE_AND_NULL(E) is safe to call on NULL
  cocci: remove risky "if (!E) free(E)" conversion
2026-09-17 12:54:14 -07:00
Junio C Hamano e0cd7bd5b0 Merge branch 'kn/receive-report-hook' into jch
A new hook 'report' is added to 'git receive-pack', which runs after
reference updates and allows the server to filter or modify the
packet-line status report sent back to the client.

* kn/receive-report-hook:
  receive-pack: coccinelle fix
  hook: introduce the receive-report hook
  receive-pack: move message generation to separate function
  receive-pack: drop static variables to track report status version
  doc: add proc-receive hook info in 'git-receive-pack.adoc'
2026-09-17 12:54:14 -07:00
Junio C Hamano ba8defa938 Merge branch 'hn/history-squash' into jch
The experimental 'git history' command has been taught a new 'squash'
subcommand to fold a range of commits into a single commit, with any
descendants replayed on top.

* hn/history-squash:
  history: support editing squashed commit messages
  history: create squashed commits without editing
  history: protect branches when squashing a range
  history: validate squash revision ranges
  history: add skeleton for squash subcommand
  sequencer: share the squash message marker helpers and flags
  history: give commit_tree_ext a message template
  history: extract helper for a commit's parent tree
2026-09-17 12:54:13 -07:00
Junio C Hamano 1847b18a9b Merge branch 'ps/odb-alternates-at-creation' into jch
The setup of alternates has been deferred to object database
creation time during clone, which drops the unused ad-hoc alternate
writing API, simplifying the object database backend interface.

* ps/odb-alternates-at-creation:
  odb/source: remove the ability to write alternates
  builtin/clone: write alternates via `odb_create_on_disk()`
  odb/source: support writing alternates when creating the database
  builtin/clone: move setup of alternates for non-shared local clones
  builtin/clone: move setup of alternates for shared local clones
  builtin/clone: refactor handling of "--reference{,-if-able}"
  builtin/clone: move around `setup_reference()`
  builtin/clone: defer setup of the object database
  setup: split up concerns of `init_db()`
2026-09-17 12:54:13 -07:00
Junio C Hamano d38352cd43 A few more fixes before -rc2
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2026-09-17 09:48:17 -07:00
Junio C Hamano 3bbf43483e Merge branch 'yt/pathspec-negative-prefix'
The pathspec matching logic has been updated to avoid out-of-bounds
memory accesses when a negative pathspec is shorter than the common
prefix of positive pathspecs.

* yt/pathspec-negative-prefix:
  dir: preserve pathspec prefix optimization with leading excludes
  dir: do not apply prefix to negative pathspecs
2026-09-17 09:48:17 -07:00
Junio C Hamano 2a41443dc8 Merge branch 'tz/doc-pack-refs-and-refs-fixes'
Doc updates.

* tz/doc-pack-refs-and-refs-fixes:
  doc/refs: backtick-quote commands and options consistently
  doc/pack-refs: convert synopsis and options to new style
2026-09-17 09:48:17 -07:00
Yoichi NAKAYAMA 7b58375ab3 mailmap: normalize name for Yoichi NAKAYAMA
Normalize name formatting and map older formats to the canonical one.

Signed-off-by: Yoichi NAKAYAMA <yoichi.nakayama@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2026-09-17 09:43:13 -07:00
Junio C Hamano 12cb6293d6 Git 2.56-rc1
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2026-09-16 09:07:56 -07:00
Junio C Hamano d306f3f0d5 Merge branch 'ks/history-commit-leakfix'
The memory leak caused by not unusing the commit buffer returned by
repo_logmsg_reencode() during the rewording operation in 'git
history' has been plugged.

* ks/history-commit-leakfix:
  builtin/history: unuse the commit buffer after use
2026-09-16 09:04:56 -07:00
Junio C Hamano b6a7e39a8c Merge branch 'jc/rust-cargo-build-target'
When cross-compiling with Cargo, the output artifact is placed in a
target-specific subdirectory, which causes the build system to fail
to locate it.  The build system has been updated to respect the
'CARGO_BUILD_TARGET' environment variable.

* jc/rust-cargo-build-target:
  rust: respect CARGO_BUILD_TARGET when locating build output
2026-09-16 09:04:55 -07:00
Junio C Hamano 3a055174da Merge branch 'js/rust-in-windows-ci'
Update Windows CI build to support Rust.

* js/rust-in-windows-ci:
  ci(windows): build with Rust
  rust: pick a GCC-compatible Cargo target under MSYS2/MinGW
2026-09-16 09:04:55 -07:00
Junio C Hamano f0ef1b96a0 4th batch for -rc1
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2026-09-15 11:07:37 -07:00
Junio C Hamano 14bf3a43f8 Merge branch 'ps/odb-pluggable-fsck'
The consistency checks for the object database (fsck) have been
decoupled from the generic builtin implementation and moved into the
backend-specific object source layers, making them pluggable for
different object storage formats.

* ps/odb-pluggable-fsck:
  builtin/fsck: move loose object verification into the loose source
  builtin/fsck: move multi-pack index verification into the packed source
  builtin/fsck: move bitmap verification into the packed source
  builtin/fsck: move reverse index verification into the packed source
  builtin/fsck: move packfile verification into the packed source
  odb: provide infrastructure for pluggable fsck checks
  builtin/fsck: don't check alternates with "--no-full"
  builtin/fsck: de-globalize option handling
  builtin/fsck: merge `fsck_obj_buffer()` and `fsck_obj()`
  builtin/fsck: use `fsck_obj_buffer()` when checking loose objects
2026-09-15 11:07:37 -07:00
Junio C Hamano 4ee3b87aaa Merge branch 'ps/odb-stop-registering-in-memory-sources'
The mechanism to register in-memory alternate object sources has
been removed, as submodule object databases are now accessed
natively via their own repository structures.  This simplifies
object database management and prepares the codebase for migrating
alternate tracking into the files backend.

* ps/odb-stop-registering-in-memory-sources:
  odb: remove the ability to link sources ad-hoc
  t/helper: stop registering alternates in "ref-store" command
  t/helper: adapt read-midx to not link ad-hoc source anymore
  builtin/multi-pack-index: refuse unknown sources with "--object-dir="
  odb/packed: fix memory leaks when freeing source
  tmp-objdir: drop unused function to register alternate
  odb: remove infrastructure to register submodule sources
  builtin/grep: stop registering submodule ODB as source
  submodule-config: stop registering submodule sources
  submodule-config: stop using `the_hash_algo`
  submodule-config: remove uses of `the_repository`
  cache-tree: remove dependency on `the_repository`
  cache-tree: drop `the_repository` in `cache_tree_fully_valid()`
2026-09-15 11:07:36 -07:00
Junio C Hamano c78ed9e458 Merge branch 'js/win-cmake-use-ucrt64'
Windows build switches from MINGW64 to URCR64 runtime starting Git
2.56.0; switch the cmake based build at the same time.

* js/win-cmake-use-ucrt64:
  cmake(windows): accommodate for Git for Windows' migration to UCRT64
2026-09-15 11:07:36 -07:00
Junio C Hamano 6fc157174b Merge branch 'js/mingw-test-fixes-around-perl'
Correct tests that depend on Perl running on MinGW

* js/mingw-test-fixes-around-perl:
  t9129: skip UTF-8 tests on Windows
  t9700: accommodate for MSYS2 Perl reporting as `cygwin`
2026-09-15 11:07:36 -07:00
Todd Zullinger 995251109f doc/refs: backtick-quote commands and options consistently
The git-refs doc was converted to the synopsis style in 89be7d2774
(builtin/refs: add '--no-reflog' flag to drop reflogs, 2025-02-21).  The
commands and options were not backtick-quoted at that time.  84f3d6e11e
(doc lint: check that synopsis manpages have synopsis inlines,
2025-08-11) applied backtick-quotes to the existing commands and
options.

Subsequently, a number of commands and options were added without such
quoting, leaving the documentation rendered inconsistently.  Apply
backtick-quotes to all entries.

Signed-off-by: Todd Zullinger <tmz@pobox.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2026-09-15 09:22:16 -07:00
Todd Zullinger db06ca011e doc/pack-refs: convert synopsis and options to new style
Replace [verse] with [synopsis] in the SYNOPSIS block and remove
single-quote formatting from the command name.

Backtick-quote all option terms in the OPTIONS section via the included
pack-refs-options.adoc and convert the standalone placeholder _<branch>_
in prose.

Signed-off-by: Todd Zullinger <tmz@pobox.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2026-09-15 09:22:15 -07:00
Kaartic Sivaraam 0e75d17ff7 builtin/history: unuse the commit buffer after use
Every call to repo_logmsg_reencode() must be paired with a call to
repo_unuse_commit_buffer(), or we may leak an allocated buffer. We
have such a leak in "git history", which we can fix by adding an unuse
call.

The leak-checking tests don't detect this because we only allocate a
fresh buffer sometimes: when the message is reencoded, or when we had
to load it fresh from the odb (e.g., because the commit was parsed
from the commit graph rather than the object contents). But you can
see it by running:

  make SANITIZE=leak
  cd t
  GIT_TEST_COMMIT_GRAPH=1 ./t3451-history-reword.sh

Helped-by: Jeff King <peff@peff.net>
Signed-off-by: Kaartic Sivaraam <kaartic.sivaraam@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2026-09-15 09:21:00 -07:00
Junio C Hamano c090a2363c receive-pack: coccinelle fix
Let's not check the nullness of cmd->error_string_owned before
calling FREE_AND_NULL(cmd->error_string_owned).  It is cheap and
safe to call FREE_AND_NULL(variable) for a variable that has NULL
in it.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
2026-09-14 15:36:48 -07:00
Junio C Hamano 339ab2a8f1 3rd batch for -rc1
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2026-09-14 14:02:53 -07:00
Junio C Hamano 6c51b4c9ed Merge branch 'sa/rev-list-missing-only'
The git rev-list command has been augmented with a '--missing-only'
option that filters the output to only show missing objects,
stripping the leading '?' character and suppressing present objects,
which is useful when used in combination with '--missing=print' or
'--missing=print-info'.

* sa/rev-list-missing-only:
  rev-list: add --missing-only option to filter output
2026-09-14 14:02:53 -07:00
Junio C Hamano fb03713899 Merge branch 'ps/tune-rerere-gc'
"git maintenance" triggered "rerere gc" in unappropriate times and
interfered with "git rebase" etc. too much.  The conditions "rerere
gc" gets triggered have been tweaked.

* ps/tune-rerere-gc:
  builtin/maintenance: improve heuristic for "rerere gc"
  rerere: extract logic to determine whether entries are stale
2026-09-14 14:02:53 -07:00
Junio C Hamano 35026335e1 Merge branch 'hn/checkout-m-autostash-refine'
The autostash fallback in 'git checkout -m' has been refined to only
retry when there are local changes.  Additionally, a blank line now
visually separates autostash conflict advice from the subsequent
branch-switch message.

* hn/checkout-m-autostash-refine:
  checkout: separate autostash conflict advice from branch-switch message
  stash: reserve exit status 1 for conflicts
2026-09-14 14:02:53 -07:00
Junio C Hamano 88b068eb33 Merge branch 'wf/imap-send-draft'
The 'git imap-send' command has been taught to take the '--draft'
option to mark uploaded messages as drafts, which helps some email
clients render them properly for editing and sending.

* wf/imap-send-draft:
  imap-send: add --draft to set IMAP \Draft flag
2026-09-14 14:02:52 -07:00
Junio C Hamano e731c02bf7 Merge branch 'mm/lib-httpd-cgi-safe'
CGI helper scripts used by HTTP-related test scripts have been updated
to use atomic filesystem operations, preventing race conditions when
Apache handles concurrent requests.

* mm/lib-httpd-cgi-safe:
  t/lib-httpd: document writing concurrency-safe CGI helpers
  t/lib-httpd: make http-429 first-request check atomic
  t/lib-httpd: fix apply-one-time-script race under concurrent requests
2026-09-14 14:02:52 -07:00
Yannik Tausch b6f17686b2 dir: preserve pathspec prefix optimization with leading excludes
Directory walks use the common directory prefix of non-exclude
pathspec items to avoid scanning unrelated portions of the working
tree or index. Exclude items only remove paths from that candidate
set, so they do not need to widen the traversal.

When an exclude item is the first pathspec item, common_prefix_len()
fails to establish a comparison base and returns a zero-length prefix.
The result is correct, but Git unnecessarily traverses from a broader
starting point even when all non-exclude items share a directory.

Use the first non-exclude item as the comparison base and return its
string together with the prefix length, allowing callers to start from
the recovered directory prefix. Exclude matching continues to use full
paths, so this restores the optimization without changing which paths
are selected. Add a unit test covering an exclude item before two
non-exclude items with a common directory.

Signed-off-by: Yannik Tausch <dev@ytausch.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2026-09-14 07:57:47 -07:00
Yannik Tausch 16abad3360 dir: do not apply prefix to negative pathspecs
common_prefix_len() derives the common prefix solely from non-exclude
pathspec items. However, match_pathspec_with_flags() also passes that
prefix when matching exclude items.

This can produce incorrect results because that prefix does not
necessarily match an exclude item. For example, given non-exclude items
"a/b" and "a/c" and an exclude item "x/b", stripping the two-byte
prefix from both the pathname "a/b/m" and pattern "x/b" makes the
remaining strings match and incorrectly excludes the pathname.

If an exclude item is shorter than the prefix, match_pathspec_item()
instead advances item->match beyond its allocation and subtracts the
prefix from item->len, producing a negative matchlen. It then
dereferences the out-of-bounds pointer. If the resulting byte is not
NUL, matchlen is converted to size_t when passed to ps_strncmp(), which
may cause a much larger out-of-bounds read.

The out-of-bounds access can be reproduced with AddressSanitizer:

    make SANITIZE=address CFLAGS="-g -O0" git
    git init test &&
    cd test &&
    DIR=$(printf "a%.0s" {1..150}) &&
    mkdir -p "$DIR" &&
    touch "$DIR/f.txt" &&
    git add -A &&
    git commit -m test &&
    ../git ls-files -- "$DIR/" ":(exclude)xy"

Fix the bug by using a zero prefix when matching exclude items. Add
regression tests for both the deterministic incorrect match and the
shorter exclude item that causes the out-of-bounds access.

Signed-off-by: Yannik Tausch <dev@ytausch.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2026-09-14 07:57:47 -07:00
Ariel Keselman d8e4585822 refs/files: avoid packed-refs lock for root ref deletion
Deleting a root ref queues a packed-ref transaction in the files
backend, even though root refs cannot be packed. For example, holding
.git/packed-refs.lock makes "git update-ref --no-deref -d AUTO_MERGE"
fail, whether or not AUTO_MERGE exists.

This also affects post-commit cleanup, which deletes AUTO_MERGE after
updating HEAD. In a linked worktree with read-only shared metadata,
commit succeeds but cleanup reports a packed-refs.lock error. Deleting
CHERRY_PICK_HEAD and REVERT_HEAD is affected as well.

Skip the packed transaction for root-ref deletions. Keep loose-ref
locking and packed-ref deletion for other refs unchanged.

Signed-off-by: Ariel Keselman <skariel@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2026-09-14 07:37:00 -07:00
Junio C Hamano 3699d22b59 2nd batch for -rc1
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2026-09-13 21:53:31 -07:00
Junio C Hamano 584621d0b0 Merge branch 'ta/lint-gitlink-older-perl-fix'
The development helper script to lint gitlink references in the
documentation has been updated to avoid a newer Perl regular
expression syntax that breaks on older Perl versions.

* ta/lint-gitlink-older-perl-fix:
  lint-gitlink: don't use empty lower bound in .{0,8}
2026-09-13 21:53:30 -07:00
Junio C Hamano d7e8ff8565 Merge branch 'jc/history-missing-tree-errorfix'
Running "git history" in a corrupt repository can (unsurprisingly)
segfault when a necessary tree object is not found.

* jc/history-missing-tree-errorfix:
  history: do not dereference NULL when parent tree is missing
2026-09-13 21:53:30 -07:00
Junio C Hamano 994e80a373 Merge branch 'as/cherry-pick-no-commit-doc'
The documentation for 'git cherry-pick' has been updated to clarify
that the '--no-commit' option intentionally skips setting the
'CHERRY_PICK_HEAD' ref.  A test has also been added to ensure this
behavior holds even when the operation stops for conflicts.

* as/cherry-pick-no-commit-doc:
  doc: cherry-pick: note --no-commit skips CHERRY_PICK_HEAD
  t3507: check no CHERRY_PICK_HEAD after conflicting --no-commit
2026-09-13 21:53:30 -07:00
Junio C Hamano 7c051fe07a Merge branch 'kh/doc-datamodel'
The gitdatamodel documentation page has been linked from a handful
of key documentaiton pages.

* kh/doc-datamodel:
  doc: datamodel: link to the glossary
  doc: glossary: link four of the terms to gitdatamodel(7)
  doc: git: link to the gitdatamodel(7) tutorial
  doc: git: list gitdatamodel(7) as a concept guide
2026-09-13 21:53:30 -07:00
Junio C Hamano 223518fefd Merge branch 'tn/fetch-pack-trace-packfile-uri'
The process of downloading packfile URIs in protocol v2 has been
instrumented with a Trace2 region.  This visibility allows tracking
the cumulative time spent downloading external packs and the number
of advertised URIs without emitting a separate event per pack.

* tn/fetch-pack-trace-packfile-uri:
  fetch-pack: trace packfile URI downloads
2026-09-13 21:53:30 -07:00
Junio C Hamano d5cd54c966 Merge branch 'jc/pathspec-match-const'
Two members in "struct pathspec_item" were of type "char *", but
nobody updated the string through these pointers.  They have been
made "const char *" instead.

* jc/pathspec-match-const:
  pathspec: match and original in pathspec_item are const
2026-09-13 21:53:29 -07:00
Junio C Hamano 830d7476f0 Merge branch 'jk/submodule-error-leak'
The error path in 'git submodule--helper' has been updated to plug a
memory leak when a repository handle could not be obtained,
leveraging an updated idempotent repo_clear().

* jk/submodule-error-leak:
  submodule--helper: free URL when repository setup fails
  repository: make repo_clear() idempotent
2026-09-13 21:53:29 -07:00
Junio C Hamano a334b7ec86 Merge branch 'en/no-amend-during-conflicts'
Teach 'am', 'revert', and 'rebase' that running 'commit --amend' or a
partial 'commit <paths>' makes no sense during operations that stop
and return control to the user to resolve conflicts left in the
working tree, just like 'cherry-pick' and 'merge' do.

* en/no-amend-during-conflicts:
  commit: refuse partial commits during conflict resolution
  commit: refuse to amend during conflict resolution
  commit: reword the empty-commit rebase amend error
  commit: allow a partial commit when a rebase pick becomes empty
  commit: clarify FROM_REBASE_PICK and is_from_rebase() names
2026-09-13 21:53:29 -07:00
Junio C Hamano cee3798cb4 Merge branch 'bc/maintenance-doc-markup-fix-for-asciidoc'
Mark-up fix for 'git maintenance' documentation pages.

* bc/maintenance-doc-markup-fix-for-asciidoc:
  doc: fix conjoined maintenance strategies in git-config(1)
2026-09-13 21:53:29 -07:00
Junio C Hamano a449fe1123 Merge branch 'jk/ci-use-system-asciidoctor'
The CI script to install dependencies for the documentation build
has been updated to install asciidoctor directly via the system
package manager instead of pinning to an older version via gem.
Additionally, an obsolete variable used for retired Azure Pipelines
environments has been removed.

* jk/ci-use-system-asciidoctor:
  ci: use system asciidoctor
2026-09-13 21:53:28 -07:00
Johannes Schindelin 1cd6b7de52 cmake(windows): accommodate for Git for Windows' migration to UCRT64
Git for Windows needs to ship with a lot of Unix tools that Git takes
for granted, such as `sed`, `awk`, a C compiler and a Unix shell, just
to name a few. In Git for Windows, these are provided by the MSYS2
project.

Part of these tools (such as `bash.exe`) use a POSIX emulation layer
("MSYS2 runtime", a friendly fork of the Cygwin runtime), but others
target a native Win32 toolchain, e.g. `git.exe`. There are multiple
flavors of that toolchain, and historically Git for Windows used MINGW64
on x64 Windows. This toolchain uses the old MSVC runtime, and therefore
the MSYS2 project deprecated it.

As a consequence, Git for Windows switches to UCRT64 with v2.56.0. That
flavor still uses GCC to compile native Win32 binaries, but targets the
Universal C Runtime ("UCRT"). Internally, this means that the new
`git.exe` is installed into a new prefix, `/ucrt64/`, whereas the old
`git.exe` was installed into `/mingw64/`.

A recently-upstreamed commit hard-codes this expectation even into the
CMake-based build, so that the built `git.exe` "knows where it lives"
and can ensure that the tools it expects on the `PATH` are found.

Naturally, this hard-coded MINGW64 needs to change to UCRT64 now, too.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2026-09-13 16:01:18 -07:00
Johannes Schindelin aa40ca0217 t9129: skip UTF-8 tests on Windows
The assumption of this test is that Perl and Git have the same idea how
to perform encoding conversions.

However, in Git for Windows, Git is a native Win32 program, and such
programs have a very different concept of encodings (called "Code
Pages", and they are not controlled via environment variables at all),
whereas the Perl interpreter used in Git for Windows is a pseudo-Unix
one that uses the MSYS2 runtime (which _does_ try very much to abide by
Unix' `LC_ALL` and friends, and totally ignores Windows' current or
active code pages).

As such, these test cases _cannot_ work with Git for Windows. So let's
just skip them on that platform.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2026-09-13 15:59:08 -07:00
Johannes Schindelin 8fff84c417 t9700: accommodate for MSYS2 Perl reporting as `cygwin`
As of a year or two ago, there is this push to align MSYS2 more closely
with Cygwin, so as to benefit from a closer collaboration. Part of that
is that the triplet `x86_64-pc-cygwin` is used nowadays, whereas it had
been `x86_64-pc-msys` previously. Likewise, Perl now reports `$^O` as
`cygwin` instead of `msys`.

The Perl module test used `msys` as tell-tale when to accommodate for a
native Windows version of `git.exe` which would report absolute
_Windows_ paths rather than those pseudo-Unix paths. We cannot use that
tell-tale anymore, and we also cannot adjust it to `cygwin` because that
would break in Cygwin (where `git.exe` reports absolute pseudo-Unix
paths).

Let's use the environment variable `MSYSTEM` instead (being mindful that
the `MSYSTEM=MSYS` variant would _also_ reflect a setup where `git.exe`
won't report absolute _Windows_ paths).

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2026-09-13 15:59:08 -07:00
Johannes Schindelin 86909a94db ci(windows): build with Rust
The Windows runners used by Git's GitHub workflow's `windows-build` job
ship `rustup` plus a `*-pc-windows-msvc` default toolchain (see
https://github.com/actions/runner-images/blob/main/images/windows/Windows2022-Readme.md
and
https://github.com/actions/partner-runner-images/blob/main/images/arm-windows-11-image.md),
but no precompiled `std` for `*-pc-windows-gnu` or
`*-pc-windows-gnullvm`. With the Makefile now picking a GCC-compatible
target triple based on `$(MSYSTEM)`, the build step needs that
precompiled `std` to be installed before invoking `make`, otherwise
`cargo build --target <triple>` fails to find a usable `std` for the
chosen target.

Add a step between the SDK setup and the `make` invocation that selects
the matching triple from `$MSYSTEM` (which
`git-for-windows/setup-git-for-windows-sdk` exports for every subsequent
step) and runs `rustup target add` for it. The mapping mirrors what
`config.mak.uname` derives from `$(MSYSTEM)` and `$(HOST_CPU)`, just
enumerated explicitly here since CI has direct knowledge of which MSYS2
subsystems the matrix actually exercises (`CLANGARM64` for the ARM64
runner, `MINGW64` for the x86_64 runner). Technically, we only need to
handle MINGW64 at present, but the switch to UCRT64 is imminent, and the
other case arms serve as a very fine documentation of what people should
do for other MSYSTEM values.

For a `staticlib` crate-type `cargo build` does not invoke an external
linker, so no further toolchain components (e.g. the `gnullvm` LLVM
linker) need to be installed; `rustup target add` alone is sufficient.

Assisted-by: Claude Opus 4.7
Helped-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2026-09-13 15:48:09 -07:00
Johannes Schindelin ce6f9ffaa7 rust: pick a GCC-compatible Cargo target under MSYS2/MinGW
When Git is built under MSYS2/MinGW with Rust support enabled, the
Makefile expects `cargo build` to drop a `target/release/libgitcore.a`
that is linkable by the same MinGW GCC used for every other object. With
Rust installed via `rustup` (the way it ships on the GitHub-hosted
`windows-2022` and `windows-11-arm` runners that build git/git and its
forks), the default toolchain targets the MSVC ABI; cargo then writes
`target/release/gitcore.lib` instead, which the MinGW `ld.exe` cannot
consume:

    LINK git-shell.exe
    D:\git-sdk-64-minimal\mingw64\bin/ld.exe: cannot find target/release/libgitcore.a: No such file or directory
    collect2.exe: error: ld returned 1 exit status

See https://github.com/microsoft/git/actions/runs/27341625000 for a
full example log.

Let's define the correct target, using the `CARGO_BUILD_TARGET` variable
that will be picked up by Rust, see
https://dirname.github.io/rust-std-doc/cargo/reference/environment-variables.html#:~:text=CARGO%5FBUILD%5FTARGET

Re-use (and fix) the existing `HOST_CPU` variable to determine the
correct value. Avoid relying on environment variables that are simply
not defined in Git for Windows' minimal SDK that Git uses in its CI
runs.

Assisted-by: Claude Opus 4.7
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2026-09-13 15:48:08 -07:00
Junio C Hamano 32814b69d0 cocci: FREE_AND_NULL(E) is safe to call on NULL
Just like we allow calling free(E) without checking if E is not
NULL, it is safe to call FREE_AND_NULL(E) unconditionally.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
2026-09-11 15:25:28 -07:00
Junio C Hamano d870565117 cocci: remove risky "if (!E) free(E)" conversion
The current cocci patches try to convert

	if (!E)
		free(E);

into an unconditional call to free(E), with the rationale

    cocci: detect useless free(3) calls

    Add a semantic patch for removing checks that cause free(3) to only be
    called with a NULL pointer, as that must be a programming mistake.

which came from ec6cd14c7a (cocci: detect useless free(3) calls,
2017-02-11).

Leaving _something_ in ALL.patch output to draw programmers'
attention is a good thing, but this changes a piece of code that is
originally a no-op to do something else, which may be even worse.

We could change it to

	if (!E)
		BUG("free(E) is certainly not what we meant to write");

to force programmers to think.  But it probably is safer to just
rewrite one form of no-op into a simpler form of no-op.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
2026-09-11 15:25:28 -07:00