Repository navigation
Conversation
When cURL follows a redirect, it calls the CURLOPT_HEADERFUNCTION for each header received including ones from a redirect. http_request() sets fwrite_wwwauth() as the header function, which will record the wwwauth[] entries for the last step in the redirection chain. However, when http_request_recoverable() sees that cURL followed a redirect, it attempts to update the credentials for the request from the new URL using credential_from_url(). The first thing that does is call credential_clear(), which clears everything including wwwauth_headers. If the new URL should use a credential helper rather than credentials embedded in the URL, this loses the list of authentication methods that the server provided in the redirect. The WWW-Authenticate challenge is not derived from the URL; it is populated from the server's response, and after a redirect it describes how to authenticate to the redirect target and it needs to survive the URL update so that credential helpers can know which authentication methods are allowed. Add a new credential_update_url() that wraps credential_from_url() and preserves wwwauth_headers specifically. Use SWAP() to avoid having to copy the whole strbuf. Signed-off-by: Aaron Plattner <aplattner@nvidia.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
The ability to provide a commit message for git commit --fixup and its
variations is limited:
* Plain --fixup only allows using the -m flag
* The amend/reword --fixup variants only allow supplying the message
using an editor
For amend/reword, the -m and -F flags are rejected: -m is caught by a
die() in prepare_to_commit(), and -F is caught by
die_for_incompatible_opt4() which groups -F with --fixup as mutually
exclusive. This makes these modes poorly suited for non-interactive
workflows -- notably when using AI coding agents.
When support to use the -m option was introduced in [1] it was noted
that there could be support for other options but at the time the use
case was deemed too niche. Later, when the amend suboption was
introduced in [2] -m support for amend fixups was discussed but not
pursued, and -F was already caught by the higher-layer incompatibility
check grouping it with --fixup.
The rejections of these options hark back to when --fixup was
introduced in [3] and as noted in [1] -- there's nothing inherently
preventing support for them. The current patchwork of which flags
work with which --fixup variants has no strong logic to it, and
allowing all of them simplifies both the code and the interface.
Allow -m and -F to supply the message body for all --fixup variations,
mirroring the flow of a regular commit. -c and -C, which are blocked
by the same incompatibility check, are handled in the next commit.
1. 30884c9 (commit: add support for --fixup <commit> -m"<extra
message>", 2017-12-22)
2. 494d314 (commit: add amend suboption to --fixup to create amend!
commit, 2021-03-15)
3. d71b8ba (commit: --fixup option for use with rebase --autosquash,
2010-11-02)
Helped-by: Junio C Hamano <gitster@pobox.com>
Suggested-by: Phillip Wood <phillip.wood123@gmail.com>
Signed-off-by: Erik Cervin-Edin <erik@cervined.in>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
The fixup code path in prepare_to_commit() only knows how to take a message body from -m or -F. Now that the previous commit allows -m and -F for all --fixup variations, -c/-C are the odd ones out. Teach the fixup path to look up the ref given to -c/-C and seed its message when preparing to amend the commit, mirroring what --fixup=amend does when no message source is given. With this in place, -m/-F/-c/-C all behave consistently across the plain, amend, and reword --fixup forms. The incompatibility check grouping -C, -c, and --fixup can go away entirely, as -C and -c are already rejected together by the check that groups them with -m and -F. Helped-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Erik Cervin-Edin <erik@cervined.in> Signed-off-by: Junio C Hamano <gitster@pobox.com>
keyring_get() searches with SECRET_SEARCH_LOAD_SECRETS, then passes
secret_item_get_secret() of the first match unchecked to
secret_value_get_text() and secret_value_unref(). As libsecret
documents, that secret can be NULL: the search does not load secrets
of locked items, such as when SECRET_SEARCH_UNLOCK fails to unlock
them, and it ignores errors from loading secrets. The GNOME keyring
daemon also silently leaves out of its reply any item which is locked
or which was deleted after the search matched it, e.g. by a concurrent
"credential erase" from another git process. We then print
secret_value_get_text: assertion 'value' failed
secret_value_unref: assertion 'value != NULL' failed
before git falls back to prompting for the password.
We could keep the flag and load the secret explicitly only when it is
NULL, but SECRET_SEARCH_LOAD_SECRETS is not part of the search call:
libsecret implements it as a separate GetSecrets D-Bus call after
SearchItems. Drop the flag and instead always load the one secret we
use with secret_item_load_secret_sync(), which reports errors. This
takes as many D-Bus calls as before, and leaves a single code path
that runs every time, rather than a fallback that only runs in a rare
race. libsecret's own secret-tool also loads each secret explicitly
after searching.
An inaccessible item now produces a useful error message instead of
the assertion failures, and git still falls back to prompting. The
race needs a concurrent process or a locked keyring to trigger, so
there is no test.
Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Scripts frequently need to find the root directory of a repository's working tree. Currently, this requires using `git rev-parse --show-toplevel` or inferring it from other repository information. Introduce `path.toplevel.absolute` and `path.toplevel.relative` keys to `git repo info`. This allows scripts to retrieve the top-level working tree path in a predictable, strictly formatted manner without relying on `rev-parse`. If requested in a bare repository where no working tree exists, the command returns an empty string. Mentored-by: Justin Tobler <jltobler@gmail.com> Mentored-by: Lucas Seiki Oshiro <lucasseikioshiro@gmail.com> Signed-off-by: K Jayatheerth <jayatheerthkulkarni2005@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
`get_superproject_working_tree()` currently uses `xgetcwd()` to determine the repository whose superproject should be checked. This is incorrect when `--git-dir` points to a repository different from the one associated with the current working directory. In that case, the current working directory may cause the function to return the wrong superproject or an empty result. Pass the `repository` to `get_superproject_working_tree()` so that the superproject is determined from the repository being inspected rather than the current working directory. Mentored-by: Justin Tobler <jltobler@gmail.com> Mentored-by: Lucas Seiki Oshiro <lucasseikioshiro@gmail.com> Signed-off-by: K Jayatheerth <jayatheerthkulkarni2005@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Scripts working in multi-repository setups often need to identify the top-level working tree of a superproject from within a submodule. Currently, this is only exposed via `git rev-parse --show-superproject-working-tree`. Introduce `path.superproject-root.absolute` and `path.superproject-root.relative` keys to `git repo info`. This exposes the core submodule context via a scriptable config-like key using standard format rules. If requested when not inside a submodule, the command returns an empty string. Mentored-by: Justin Tobler <jltobler@gmail.com> Mentored-by: Lucas Seiki Oshiro <lucasseikioshiro@gmail.com> Signed-off-by: K Jayatheerth <jayatheerthkulkarni2005@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Hooks are an integral part of a repository's configuration and are commonly used by tooling to automate repository-specific workflows. Currently, scripts typically retrieve the hooks directory by invoking `git rev-parse --git-path hooks`. Introduce `path.hooks.absolute` and `path.hooks.relative` keys to `git repo info`. This exposes the hooks directory as a scriptable config-like key using standard format rules, allowing scripts to retrieve it through the same interface as other repository path information. Mentored-by: Justin Tobler <jltobler@gmail.com> Mentored-by: Lucas Seiki Oshiro <lucasseikioshiro@gmail.com> Signed-off-by: K Jayatheerth <jayatheerthkulkarni2005@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
The repository index is a fundamental component used by Git and related tooling to track the working tree state. Scripts that interact with the index currently retrieve its location by invoking `git rev-parse --git-path index`. Introduce `path.index.absolute` and `path.index.relative` keys to `git repo info`. This exposes the index file location as a scriptable config-like key using standard format rules, allowing scripts to retrieve it through the same interface as other repository path information. Mentored-by: Justin Tobler <jltobler@gmail.com> Mentored-by: Lucas Seiki Oshiro <lucasseikioshiro@gmail.com> Signed-off-by: K Jayatheerth <jayatheerthkulkarni2005@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
The repository grafts file specifies alternate parent relationships for commits and may be used by repository tooling that needs to inspect or manage grafts. Scripts currently retrieve its location by invoking `git rev-parse --git-path info/grafts`. Introduce `path.grafts.absolute` and `path.grafts.relative` keys to `git repo info`. This exposes the grafts file location as a scriptable config-like key using standard format rules, allowing scripts to retrieve it through the same interface as other repository path information. Mentored-by: Justin Tobler <jltobler@gmail.com> Mentored-by: Lucas Seiki Oshiro <lucasseikioshiro@gmail.com> Signed-off-by: K Jayatheerth <jayatheerthkulkarni2005@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Scripts sometimes need the path from the repository's working tree root to the current working directory. While this information can be derived through existing Git commands, `git repo info` does not currently expose it as a scriptable key. Introduce the `path.git-prefix` key to `git repo info`. The key returns the path from the working tree root to the current working directory, returning the empty string when invoked from the working tree root. Mentored-by: Justin Tobler <jltobler@gmail.com> Mentored-by: Lucas Seiki Oshiro <lucasseikioshiro@gmail.com> Signed-off-by: K Jayatheerth <jayatheerthkulkarni2005@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Scripts sometimes need the relative path from the current working directory to the repository's working tree root (cdup). While this information can be retrieved through `git rev-parse --show-cdup`, `git repo info` does not currently expose it as a scriptable key. Introduce the `path.cdup` key to `git repo info`. The key returns the path from the current working directory to the root of the working tree, returning the empty string when invoked from the working tree root. Mentored-by: Justin Tobler <jltobler@gmail.com> Mentored-by: Lucas Seiki Oshiro <lucasseikioshiro@gmail.com> Signed-off-by: K Jayatheerth <jayatheerthkulkarni2005@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
When the monitor sends a trivial response ("/"), for example after
the daemon restarted or lost events, refresh_fsmonitor() marks every
index entry dirty, which is saved in the index. For the untracked
cache it only clears the in-memory flag use_fsmonitor. The valid bits
of the cached directories are saved unchanged, although nothing
checks them anymore: valid_cached_dir() does not lstat() a valid
directory while the monitor is trusted.
A command that does not scan for untracked files, like "git add" or
"git checkout", therefore saves the new token next to stale valid
bits, and every later "git status" trusts them. A directory removed
in the meantime keeps its untracked files listed, or, when its own
entry is invalid, makes every run print
```
warning: could not open directory 'sub/': No such file or directory
```
Check every cached directory against its stat data before the cache
is saved next to such a token, as valid_cached_dir() does without a
monitor, and invalidate the ones that changed or disappeared. Doing
this at write time skips commands that do not write the index, and
sparse index writes, which drop the fsmonitor extension anyway.
The cost is one lstat() per cached directory, once per trivial
response.
Signed-off-by: Ilia K <ki.stfu@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
The `get_path_prefix()` function uses a `do ... while()` loop that unconditionally decrements the `size_t` index variable before checking the loop condition. When that variable is 0 on entry, the decrement wraps to `SIZE_MAX`, and `path[SIZE_MAX]` is an out-of-bounds read. The current caller (`write_tar_entry()`) only invokes this function when `pathlen > sizeof(header.name)` i.e. when `pathlen` is at least 100. Therefore, the bug is unreachable in practice. However, the function's interface accepts arbitrary pathlen and maxlen values, and a future caller or a maxlen of 0 could trigger the wrap, so let's add a check for that. Pointed out by Coverity. Assisted-by: Claude Opus 4.6 Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
The `fwrite_sha1_file()` function tracks the number of bytes written via an `int` variable, but the total size to write is of type `size_t`. When the HTTP response body exceeds INT_MAX (~2GB), this causes an overflow and a heap under-read, then writes that data to the local object file. The hash check afterward would reject the corrupt object (so no bad data enters the object store), but the under-read itself could leak adjacent heap contents to the temporary file. In practice this is unlikely because curl delivers data in small chunks (typically 16KB per callback invocation), so in practice, the total size is far below INT_MAX in a single call. However, the function interface accepts arbitrary sizes, and the accumulation across the loop means that the `int` variable grows across calls within a single invocation, not across callbacks. Change the type from `int` to `size_t` to match the type of the total size. This is a hardening fix: the attack surface (a malicious HTTP server triggering a >2GB single-callback delivery) is theoretical under normal curl configurations, but the type mismatch is a genuine defect. Pointed out by Coverity. Assisted-by: Claude Opus 4.6 Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Both the `read_in_full()` as well as the `write_in_full()` function accumulate the bytes transferred count in a variable of type `ssize_t`, but accept a `size_t` count parameter. When count exceeds `SSIZE_MAX`, that total count overflows after processing `SSIZE_MAX` bytes, producing a negative return value that callers interpret as an error (or worse, a small positive value after further wrapping). In practice, git never passes such large counts because file sizes and buffer allocations are bounded well below SSIZE_MAX on all target platforms. The POSIX specification for `read()` and `write()` also limits single operations to `SSIZE_MAX` bytes, and git's `xread()`/`xwrite()` wrappers further clamp to `MAX_IO_SIZE`. But the accumulation in the `*_in_full()` wrappers means that even with per-call clamping, total can exceed `SSIZE_MAX` when count does. Reject a total count that exceeds the range of `ssize_t` upfront with `EINVAL` rather than silently producing wrong return values, matching the POSIX convention for invalid arguments. Pointed out by Coverity. Assisted-by: Claude Opus 4.6 Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
`unsigned_mult_overflows()` does not cover signed arithmetic, but types such as `time_t` can be signed or unsigned. Add signed and type-generic guards so callers can check multiplication overflow in either case. Overflow depends on the product type selected by C's usual arithmetic conversions. Products equal to the signed minimum are representable and must not be rejected. Assisted-by: Claude Opus 4.6, GPT-6 and GPT-6.1 Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
The `approxidate_alpha()` function multiplies a time unit length (e.g., 604800 for weeks) by a user-supplied number to compute a time offset in seconds. Both operands are `int`, and the product is passed to `update_tm()` as `time_t`. For inputs like "99999 weeks ago", the int multiplication overflows (604800 * 99999 is roughly 60 billion, far beyond `INT_MAX`), producing a wrapped value that results in a wrong date. Use the checked `time_t` multiplication so oversized products do not overflow or wrap around. On platforms where `time_t` is unsigned (and where the pre-processor allows us to determine this fact), reject counts that are too large and report a parse error. Narrowing them first could otherwise produce negative or truncated values that become bogus offsets. Leave signed `time_t` count parsing unchanged. Pointed out by Coverity. Assisted-by: Claude Opus 4.6 and GPT-6.1 Sol Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
The current explanation has the following issues: - Says detached HEAD state is useful but doesn't explain why - Takes many paragraphs before explaining what detached HEAD state is - It's common for users to accidentally end up in detached HEAD state, but it doesn't explain why that might happen - One of the UI improvements in `git switch` is to make it harder to detach accidentally, but that isn't advertised. See 7968bef (switch: only allow explicit detached HEAD, 2019-03-29) - Too many confusing diagrams Write a new explanation addressing these issues, and put it in a standalone guide so that we can easily reference it from advice ("see `git help detached-head`"). The result is a shorter guide that covers more material. The framing that "Git considers commits that aren't on a branch/other reference to be garbage" is taken from Steve Klabnik's tutorial https://steveklabnik.github.io/jujutsu-tutorial/branching-merging-and-conflicts/anonymous-branches.html. It's funny and it's consistent with the way Git uses the term "garbage collection". Co-authored-by: Marie Claire LeBlanc Flanagan <hello@marieflanagan.com> Signed-off-by: Marie Claire LeBlanc Flanagan <hello@marieflanagan.com> Signed-off-by: Julia Evans <julia@jvns.ca> Signed-off-by: Junio C Hamano <gitster@pobox.com>
The only "mktree --batch" test in t1010 is the one checking that it survives a concurrent repack. Nothing covers basic batch mode, which is how the leak fixed in 6272f3b (mktree: plug per-tree leak in --batch mode, 2026-08-29) went unnoticed. Add a few tests for it. Two trees in one batch should get the same IDs as running plain "mktree" on each, a trailing blank line should not add an extra tree, -z input should work, and a tree that names a missing object should make mktree die after printing the trees before it. While at it, check that a blank line is rejected without --batch. One test feeds two blank lines in a row and expects an empty tree in between. That is what mktree does today, but the documentation says trees are separated by "a single blank line", so I am not sure it is intended. The test records the current behaviour. Suggested-by: Jeff King <peff@peff.net> Signed-off-by: Roger Koranteng <rogerkorantenng@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
The `repo_rerere()` function is the only function in "rerere.h" that does not have a `rerere_` prefix. And while it does indeed receive a repository as first parameter, that's not a good-enough reason to give it a `repo_` prefix. Rename the function to just `rerere()`. Move around and extend documentation of this function to better explain what it does. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Our modern coding guidelines say that flags should typically be passed around as enums so that it becomes trivial to see what kind of flags are expected. Adapt the rerere flags accordingly and document them. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
There are a couple of references to `the_repository` in git-rerere(1). As that command cannot run outside of a repository these references can be trivially replaced by the repository that's passed in as parameter to `cmd_rerere()`. We don't have to worry about the repository being `NULL` when called with "-h", either, as there are no references to the repo before we call `parse_options()`. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
The git-rerere(1) command has a "--[no-]rerere-autoupdate" flag. If passed, we explicitly enable or disable recording clean merge resolutions that are staged in the index. This flag only matters to git-rerere(1) when not executed with any subcommand, but we also forward the flag to `git rerere status` and `git rerere diff`. This is mostly harmless as we would ignore those flags anyway, but it makes subsequent refactorings harder to understand. Prepare for these refactorings by not using the flag in those subcommands anymore. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
The git-rerere(1) command has its own, home-grown implementation of
subcommands. Of course this implementation is inconsistent with how
subcommands typically work:
- Options from other subcommands apply to each other.
- We don't have proper usage strings.
- Running `git rerere <subcmd> -h` doesn't print the options that are
supported by that subcommand, but instead it just prints the help of
git-rerere(1) itself.
A subsequent commit will thus introduce proper subcommands as supported
by our parse-options subsystem. Refactor the "forget" subcommand to use
parse-options as a preparatory step. The other commands will follow in
subsequent commits until all of them have been converted, and then we
switch over to `OPT_SUBCOMMAND()`.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
As explained in a preceding commit, a subsequent commit will introduce proper subcommands as supported by our parse-options subsystem. Refactor the "clear" subcommand to use parse-options as a preparatory step. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
As explained in a preceding commit, a subsequent commit will introduce proper subcommands as supported by our parse-options subsystem. Refactor the "status" subcommand to use parse-options as a preparatory step. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
As explained in a preceding commit, a subsequent commit will introduce proper subcommands as supported by our parse-options subsystem. Refactor the "remaining" subcommand to use parse-options as a preparatory step. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
As explained in a preceding commit, a subsequent commit will introduce proper subcommands as supported by our parse-options subsystem. Refactor the "diff" subcommand to use parse-options as a preparatory step. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
The 'libsecret' credential helper has been updated to explicitly load secrets instead of relying on the search flag, preventing assertion failures when items are concurrently deleted or locked. * dm/libsecret-explicit-load: credential/libsecret: load secrets explicitly
The manual page linter has been extended to ensure that concept guides and interface manuals listed in the documentation makefile are also properly featured in the command list. * ta/command-list-guides-sync-lint: lint-docs: check the guide list in command-list.txt command-list.txt: add gitformat-loose(5) and gitpacking(7)
gitgitgadget
Bot
force-pushed
the
seen
branch
from
November 6, 2026 04:52
1d418d1 to
3de8ebe
Compare
Author
|
/submit |
|
Error: Ignoring PR with empty title and/or body |
Use memset() to initialize repository configuration values to zero, removing the need for explicit zero and NULL assignments. Keep non-zero defaults initialized separately. Signed-off-by: Joy Gundu <soniqjjj@gmail.com>
Joiejoie1
force-pushed
the
repo-zero-initialize-config-values
branch
from
November 6, 2026 11:04
f9aef8a to
842b6ce
Compare
Author
|
/submit |
|
Submitted as pull.2298.git.1793966368860.gitgitgadget@gmail.com To fetch this version into To fetch this version to local tag |
|
Patrick Steinhardt wrote on the Git mailing list (how to reply to this email): On Fri, Nov 06, 2026 at 11:59:28AM +0000, Joy via GitGitGadget wrote:
> From: Joy Gundu <soniqjjj@gmail.com>
>
> Use memset() to initialize repository configuration values to
> zero, removing the need for explicit zero and NULL assignments.
> Keep non-zero defaults initialized separately.
>
> Signed-off-by: Joy Gundu <soniqjjj@gmail.com>
> ---
> [Outreachy] repo: zero-initialize configuration values
So I guess this patch was split out because of our recent push to not
make further changes to `repo_config_values()`? If so, it would have
made sense to point that out explicitly both here, and in the original
thread that you've sent.
In any case, the patch is obviously correct and is a good improvement in
my opinion. So this looks good to me, thanks.
Patrick |
|
Joie Joie wrote on the Git mailing list (how to reply to this email): Thanks, Patrick.
Yes, that was my reason for splitting the patch. It only changes how
the existing configuration values are initialized and doesn't add a
new struct member, so I felt it could be reviewed separately from the
changes affected by the recent direction.
You're right, though. I should have explained that more clearly in the
patch description and the original thread. I'll make sure to include
that context in future submissions.
Thanks for taking the time to review it!
On Fri, Nov 6, 2026 at 3:16 PM Patrick Steinhardt <ps@pks.im> wrote:
>
> On Fri, Nov 06, 2026 at 11:59:28AM +0000, Joy via GitGitGadget wrote:
> > From: Joy Gundu <soniqjjj@gmail.com>
> >
> > Use memset() to initialize repository configuration values to
> > zero, removing the need for explicit zero and NULL assignments.
> > Keep non-zero defaults initialized separately.
> >
> > Signed-off-by: Joy Gundu <soniqjjj@gmail.com>
> > ---
> > [Outreachy] repo: zero-initialize configuration values
>
> So I guess this patch was split out because of our recent push to not
> make further changes to `repo_config_values()`? If so, it would have
> made sense to point that out explicitly both here, and in the original
> thread that you've sent.
>
> In any case, the patch is obviously correct and is a good improvement in
> my opinion. So this looks good to me, thanks.
>
> Patrick |
gitgitgadget
Bot
force-pushed
the
seen
branch
from
November 6, 2026 20:32
3de8ebe to
243dcd6
Compare
|
Junio C Hamano wrote on the Git mailing list (how to reply to this email): Patrick Steinhardt <ps@pks.im> writes:
> In any case, the patch is obviously correct and is a good improvement in
> my opinion. So this looks good to me, thanks.
It however does not look good to me. I would prefer to see
struct foo foo = {0};
if everything is zero initialized, or if there are some members
initialized to specific values, C99 designated initializers to be
used:
struct foo foo = {
/* Comment on this stuff */
.object_creation_mode = OBJECT_CREATION_MODE,
/* Comment on this other stuff */
.branch_track = BRANCH_TRACK_REMOTE,
};
Now this is overwriting the passed in structure members, so how we
write the initialization is not the whole story.
Since we have avoided assuming the universal availability of the
more recent "compound literals" syntax, which is:
*cfg = (struct foo) {
... an initialization with designated initializers ...
};
we seem to (ab)use struct assignment, e.g.,
static struct foo foo_template = {
... an initialization with designated initializers ...
};
*cfg = foo_template;
in a few places as a fallback in the existing code (DI is C99,
struct assignment is C89, so it has been a safer assumption than
assuming compound literals).
But I do recall we made this update to our CodingGuidelines document.
. since late 2024 with v2.48.0-rc0~20, we have been using compound
literals, e.g., (struct foo){ .member = value };
So perhaps it is time to switch this to assign a compound literal? |
gitgitgadget
Bot
force-pushed
the
seen
branch
2 times, most recently
from
November 9, 2026 19:17
2ac96db to
0a50955
Compare
|
Joie Joie wrote on the Git mailing list (how to reply to this email): Thanks, Junio.
I hadn't considered using a compound literal here. I was following the
existing initialization approach, but your suggestion makes sense,
especially given the update to the CodingGuidelines.
I'll look into changing the initialization to use a compound literal
while preserving the existing defaults and behavior.
On Fri, Nov 6, 2026 at 8:36 PM Junio C Hamano <gitster@pobox.com> wrote:
>
> Patrick Steinhardt <ps@pks.im> writes:
>
> > In any case, the patch is obviously correct and is a good improvement in
> > my opinion. So this looks good to me, thanks.
>
> It however does not look good to me. I would prefer to see
>
> struct foo foo = {0};
>
> if everything is zero initialized, or if there are some members
> initialized to specific values, C99 designated initializers to be
> used:
>
> struct foo foo = {
> /* Comment on this stuff */
> .object_creation_mode = OBJECT_CREATION_MODE,
>
> /* Comment on this other stuff */
> .branch_track = BRANCH_TRACK_REMOTE,
> };
>
> Now this is overwriting the passed in structure members, so how we
> write the initialization is not the whole story.
>
> Since we have avoided assuming the universal availability of the
> more recent "compound literals" syntax, which is:
>
> *cfg = (struct foo) {
> ... an initialization with designated initializers ...
> };
>
> we seem to (ab)use struct assignment, e.g.,
>
> static struct foo foo_template = {
> ... an initialization with designated initializers ...
> };
>
> *cfg = foo_template;
>
> in a few places as a fallback in the existing code (DI is C99,
> struct assignment is C89, so it has been a safer assumption than
> assuming compound literals).
>
> But I do recall we made this update to our CodingGuidelines document.
>
> . since late 2024 with v2.48.0-rc0~20, we have been using compound
> literals, e.g., (struct foo){ .member = value };
>
> So perhaps it is time to switch this to assign a compound literal? |
|
Junio C Hamano wrote on the Git mailing list (how to reply to this email): Joie Joie <soniqjjj@gmail.com> writes:
> Thanks, Junio.
>
> I hadn't considered using a compound literal here. I was following the
> existing initialization approach, but your suggestion makes sense,
> especially given the update to the CodingGuidelines.
>
> I'll look into changing the initialization to use a compound literal
> while preserving the existing defaults and behavior.
Sounds good, but do not top post ;-)
>
> On Fri, Nov 6, 2026 at 8:36 PM Junio C Hamano <gitster@pobox.com> wrote:
>>
>> Patrick Steinhardt <ps@pks.im> writes:
>>
>> > In any case, the patch is obviously correct and is a good improvement in
>> > my opinion. So this looks good to me, thanks.
>>
>> It however does not look good to me. I would prefer to see
>>
>> struct foo foo = {0};
>>
>> if everything is zero initialized, or if there are some members
>> initialized to specific values, C99 designated initializers to be
>> used:
>>
>> struct foo foo = {
>> /* Comment on this stuff */
>> .object_creation_mode = OBJECT_CREATION_MODE,
>>
>> /* Comment on this other stuff */
>> .branch_track = BRANCH_TRACK_REMOTE,
>> };
>>
>> Now this is overwriting the passed in structure members, so how we
>> write the initialization is not the whole story.
>>
>> Since we have avoided assuming the universal availability of the
>> more recent "compound literals" syntax, which is:
>>
>> *cfg = (struct foo) {
>> ... an initialization with designated initializers ...
>> };
>>
>> we seem to (ab)use struct assignment, e.g.,
>>
>> static struct foo foo_template = {
>> ... an initialization with designated initializers ...
>> };
>>
>> *cfg = foo_template;
>>
>> in a few places as a fallback in the existing code (DI is C99,
>> struct assignment is C89, so it has been a safer assumption than
>> assuming compound literals).
>>
>> But I do recall we made this update to our CodingGuidelines document.
>>
>> . since late 2024 with v2.48.0-rc0~20, we have been using compound
>> literals, e.g., (struct foo){ .member = value };
>>
>> So perhaps it is time to switch this to assign a compound literal? |
gitgitgadget
Bot
force-pushed
the
seen
branch
11 times, most recently
from
November 16, 2026 14:54
d749f8d to
13ebffd
Compare
gitgitgadget
Bot
force-pushed
the
seen
branch
from
November 16, 2026 22:44
13ebffd to
31dd3d3
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
CC: Patrick Steinhardt <ps@pks.im>, Kristoffer Haugsbakk <kristofferhaugsbakk@fastmail.com>, Christian Couder <christian.couder@gmail.com>, Usman Akinyemi <usmanakinyemi202@gmail.com>
cc: Joie Joie soniqjjj@gmail.com
cc: Patrick Steinhardt ps@pks.im
cc: Tanga Joris tangajoris@gmail.com