]> git.ipfire.org Git - thirdparty/git.git/log
thirdparty/git.git
10 months agoMerge branch 'jc/leakfix-mailmap'
Junio C Hamano [Wed, 14 Aug 2024 21:54:53 +0000 (14:54 -0700)] 
Merge branch 'jc/leakfix-mailmap'

Leakfix.

* jc/leakfix-mailmap:
  mailmap: plug memory leak in read_mailmap_blob()

10 months agoMerge branch 'jc/leakfix-hashfile'
Junio C Hamano [Wed, 14 Aug 2024 21:54:53 +0000 (14:54 -0700)] 
Merge branch 'jc/leakfix-hashfile'

Leakfix.

* jc/leakfix-hashfile:
  csum-file: introduce discard_hashfile()

10 months agoMerge branch 'jc/patch-id'
Junio C Hamano [Wed, 14 Aug 2024 21:54:53 +0000 (14:54 -0700)] 
Merge branch 'jc/patch-id'

The patch parser in "git patch-id" has been tightened to avoid
getting confused by lines that look like a patch header in the log
message.

* jc/patch-id:
  patch-id: tighten code to detect the patch header
  patch-id: rewrite code that detects the beginning of a patch
  patch-id: make get_one_patchid() more extensible
  patch-id: call flush_current_id() only when needed
  t4204: patch-id supports various input format

10 months agoMerge branch 'ps/refs-wo-the-repository'
Junio C Hamano [Wed, 14 Aug 2024 21:54:52 +0000 (14:54 -0700)] 
Merge branch 'ps/refs-wo-the-repository'

In the refs subsystem, implicit reliance of the_repository has been
eliminated; the repository associated with the ref store object is
used instead.

* ps/refs-wo-the-repository:
  refs/reftable: stop using `the_repository`
  refs/packed: stop using `the_repository`
  refs/files: stop using `the_repository`
  refs/files: stop using `the_repository` in `parse_loose_ref_contents()`
  refs: stop using `the_repository`

10 months agoMerge branch 'jc/jl-git-no-advice-fix'
Junio C Hamano [Wed, 14 Aug 2024 21:54:51 +0000 (14:54 -0700)] 
Merge branch 'jc/jl-git-no-advice-fix'

Remove leftover debugging cruft from a test script.

* jc/jl-git-no-advice-fix:
  t0018: remove leftover debugging cruft

10 months agoMerge branch 'tb/config-fixed-value-with-valueless-true'
Junio C Hamano [Wed, 14 Aug 2024 21:54:51 +0000 (14:54 -0700)] 
Merge branch 'tb/config-fixed-value-with-valueless-true'

"git config --value=foo --fixed-value section.key newvalue" barfed
when the existing value in the configuration file used the
valueless true syntax, which has been corrected.

* tb/config-fixed-value-with-valueless-true:
  config.c: avoid segfault with --fixed-value and valueless config

10 months agoMerge branch 'jk/apply-patch-mode-check-fix'
Junio C Hamano [Wed, 14 Aug 2024 21:54:50 +0000 (14:54 -0700)] 
Merge branch 'jk/apply-patch-mode-check-fix'

The patch parser in 'git apply' has been a bit more lenient against
unexpected mode bits, like 100664, recorded on extended header lines.

* jk/apply-patch-mode-check-fix:
  apply: canonicalize modes read from patches

10 months agoMerge branch 'ps/ref-api-cleanup'
Junio C Hamano [Wed, 14 Aug 2024 21:54:50 +0000 (14:54 -0700)] 
Merge branch 'ps/ref-api-cleanup'

Code clean-up.

* ps/ref-api-cleanup:
  refs: drop `ref_store`-less functions

10 months agoMerge branch 'ps/ls-remote-out-of-repo-fix'
Junio C Hamano [Wed, 14 Aug 2024 21:54:49 +0000 (14:54 -0700)] 
Merge branch 'ps/ls-remote-out-of-repo-fix'

A recent update broke "git ls-remote" used outside a repository,
which has been corrected.

* ps/ls-remote-out-of-repo-fix:
  builtin/ls-remote: fall back to SHA1 outside of a repo

10 months agoMerge branch 'jc/transport-leakfix'
Junio C Hamano [Wed, 14 Aug 2024 21:54:49 +0000 (14:54 -0700)] 
Merge branch 'jc/transport-leakfix'

Leakfix.

* jc/transport-leakfix:
  transport: fix leak with transport helper URLs

10 months agoMerge branch 'rh/http-proxy-path'
Junio C Hamano [Wed, 14 Aug 2024 21:54:48 +0000 (14:54 -0700)] 
Merge branch 'rh/http-proxy-path'

The value of http.proxy can have "path" at the end for a socks
proxy that listens to a unix-domain socket, but we started to
discard it when we taught proxy auth code path to use the
credential helpers, which has been corrected.

* rh/http-proxy-path:
  http: do not ignore proxy path

10 months agoMerge branch 'cp/unit-test-reftable-pq'
Junio C Hamano [Wed, 14 Aug 2024 21:54:48 +0000 (14:54 -0700)] 
Merge branch 'cp/unit-test-reftable-pq'

The tests for "pq" part of reftable library got rewritten to use
the unit test framework.

* cp/unit-test-reftable-pq:
  t-reftable-pq: add tests for merged_iter_pqueue_top()
  t-reftable-pq: add test for index based comparison
  t-reftable-pq: make merged_iter_pqueue_check() callable by reference
  t-reftable-pq: make merged_iter_pqueue_check() static
  t: move reftable/pq_test.c to the unit testing framework
  reftable: change the type of array indices to 'size_t' in reftable/pq.c
  reftable: remove unnecessary curly braces in reftable/pq.c

10 months agoMerge branch 'jk/osxkeychain-username-is-nul-terminated'
Junio C Hamano [Wed, 14 Aug 2024 21:54:47 +0000 (14:54 -0700)] 
Merge branch 'jk/osxkeychain-username-is-nul-terminated'

The credential helper to talk to OSX keychain sometimes sent
garbage bytes after the username, which has been corrected.

* jk/osxkeychain-username-is-nul-terminated:
  credential/osxkeychain: respect NUL terminator in username

10 months agoMerge branch 'ps/leakfixes-part-3'
Junio C Hamano [Wed, 14 Aug 2024 21:54:47 +0000 (14:54 -0700)] 
Merge branch 'ps/leakfixes-part-3'

More leakfixes.

* ps/leakfixes-part-3: (24 commits)
  commit-reach: fix trivial memory leak when computing reachability
  convert: fix leaking config strings
  entry: fix leaking pathnames during delayed checkout
  object-name: fix leaking commit list items
  t/test-repository: fix leaking repository
  builtin/credential-cache: fix trivial leaks
  builtin/worktree: fix leaking derived branch names
  builtin/shortlog: fix various trivial memory leaks
  builtin/rerere: fix various trivial memory leaks
  builtin/credential-store: fix leaking credential
  builtin/show-branch: fix several memory leaks
  builtin/rev-parse: fix memory leak with `--parseopt`
  builtin/stash: fix various trivial memory leaks
  builtin/remote: fix various trivial memory leaks
  builtin/remote: fix leaking strings in `branch_list`
  builtin/ls-remote: fix leaking `pattern` strings
  builtin/submodule--helper: fix leaking buffer in `is_tip_reachable`
  builtin/submodule--helper: fix leaking clone depth parameter
  builtin/name-rev: fix various trivial memory leaks
  builtin/describe: fix trivial memory leak when describing blob
  ...

10 months agoThe third batch
Junio C Hamano [Wed, 7 Aug 2024 16:46:53 +0000 (09:46 -0700)] 
The third batch

Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agoMerge branch 'ps/p4-tests-updates'
Junio C Hamano [Thu, 8 Aug 2024 17:41:20 +0000 (10:41 -0700)] 
Merge branch 'ps/p4-tests-updates'

Perforce tests have been updated.

* ps/p4-tests-updates:
  t98xx: mark Perforce tests as memory-leak free
  ci: update Perforce version to r23.2
  t98xx: fix Perforce tests with p4d r23 and newer

10 months agoMerge branch 'dh/encoding-trace-optim'
Junio C Hamano [Thu, 8 Aug 2024 17:41:20 +0000 (10:41 -0700)] 
Merge branch 'dh/encoding-trace-optim'

An expensive operation to prepare tracing was done in re-encoding
code path even when the tracing was not requested, which has been
corrected.

* dh/encoding-trace-optim:
  convert: return early when not tracing

10 months agoMerge branch 'ps/doc-more-c-coding-guidelines'
Junio C Hamano [Thu, 8 Aug 2024 17:41:19 +0000 (10:41 -0700)] 
Merge branch 'ps/doc-more-c-coding-guidelines'

Some project conventions have been added to CodingGuidelines.

* ps/doc-more-c-coding-guidelines:
  Documentation: consistently use spaces inside initializers
  Documentation: document idiomatic function names
  Documentation: document naming schema for structs and their functions
  Documentation: clarify indentation style for C preprocessor directives
  clang-format: fix indentation width for preprocessor directives

10 months agoMerge branch 'rs/grep-omit-blank-lines-after-function-at-eof'
Junio C Hamano [Thu, 8 Aug 2024 17:41:19 +0000 (10:41 -0700)] 
Merge branch 'rs/grep-omit-blank-lines-after-function-at-eof'

"git grep -W" omits blank lines that follow the found function at
the end of the file, just like it omits blank lines before the next
function.

* rs/grep-omit-blank-lines-after-function-at-eof:
  grep: -W: skip trailing empty lines at EOF, too

10 months agoMerge branch 'dd/notes-empty-no-edit-by-default'
Junio C Hamano [Thu, 8 Aug 2024 17:41:19 +0000 (10:41 -0700)] 
Merge branch 'dd/notes-empty-no-edit-by-default'

"git notes add -m '' --allow-empty" and friends that take prepared
data to create notes should not invoke an editor, but it started
doing so since Git 2.42, which has been corrected.

* dd/notes-empty-no-edit-by-default:
  notes: do not trigger editor when adding an empty note

10 months agoMerge branch 'es/shell-check-updates'
Junio C Hamano [Thu, 8 Aug 2024 17:41:18 +0000 (10:41 -0700)] 
Merge branch 'es/shell-check-updates'

Test script linter has been updated to catch an attempt to use
one-shot export construct "VAR=VAL func" for shell functions (which
does not work for some shells) better.

* es/shell-check-updates:
  check-non-portable-shell: improve `VAR=val shell-func` detection
  check-non-portable-shell: suggest alternative for `VAR=val shell-func`
  check-non-portable-shell: loosen one-shot assignment error message
  t4034: fix use of one-shot variable assignment with shell function
  t3430: drop unnecessary one-shot "VAR=val shell-func" invocation

10 months agoMerge branch 'rj/add-p-pager'
Junio C Hamano [Thu, 8 Aug 2024 17:41:18 +0000 (10:41 -0700)] 
Merge branch 'rj/add-p-pager'

A 'P' command to "git add -p" that passes the patch hunk to the
pager has been added.

* rj/add-p-pager:
  add-patch: render hunks through the pager
  pager: introduce wait_for_pager
  pager: do not close fd 2 unnecessarily
  add-patch: test for 'p' command

10 months agoMerge branch 'ks/unit-test-comment-typofix'
Junio C Hamano [Thu, 8 Aug 2024 17:41:17 +0000 (10:41 -0700)] 
Merge branch 'ks/unit-test-comment-typofix'

Typofix.

* ks/unit-test-comment-typofix:
  unit-tests/test-lib: fix typo in check_pointer_eq() description

10 months agotransport: fix leak with transport helper URLs
Junio C Hamano [Thu, 8 Aug 2024 00:32:56 +0000 (17:32 -0700)] 
transport: fix leak with transport helper URLs

Transport URLs can be prefixed with "foo::", which would tell us that
the transport uses a remote helper called "foo". We extract the helper
name by `xstrndup()`ing the prefix before the double-colons, but never
free that string.

Fix this leak by assigning the result to a separate local variable that
we can then free upon returning.

Helped-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agoapply: canonicalize modes read from patches
Jeff King [Mon, 5 Aug 2024 06:00:10 +0000 (02:00 -0400)] 
apply: canonicalize modes read from patches

Git stores only canonical modes for blobs. So for a regular file, we
care about only "100644" or "100755" (depending only on the executable
bit), but never modes where the group or other permissions are more
exotic. So never "100664", "100700", etc. When a file in the working
tree has such a mode, we quietly turn it into one of the two canonical
modes, and that's what is stored both in the index and in tree objects.

However, we don't canonicalize modes we read from incoming patches in
git-apply. These may appear in a few lines:

  - "old mode" / "new mode" lines for mode changes

  - "new file mode" lines for newly created files

  - "deleted file mode" for removing files

For "new mode" and for "new file mode", this is harmless. The patch is
asking the result to have a certain mode, but:

  - when we add an index entry (for --index or --cached), it is
    canonicalized as we create the entry, via create_ce_mode().

  - for a working tree file, try_create_file() passes either 0777 or
    0666 to open(), so what you get depends only on your umask, not any
    other bits (aside from the executable bit) in the original mode.

However, for "old mode" and "deleted file mode", there is a minor
annoyance. We compare the patch's expected preimage mode with the
current state. But that current state is always going to be a canonical
mode itself:

  - updating an index entry via --cached will have the canonical mode in
    the index

  - for updating a working tree file, check_preimage() runs the mode
    through ce_mode_from_stat(), which does the usual canonicalization

So if the patch feeds a non-canonical mode, it's impossible for it to
match, and we will always complain with something like:

  file has type 100644, expected 100664

Since this is just a warning, the operation proceeds, but it's
confusing and annoying.

These cases should be pretty rare in practice. Git would never produce a
patch with non-canonical modes itself (since it doesn't store them).
And while we do accept patches from other programs, all of those lines
were invented by Git. So you'd need a program trying to be Git
compatible, but not handling canonicalization the same way. Reportedly
"quilt" is such a program.

We should canonicalize the modes as we read them so that the user never
sees the useless warning.

A few notes on the tests:

  - I've covered instances of all lines for completeness, even though
    the "new mode" / "new file mode" ones behave OK currently.

  - the tests apply patches to both the index and working tree, and
    check the result of both. Again, we know that all of these paths
    canonicalize anyway, but it's giving us extra coverage (although we
    are even less likely to have such a bug now since we canonicalize up
    front).

  - the test patches are missing "index" lines, which is also something
    Git would never produce. But they don't matter for the test, they do
    match the case from quilt we saw in the wild, and they avoid some
    sha1/sha256 complexity.

Reported-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agorefs: drop `ref_store`-less functions
Patrick Steinhardt [Fri, 2 Aug 2024 05:38:19 +0000 (07:38 +0200)] 
refs: drop `ref_store`-less functions

In c8f815c208 (refs: remove functions without ref store, 2024-05-07), we
have removed functions of the refs subsystem that do not take a ref
store as input parameter. In order to make it easier for folks to figure
out how to replace calls to such functions in in-flight patch series, we
kept their definitions around in an ifdeffed block.

Now that Git v2.46 is out, it is rather unlikely that anybody still has
references to these old functions in their unreleased patches. Let's
thus drop them.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agohttp: do not ignore proxy path
Ryan Hendrickson [Fri, 2 Aug 2024 05:20:07 +0000 (05:20 +0000)] 
http: do not ignore proxy path

The documentation for `http.proxy` describes that option, and the
environment variables it overrides, as supporting "the syntax understood
by curl". curl allows SOCKS proxies to use a path to a Unix domain
socket, like `socks5h://localhost/path/to/socket.sock`. Git should
therefore include, if present, the path part of the proxy URL in what it
passes to libcurl.

Co-authored-by: Jeff King <peff@peff.net>
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Ryan Hendrickson <ryan.hendrickson@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agobuiltin/ls-remote: fall back to SHA1 outside of a repo
Patrick Steinhardt [Fri, 2 Aug 2024 04:44:11 +0000 (06:44 +0200)] 
builtin/ls-remote: fall back to SHA1 outside of a repo

In c8aed5e8da (repository: stop setting SHA1 as the default object hash,
2024-05-07), we have stopped setting the default hash algorithm for
`the_repository`. Consequently, code that relies on `the_hash_algo` will
now crash when it hasn't explicitly been initialized, which may be the
case when running outside of a Git repository.

It was reported that git-ls-remote(1) may crash in such a way when using
a remote helper that advertises refspecs. This is because the refspec
announced by the helper will get parsed during capability negotiation.
At that point we haven't yet figured out what object format the remote
uses though, so when run outside of a repository then we will fail.

The course of action is somewhat dubious in the first place. Ideally, we
should only parse object IDs once we have asked the remote helper for
the object format. And if the helper didn't announce the "object-format"
capability, then we should always assume SHA256. But instead, we used to
take either SHA1 if there was no repository, or we used the hash of the
local repository, which is wrong.

Arguably though, crashing hard may not be in the best interest of our
users, either. So while the old behaviour was buggy, let's restore it
for now as a short-term fix. We should eventually revisit, potentially
by deferring the point in time when we parse the refspec until after we
have figured out the remote's object hash.

Reported-by: Mike Hommey <mh@glandium.org>
Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agot0018: remove leftover debugging cruft
Junio C Hamano [Thu, 1 Aug 2024 18:51:12 +0000 (11:51 -0700)] 
t0018: remove leftover debugging cruft

The actual file is copied out to /tmp, presumably so that the tester
can inspect it after the test is done, which may have been a useful
debugging aid.

But in the final shape of the test suite, such a code should not
exist.  We cannot even assume that we are allowed to write into /tmp
(our TMPDIR may not even be pointing at it) or read from it for that
matter.

Noticed-by: Randall S. Becker <rsbecker@nexbridge.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agoconfig.c: avoid segfault with --fixed-value and valueless config
Taylor Blau [Thu, 1 Aug 2024 17:06:54 +0000 (13:06 -0400)] 
config.c: avoid segfault with --fixed-value and valueless config

When using `--fixed-value` with a key whose value is left empty (implied
as being "true"), 'git config' may crash when invoked like either of:

    $ git config set --file=config --value=value --fixed-value \
        section.key pattern
    $ git config --file=config --fixed-value section.key value pattern

The original bugreport[1] bisects to 00bbdde141 (builtin/config:
introduce "set" subcommand, 2024-05-06), which is a red-herring, since
the original bugreport uses the new 'git config set' invocation.

The behavior likely bisects back to c90702a1f6 (config: plumb
--fixed-value into config API, 2020-11-25), which introduces the new
--fixed-value option in the first place.

Looking at the relevant frame from a failed process's coredump, the
crash appears in config.c::matches() like so:

    (gdb) up
    #1  0x000055b3e8b06022 in matches (key=0x55b3ea894360 "section.key", value=0x0,
        store=0x7ffe99076eb0) at config.c:2884
    2884 return !strcmp(store->fixed_value, value);

where we are trying to compare the `--fixed-value` argument to `value`,
which is NULL.

Avoid attempting to match `--fixed-value` for configuration keys with no
explicit value. A future patch could consider the empty value to mean
"true", "yes", "on", etc. when invoked with `--type=bool`, but let's
punt on that for now in the name of avoiding the segfault.

[1]: https://lore.kernel.org/git/CANrWfmTek1xErBLrnoyhHN+gWU+rw14y6SQ+abZyzGoaBjmiKA@mail.gmail.com/

Reported-by: Han Jiang <jhcarl0814@gmail.com>
Signed-off-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agoThe second batch
Junio C Hamano [Thu, 1 Aug 2024 17:17:48 +0000 (10:17 -0700)] 
The second batch

Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agoMerge branch 'as/show-ref-option-help-update'
Junio C Hamano [Thu, 1 Aug 2024 17:18:12 +0000 (10:18 -0700)] 
Merge branch 'as/show-ref-option-help-update'

A few descriptions in "git show-ref -h" have been clarified.

* as/show-ref-option-help-update:
  show-ref: improve short help messages of options

10 months agoMerge branch 'jc/doc-reviewing-guidelines-positive-reviews'
Junio C Hamano [Thu, 1 Aug 2024 17:18:11 +0000 (10:18 -0700)] 
Merge branch 'jc/doc-reviewing-guidelines-positive-reviews'

The reviewing guidelines document now explicitly encourages people
to give positive reviews and how.

* jc/doc-reviewing-guidelines-positive-reviews:
  ReviewingGuidelines: encourage positive reviews more

10 months agoMerge branch 'jc/doc-rebase-fuzz-vs-offset-fix'
Junio C Hamano [Thu, 1 Aug 2024 17:18:11 +0000 (10:18 -0700)] 
Merge branch 'jc/doc-rebase-fuzz-vs-offset-fix'

"git rebase --help" referred to "offset" (the difference between
the location a change was taken from and the change gets replaced)
incorrectly and called it "fuzz", which has been corrected.

* jc/doc-rebase-fuzz-vs-offset-fix:
  doc: difference in location to apply is "offset", not "fuzz"

10 months agot-reftable-pq: add tests for merged_iter_pqueue_top()
Chandra Pratap [Thu, 1 Aug 2024 10:59:48 +0000 (16:29 +0530)] 
t-reftable-pq: add tests for merged_iter_pqueue_top()

merged_iter_pqueue_top() as defined by reftable/pq.{c, h} returns
the element at the top of a priority-queue's heap without removing
it. Since there are no tests for this function in the existing
setup, add tests for the same.

Mentored-by: Patrick Steinhardt <ps@pks.im>
Mentored-by: Christian Couder <chriscool@tuxfamily.org>
Signed-off-by: Chandra Pratap <chandrapratap3519@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agot-reftable-pq: add test for index based comparison
Chandra Pratap [Thu, 1 Aug 2024 10:59:47 +0000 (16:29 +0530)] 
t-reftable-pq: add test for index based comparison

When comparing two entries, the priority queue as defined by
reftable/pq.{c, h} first compares the entries on the basis of
their ref-record's keys. If the keys turn out to be equal, the
comparison is then made on the basis of their update indices
(which are never equal).

In the current testing setup, only the case for comparison on
the basis of ref-record's keys is exercised. Add a test for
index-based comparison as well. Rename the existing test to
reflect its nature of only testing record-based comparison.

While at it, replace 'strbuf_detach' with 'xstrfmt' to assign
refnames in the existing test. This makes the test conciser.

Mentored-by: Patrick Steinhardt <ps@pks.im>
Mentored-by: Christian Couder <chriscool@tuxfamily.org>
Signed-off-by: Chandra Pratap <chandrapratap3519@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agot-reftable-pq: make merged_iter_pqueue_check() callable by reference
Chandra Pratap [Thu, 1 Aug 2024 10:59:46 +0000 (16:29 +0530)] 
t-reftable-pq: make merged_iter_pqueue_check() callable by reference

merged_iter_pqueue_check() checks the validity of a priority queue
represented by a merged_iter_pqueue struct by asserting the
parent-child relation in the struct's heap. Explicity passing a
struct to this function means a copy of the entire struct is created,
which is inefficient.

Make the function accept a pointer to the struct instead. This is
safe to do since the function doesn't modify the struct in any way.
Make the function parameter 'const' to assert immutability.

Mentored-by: Patrick Steinhardt <ps@pks.im>
Mentored-by: Christian Couder <chriscool@tuxfamily.org>
Signed-off-by: Chandra Pratap <chandrapratap3519@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agot-reftable-pq: make merged_iter_pqueue_check() static
Chandra Pratap [Thu, 1 Aug 2024 10:59:45 +0000 (16:29 +0530)] 
t-reftable-pq: make merged_iter_pqueue_check() static

merged_iter_pqueue_check() is a function previously defined in
reftable/pq_test.c (now t/unit-tests/t-reftable-pq.c) and used in
the testing of a priority queue as defined by reftable/pq.{c, h}.
As such, this function is only called by reftable/pq_test.c and it
makes little sense to expose it to non-testing code via reftable/pq.h.

Hence, make this function static and remove its prototype from
reftable/pq.h.

Mentored-by: Patrick Steinhardt <ps@pks.im>
Mentored-by: Christian Couder <chriscool@tuxfamily.org>
Signed-off-by: Chandra Pratap <chandrapratap3519@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agot: move reftable/pq_test.c to the unit testing framework
Chandra Pratap [Thu, 1 Aug 2024 10:59:44 +0000 (16:29 +0530)] 
t: move reftable/pq_test.c to the unit testing framework

reftable/pq_test.c exercises a priority queue defined by
reftable/pq.{c, h}. Migrate reftable/pq_test.c to the unit testing
framework. Migration involves refactoring the tests to use the unit
testing framework instead of reftable's test framework, and
renaming the tests to align with unit-tests' standards.

Mentored-by: Patrick Steinhardt <ps@pks.im>
Mentored-by: Christian Couder <chriscool@tuxfamily.org>
Signed-off-by: Chandra Pratap <chandrapratap3519@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agoreftable: change the type of array indices to 'size_t' in reftable/pq.c
Chandra Pratap [Thu, 1 Aug 2024 10:59:43 +0000 (16:29 +0530)] 
reftable: change the type of array indices to 'size_t' in reftable/pq.c

The variables 'i', 'j', 'k' and 'min' are used as indices for
'pq->heap', which is an array. Additionally, 'pq->len' is of
type 'size_t' and is often used to assign values to these
variables. Hence, change the type of these variables from 'int'
to 'size_t'.

Mentored-by: Patrick Steinhardt <ps@pks.im>
Mentored-by: Christian Couder <chriscool@tuxfamily.org>
Signed-off-by: Chandra Pratap <chandrapratap3519@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agoreftable: remove unnecessary curly braces in reftable/pq.c
Chandra Pratap [Thu, 1 Aug 2024 10:59:42 +0000 (16:29 +0530)] 
reftable: remove unnecessary curly braces in reftable/pq.c

According to Documentation/CodingGuidelines, control-flow statements
with a single line as their body must omit curly braces. Make
reftable/pq.c conform to this guideline. Besides that, remove
unnecessary newlines and variable assignment.

Mentored-by: Patrick Steinhardt <ps@pks.im>
Mentored-by: Christian Couder <chriscool@tuxfamily.org>
Signed-off-by: Chandra Pratap <chandrapratap3519@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agocredential/osxkeychain: respect NUL terminator in username
Jeff King [Thu, 1 Aug 2024 08:25:56 +0000 (04:25 -0400)] 
credential/osxkeychain: respect NUL terminator in username

This patch fixes a case where git-credential-osxkeychain might output
uninitialized bytes to stdout.

We need to get the username string from a system API using
CFStringGetCString(). To do that, we get the max size for the string
from CFStringGetMaximumSizeForEncoding(), allocate a buffer based on
that, and then read into it. But then we print the entire buffer to
stdout, including the trailing NUL and any extra bytes which were not
needed. Instead, we should stop at the NUL.

This code comes from 9abe31f5f1 (osxkeychain: replace deprecated
SecKeychain API, 2024-02-17). The bug was probably overlooked back then
because this code is only used as a fallback when we can't get the
string via CFStringGetCStringPtr(). According to Apple's documentation:

  Whether or not this function returns a valid pointer or NULL depends
  on many factors, all of which depend on how the string was created and
  its properties.

So it's not clear how we could make a test for this, and we'll have to
rely on manually testing on a system that triggered the bug in the first
place.

Reported-by: Hong Jiang <ilford@gmail.com>
Signed-off-by: Jeff King <peff@peff.net>
Tested-by: Hong Jiang <ilford@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agocommit-reach: fix trivial memory leak when computing reachability
Patrick Steinhardt [Thu, 1 Aug 2024 10:41:15 +0000 (12:41 +0200)] 
commit-reach: fix trivial memory leak when computing reachability

We don't free the local `stack` commit list that we use to compute
reachability of multiple commits at once. Do so.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agoconvert: fix leaking config strings
Patrick Steinhardt [Thu, 1 Aug 2024 10:41:11 +0000 (12:41 +0200)] 
convert: fix leaking config strings

In `read_convert_config()`, we end up reading some string values into
variables. We don't free any potentially-existing old values though,
which will result in a memory leak in case the same key has been defined
multiple times.

Fix those leaks.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agoentry: fix leaking pathnames during delayed checkout
Patrick Steinhardt [Thu, 1 Aug 2024 10:41:06 +0000 (12:41 +0200)] 
entry: fix leaking pathnames during delayed checkout

When filtering files during delayed checkout, we pass a string list to
`async_query_available_blobs()`. This list is initialized with NODUP,
and thus inserted strings will not be owned by the list. In the latter
function we then try to hand over ownership by passing an `xstrup()`'d
value to `string_list_insert()`. But this is not how this works: a NODUP
list does not take ownership of allocated strings and will never free
them for the caller.

Fix this issue by initializing the list as `DUP` instead and dropping
the explicit call to `xstrdup()`. This is okay to do given that this is
the single callsite of `async_query_available_blobs()`.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agoobject-name: fix leaking commit list items
Patrick Steinhardt [Thu, 1 Aug 2024 10:41:01 +0000 (12:41 +0200)] 
object-name: fix leaking commit list items

When calling `get_oid_oneline()`, we pass in a `struct commit_list` that
gets modified by the function. This creates a weird situation where the
commit list may sometimes be empty after returning, but sometimes it
will continue to carry additional commits. In those cases the remainder
of the list leaks.

Ultimately, the design where we only pass partial ownership to
`get_oid_oneline()` feels shoddy. Refactor the code such that we only
pass a constant pointer to the list, creating a local copy as needed.
Callers are thus always responsible for freeing the commit list, which
then allows us to plug a bunch of memory leaks.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agot/test-repository: fix leaking repository
Patrick Steinhardt [Thu, 1 Aug 2024 10:40:56 +0000 (12:40 +0200)] 
t/test-repository: fix leaking repository

The test-repository test helper zeroes out `the_repository` such that it
can be sure that our codebase only ends up using the supplied repository
that we initialize in the respective helper functions. This does cause
memory leaks though as the data that `the_repository` has been holding
onto is not referenced anymore.

Fix this by calling `repo_clear()` instead.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agobuiltin/credential-cache: fix trivial leaks
Patrick Steinhardt [Thu, 1 Aug 2024 10:40:51 +0000 (12:40 +0200)] 
builtin/credential-cache: fix trivial leaks

There are two trivial leaks in git-credential-cache(1):

  - We leak the child process in `spawn_daemon()`. As we do not call
    `finish_command()` and instead let the created process daemonize, we
    have to clear the process manually.

  - We do not free the computed socket path in case it wasn't given via
    `--socket=`.

Plug both of these memory leaks.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agobuiltin/worktree: fix leaking derived branch names
Patrick Steinhardt [Thu, 1 Aug 2024 10:40:46 +0000 (12:40 +0200)] 
builtin/worktree: fix leaking derived branch names

There are several heuristics that git-worktree(1) uses to derive the
name of the newly created branch when not given explicitly. These
heuristics all allocate a new string, but we only end up freeing that
string in a subset of cases.

Fix the remaining cases where we didn't yet free the derived branch
names. While at it, also free `opt_track`, which is being populated via
an `OPT_PASSTHRU()`.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agobuiltin/shortlog: fix various trivial memory leaks
Patrick Steinhardt [Thu, 1 Aug 2024 10:40:41 +0000 (12:40 +0200)] 
builtin/shortlog: fix various trivial memory leaks

There is a trivial memory leak in git-shortlog(1). Fix it.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agobuiltin/rerere: fix various trivial memory leaks
Patrick Steinhardt [Thu, 1 Aug 2024 10:40:36 +0000 (12:40 +0200)] 
builtin/rerere: fix various trivial memory leaks

There are multiple trivial memory leaks in git-rerere(1). Fix those.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agobuiltin/credential-store: fix leaking credential
Patrick Steinhardt [Thu, 1 Aug 2024 10:40:31 +0000 (12:40 +0200)] 
builtin/credential-store: fix leaking credential

We never free credentials read by the credential store, leading to a
memory leak. Plug it.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agobuiltin/show-branch: fix several memory leaks
Patrick Steinhardt [Thu, 1 Aug 2024 10:40:26 +0000 (12:40 +0200)] 
builtin/show-branch: fix several memory leaks

There are several memory leaks in git-show-branch(1). Fix them.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agobuiltin/rev-parse: fix memory leak with `--parseopt`
Patrick Steinhardt [Thu, 1 Aug 2024 10:40:21 +0000 (12:40 +0200)] 
builtin/rev-parse: fix memory leak with `--parseopt`

The `--parseopt` mode allows shell scripts to have the same option
parsing mode as we have in C builtins. It soaks up a set of option
descriptions via stdin and massages them into proper `struct option`s
that we can then use to parse a set of arguments.

We only partially free those options when done though, creating a memory
leak. Interestingly, we only end up free'ing the first option's help,
which is of course wrong.

Fix this by freeing all option's help fields as well as their `argh`
fields to plug this memory leak.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agobuiltin/stash: fix various trivial memory leaks
Patrick Steinhardt [Thu, 1 Aug 2024 10:40:17 +0000 (12:40 +0200)] 
builtin/stash: fix various trivial memory leaks

There are multiple trivial memory leaks in git-stash(1). Fix those.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agobuiltin/remote: fix various trivial memory leaks
Patrick Steinhardt [Thu, 1 Aug 2024 10:40:12 +0000 (12:40 +0200)] 
builtin/remote: fix various trivial memory leaks

There are multiple trivial memory leaks in git-remote(1). Fix those.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agobuiltin/remote: fix leaking strings in `branch_list`
Patrick Steinhardt [Thu, 1 Aug 2024 10:40:07 +0000 (12:40 +0200)] 
builtin/remote: fix leaking strings in `branch_list`

The `struct string_list branch_list` is declared as `NODUP`, which makes
it not copy strings inserted into it. This causes memory leaks though,
as this means it also won't be responsible for _freeing_ inserted
strings. Thus, every branch we add to this will leak.

Fix this by marking the list as `DUP` instead and free the local copy we
have of the variable.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agobuiltin/ls-remote: fix leaking `pattern` strings
Patrick Steinhardt [Thu, 1 Aug 2024 10:40:02 +0000 (12:40 +0200)] 
builtin/ls-remote: fix leaking `pattern` strings

Users can pass patterns to git-ls-remote(1), which allows them to filter
the list of printed references. We assemble those patterns into an array
and prefix them with "*/", but never free either the array nor the
allocated strings.

Refactor the code to use a `struct strvec` instead of manually tracking
the strings in an array. Like this, we can easily use `strvec_clear()`
to release both the vector and the contained string for us, plugging the
leak.

Helped-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agobuiltin/submodule--helper: fix leaking buffer in `is_tip_reachable`
Patrick Steinhardt [Thu, 1 Aug 2024 10:39:57 +0000 (12:39 +0200)] 
builtin/submodule--helper: fix leaking buffer in `is_tip_reachable`

The `rev` buffer in `is_tip_reachable()` is being populated with the
output of git-rev-list(1) -- if either the command fails or the buffer
contains any data, then the input commit is not reachable.

The buffer isn't used for anything else, but neither do we free it,
causing a memory leak. Fix this.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agobuiltin/submodule--helper: fix leaking clone depth parameter
Patrick Steinhardt [Thu, 1 Aug 2024 10:42:59 +0000 (12:42 +0200)] 
builtin/submodule--helper: fix leaking clone depth parameter

The submodule helper supports a `--depth` parameter for both its "add"
and "clone" subcommands, which in both cases end up being forwarded to
git-clone(1). But while the former subcommand uses an `OPT_INTEGER()` to
parse the depth, the latter uses `OPT_STRING()`. Consequently, it is
possible to pass non-integer input to "--depth" when calling the "clone"
subcommand, where the value will then ultimately cause git-clone(1) to
bail out.

Besides the fact that the parameter verification should happen earlier,
the submodule helper infrastructure also internally tracks the depth via
a string. This requires us to convert the integer in the "add"
subcommand into an allocated string, and this string ultimately leaks.

Refactor the code to consistently track the clone depth as an integer.
This plugs the memory leak, simplifies the code and allows us to use
`OPT_INTEGER()` instead of `OPT_STRING()`, validating the input before
we shell out to git--clone(1).

Original-patch-by: Rubén Justo <rjusto@gmail.com>
Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agobuiltin/name-rev: fix various trivial memory leaks
Patrick Steinhardt [Thu, 1 Aug 2024 10:38:35 +0000 (12:38 +0200)] 
builtin/name-rev: fix various trivial memory leaks

There are several structures that we don't release after
`cmd_name_rev()` is done. Plug those leaks.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agobuiltin/describe: fix trivial memory leak when describing blob
Patrick Steinhardt [Thu, 1 Aug 2024 10:38:30 +0000 (12:38 +0200)] 
builtin/describe: fix trivial memory leak when describing blob

We never free the `struct strvec args` variable in `describe_blob()`,
which thus causes a memory leak. Fix this.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agobuiltin/describe: fix leaking array when running diff-index
Patrick Steinhardt [Thu, 1 Aug 2024 10:38:25 +0000 (12:38 +0200)] 
builtin/describe: fix leaking array when running diff-index

When running git-describe(1) with `--dirty`, we will set up a `struct
rev_info` with arguments for git-diff-index(1). The way we assemble the
arguments it causes two memory leaks though:

  - We never release the `struct strvec`.

  - `setup_revisions()` may end up removing some entries from the
    `strvec`, which we wouldn't free even if we released the struct.

While we could plug those leaks, this is ultimately unnecessary as the
arguments we pass are part of a static array anyway. So instead,
refactor the code to drop the `struct strvec` and just pass this static
array directly.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agobuiltin/describe: fix memory leak with `--contains=`
Patrick Steinhardt [Thu, 1 Aug 2024 10:38:20 +0000 (12:38 +0200)] 
builtin/describe: fix memory leak with `--contains=`

When calling `git describe --contains=`, we end up invoking
`cmd_name_rev()` with some munged argv array. This array may contain
allocated strings and furthermore will likely be modified by the called
function. This results in two memory leaks:

  - First, we leak the array that we use to assemble the arguments.

  - Second, we leak the allocated strings that we may have put into the
    array.

Fix those leaks by creating a separate copy of the array that we can
hand over to `cmd_name_rev()`. This allows us to free all strings
contained in the `strvec`, as the original vector will not be modified
anymore.

Furthermore, free both the `strvec` and the copied array to fix the
first memory leak.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agobuiltin/log: fix leaking branch name when creating cover letters
Patrick Steinhardt [Thu, 1 Aug 2024 10:38:16 +0000 (12:38 +0200)] 
builtin/log: fix leaking branch name when creating cover letters

When calling `make_cover_letter()` without a branch name, we try to
derive the branch name by calling `find_branch_name()`. But while this
function returns an allocated string, we never free the result and thus
have a memory leak. Fix this.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agobuiltin/replay: plug leaking `advance_name` variable
Patrick Steinhardt [Thu, 1 Aug 2024 10:38:11 +0000 (12:38 +0200)] 
builtin/replay: plug leaking `advance_name` variable

The `advance_name` variable can either contain a static string when
parsed via the `--advance` command line option or it may be an allocated
string when set via `determine_replay_mode()`. Because we cannot be sure
whether it is allocated or not we just didn't free it at all, resulting
in a memory leak.

Split up the variables such that we can track the static and allocated
strings separately and then free the allocated one to fix the memory
leak.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agoStart the 2.47 cycle
Junio C Hamano [Wed, 31 Jul 2024 20:02:10 +0000 (13:02 -0700)] 
Start the 2.47 cycle

Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agoMerge branch 'jc/how-to-maintain-updates'
Junio C Hamano [Wed, 31 Jul 2024 20:34:21 +0000 (13:34 -0700)] 
Merge branch 'jc/how-to-maintain-updates'

Doc update.

* jc/how-to-maintain-updates:
  howto-maintain: update daily tasks
  howto-maintain: cover a whole development cycle

10 months agoMerge branch 'tn/doc-commit-fix'
Junio C Hamano [Wed, 31 Jul 2024 20:34:20 +0000 (13:34 -0700)] 
Merge branch 'tn/doc-commit-fix'

Docfix.

* tn/doc-commit-fix:
  doc: remove dangling closing parenthesis

10 months agoMerge branch 'jc/doc-one-shot-export-with-shell-func'
Junio C Hamano [Wed, 31 Jul 2024 20:34:19 +0000 (13:34 -0700)] 
Merge branch 'jc/doc-one-shot-export-with-shell-func'

It has been documented that we avoid "VAR=VAL shell_func" and why.

* jc/doc-one-shot-export-with-shell-func:
  CodingGuidelines: document a shell that "fails" "VAR=VAL shell_func"

10 months agoMerge branch 'cp/unit-test-reftable-merged'
Junio C Hamano [Wed, 31 Jul 2024 20:34:19 +0000 (13:34 -0700)] 
Merge branch 'cp/unit-test-reftable-merged'

Another reftable test has been ported to use the unit test framework.

* cp/unit-test-reftable-merged:
  t-reftable-merged: add test for REFTABLE_FORMAT_ERROR
  t-reftable-merged: use reftable_ref_record_equal to compare ref records
  t-reftable-merged: add tests for reftable_merged_table_max_update_index
  t-reftable-merged: improve the const-correctness of helper functions
  t-reftable-merged: improve the test t_merged_single_record()
  t: harmonize t-reftable-merged.c with coding guidelines
  t: move reftable/merged_test.c to the unit testing framework

10 months agoMerge branch 'kn/ci-clang-format'
Junio C Hamano [Wed, 31 Jul 2024 20:34:18 +0000 (13:34 -0700)] 
Merge branch 'kn/ci-clang-format'

A CI job that use clang-format to check coding style issues in new
code has been added.

* kn/ci-clang-format:
  ci/style-check: add `RemoveBracesLLVM` in CI job
  check-whitespace: detect if no base_commit is provided
  ci: run style check on GitHub and GitLab
  clang-format: formalize some of the spacing rules
  clang-format: avoid spacing around bitfield colon
  clang-format: indent preprocessor directives after hash

10 months agoMerge branch 'jc/checkout-no-op-switch-errors'
Junio C Hamano [Wed, 31 Jul 2024 20:34:18 +0000 (13:34 -0700)] 
Merge branch 'jc/checkout-no-op-switch-errors'

"git checkout --ours" (no other arguments) complained that the
option is incompatible with branch switching, which is technically
correct, but found confusing by some users.  It now says that the
user needs to give pathspec to specify what paths to checkout.

* jc/checkout-no-op-switch-errors:
  checkout: special case error messages during noop switching

10 months agoMerge branch 'pw/add-patch-with-suppress-blank-empty'
Junio C Hamano [Wed, 31 Jul 2024 20:34:17 +0000 (13:34 -0700)] 
Merge branch 'pw/add-patch-with-suppress-blank-empty'

"git add -p" by users with diff.suppressBlankEmpty set to true
failed to parse the patch that represents an unmodified empty line
with an empty line (not a line with a single space on it), which
has been corrected.

* pw/add-patch-with-suppress-blank-empty:
  add-patch: use normalize_marker() when recounting edited hunk
  add-patch: handle splitting hunks with diff.suppressBlankEmpty

10 months agoMerge branch 'rj/make-cleanup'
Junio C Hamano [Wed, 31 Jul 2024 20:34:17 +0000 (13:34 -0700)] 
Merge branch 'rj/make-cleanup'

A build tweak knob has been simplified by not setting the value
that is already the default; another unused one has been removed.

* rj/make-cleanup:
  config.mak.uname: remove unused uname_P variable
  Makefile: drop -Wno-universal-initializer from SP_EXTRA_FLAGS

10 months agoMerge branch 'jt/doc-post-receive-hook-update'
Junio C Hamano [Wed, 31 Jul 2024 20:34:16 +0000 (13:34 -0700)] 
Merge branch 'jt/doc-post-receive-hook-update'

Doc update.

* jt/doc-post-receive-hook-update:
  doc: clarify post-receive hook behavior

10 months agoMerge branch 'ad/merge-with-diff-algorithm'
Junio C Hamano [Wed, 31 Jul 2024 20:34:16 +0000 (13:34 -0700)] 
Merge branch 'ad/merge-with-diff-algorithm'

Many Porcelain commands that internally use the merge machinery
were taught to consistently honor the diff.algorithm configuration.

* ad/merge-with-diff-algorithm:
  merge-recursive: honor diff.algorithm

10 months agoMerge branch 'rs/t-strvec-use-test-msg'
Junio C Hamano [Wed, 31 Jul 2024 20:34:15 +0000 (13:34 -0700)] 
Merge branch 'rs/t-strvec-use-test-msg'

Unit test clean-up.

* rs/t-strvec-use-test-msg:
  t-strvec: fix type mismatch in check_strvec
  t-strvec: improve check_strvec() output
  t-strvec: use test_msg()

10 months agot98xx: mark Perforce tests as memory-leak free
Patrick Steinhardt [Wed, 31 Jul 2024 10:37:56 +0000 (12:37 +0200)] 
t98xx: mark Perforce tests as memory-leak free

All the Perforce tests are free of memory leaks. This went unnoticed
because most folks do not have p4 and p4d installed on their computers.
Consequently, given that the prerequisites for running those tests
aren't fulfilled, `TEST_PASSES_SANITIZE_LEAK=check` won't notice that
those tests are indeed memory leak free.

Mark those tests accordingly.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agoci: update Perforce version to r23.2
Patrick Steinhardt [Wed, 31 Jul 2024 10:37:45 +0000 (12:37 +0200)] 
ci: update Perforce version to r23.2

Update our Perforce version from r21.2 to r23.2. Note that the updated
version is not the newest version. Instead, it is the last version where
the way that Perforce is being distributed remains the same as in r21.2.
Newer releases stopped distributing p4 and p4d executables as well as
the macOS archives directly and would thus require more work.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agot98xx: fix Perforce tests with p4d r23 and newer
Patrick Steinhardt [Wed, 31 Jul 2024 10:37:40 +0000 (12:37 +0200)] 
t98xx: fix Perforce tests with p4d r23 and newer

Some of the tests in t98xx modify the Perforce depot in ways that the
tool wouldn't normally allow. This is done to test behaviour of git-p4
in certain edge cases that we have observed in the wild, but which
should in theory not be possible.

Naturally, modifying the depot on disk directly is quite intimate with
the tool and thus prone to breakage when Perforce updates the way that
data is stored. And indeed, those tests are broken nowadays with r23 of
Perforce. While a file revision was previously stored as a plain file
"depot/file,v", it is now stored in a directory "depot/file,d" with
compression.

Adapt those tests to handle both old- and new-style depot layouts.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agoconvert: return early when not tracing
D Harithamma [Wed, 31 Jul 2024 13:33:59 +0000 (13:33 +0000)] 
convert: return early when not tracing

When Git adds a file requiring encoding conversion and tracing of encoding
conversion is not requested via the GIT_TRACE_WORKING_TREE_ENCODING
environment variable, the `trace_encoding()` function still allocates &
prepares "human readable" copies of the file contents before and after
conversion to show in the trace. This results in a high memory footprint
and increased runtime without providing any user-visible benefit.

This fix introduces an early exit from the `trace_encoding()` function
when tracing is not requested, preventing unnecessary memory allocation
and processing.

Signed-off-by: D Harithamma <harithamma.d@ibm.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agoDocumentation: consistently use spaces inside initializers
Patrick Steinhardt [Tue, 30 Jul 2024 07:24:52 +0000 (09:24 +0200)] 
Documentation: consistently use spaces inside initializers

Our coding guide is inconsistent with how it uses spaces inside of
initializers (`struct foo bar = { something }`). While we mostly carry
the space between open and closing braces and the initialized members,
in one case we don't.

Fix this one instance such that we consistently carry the space. This is
also consistent with how clang-format formats such initializers.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agoDocumentation: document idiomatic function names
Patrick Steinhardt [Tue, 30 Jul 2024 07:24:47 +0000 (09:24 +0200)] 
Documentation: document idiomatic function names

We semi-regularly have discussions around whether a function shall be
named `S_release()`, `S_clear()` or `S_free()`. Indeed, it may not be
obvious which of these is preferable as we never really defined what
each of these variants means exactly.

Carve out a space where we can add idiomatic names for common functions
in our coding guidelines and define each of those functions. Like this,
we can get to a shared understanding of their respective semantics and
can easily point towards our style guide in future discussions such that
our codebase becomes more consistent over time.

Note that the intent is not to rename all functions which violate these
semantics right away. Rather, the intent is to slowly converge towards a
common style over time.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agoDocumentation: document naming schema for structs and their functions
Patrick Steinhardt [Tue, 30 Jul 2024 07:24:43 +0000 (09:24 +0200)] 
Documentation: document naming schema for structs and their functions

We nowadays have a proper mishmash of struct-related functions that are
called `<verb>_<struct>` (e.g. `clear_prio_queue()`) versus functions
that are called `<struct>_<verb>` (e.g. `strbuf_clear()`). While the
former style may be easier to tie into a spoken conversation, most of
our communication happens in text anyway. Furthermore, prefixing
functions with the name of the structure they operate on makes it way
easier to group them together, see which functions are related, and will
also help folks who are using code completion.

Let's thus settle on one style, namely the one where functions start
with the name of the structure they operate on.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agoDocumentation: clarify indentation style for C preprocessor directives
Patrick Steinhardt [Tue, 30 Jul 2024 07:24:38 +0000 (09:24 +0200)] 
Documentation: clarify indentation style for C preprocessor directives

In the preceding commit, we have settled on using a single space per
nesting level to indent preprocessor directives. Clarify our coding
guidelines accordingly.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agoclang-format: fix indentation width for preprocessor directives
Patrick Steinhardt [Tue, 30 Jul 2024 07:24:33 +0000 (09:24 +0200)] 
clang-format: fix indentation width for preprocessor directives

In [1], we have improved our clang-format configuration to also specify
the style for how to indent preprocessor directives. But while we have
settled the question of where to put the indentation, either before or
after the hash sign, we didn't specify exactly how to indent.

With the current configuration, clang-format uses tabs to indent each
level of nested preprocessor directives, which is in fact unintentional
and never done in our codebase. Instead, we use a mixture of indenting
by either one or two spaces, where using a single space is somewhat more
common.

Adapt our clang-format configuration accordingly by specifying an
indentation width of one space.

[1]: <20240708092317.267915-1-karthik.188@gmail.com>

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agoMerge branch 'kn/ci-clang-format' into ps/doc-more-c-coding-guidelines
Junio C Hamano [Tue, 30 Jul 2024 20:47:26 +0000 (13:47 -0700)] 
Merge branch 'kn/ci-clang-format' into ps/doc-more-c-coding-guidelines

* kn/ci-clang-format:
  ci/style-check: add `RemoveBracesLLVM` in CI job
  check-whitespace: detect if no base_commit is provided
  ci: run style check on GitHub and GitLab
  clang-format: formalize some of the spacing rules
  clang-format: avoid spacing around bitfield colon
  clang-format: indent preprocessor directives after hash

10 months agorefs/reftable: stop using `the_repository`
Patrick Steinhardt [Tue, 30 Jul 2024 05:23:05 +0000 (07:23 +0200)] 
refs/reftable: stop using `the_repository`

Convert the reftable ref backend to stop using `the_repository` in favor
of the repo that gets passed in via `struct ref_store`.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agorefs/packed: stop using `the_repository`
Patrick Steinhardt [Tue, 30 Jul 2024 05:23:01 +0000 (07:23 +0200)] 
refs/packed: stop using `the_repository`

Convert the packed ref backend to stop using `the_repository` in favor
of the repo that gets passed in via `struct ref_store`.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agorefs/files: stop using `the_repository`
Patrick Steinhardt [Tue, 30 Jul 2024 05:22:56 +0000 (07:22 +0200)] 
refs/files: stop using `the_repository`

Convert the files ref backend to stop using `the_repository` in favor of
the repo that gets passed in via `struct ref_store`.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agorefs/files: stop using `the_repository` in `parse_loose_ref_contents()`
Patrick Steinhardt [Tue, 30 Jul 2024 05:22:51 +0000 (07:22 +0200)] 
refs/files: stop using `the_repository` in `parse_loose_ref_contents()`

We implicitly rely on `the_repository` in `parse_loose_ref_contents()`
by calling `parse_oid_hex()`. Convert the function to instead use
`parse_oid_hex_algop()` and have callers pass in the hash algorithm to
use.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agorefs: stop using `the_repository`
Patrick Steinhardt [Tue, 30 Jul 2024 05:22:46 +0000 (07:22 +0200)] 
refs: stop using `the_repository`

Convert "refs.c" to stop using `the_repository` in favor of the repo
that gets passed in via `struct ref_store`.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agogrep: -W: skip trailing empty lines at EOF, too
René Scharfe [Tue, 30 Jul 2024 14:18:54 +0000 (16:18 +0200)] 
grep: -W: skip trailing empty lines at EOF, too

4aa2c4753d (grep: -W: don't extend context to trailing empty lines,
2016-05-28) stopped showing empty lines at the end of function context
when using -W.  Do the same for trailing empty lines at the end of
files, for consistency -- it doesn't matter whether a function section
is ended by the next function or the end of the file.

Test it by adding a trailing empty line to the file used by the test
"grep -W" and leave its expected output the same.

Signed-off-by: René Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agopatch-id: tighten code to detect the patch header
Junio C Hamano [Tue, 30 Jul 2024 01:17:38 +0000 (18:17 -0700)] 
patch-id: tighten code to detect the patch header

The get_one_patchid() function unconditionally takes a line that
matches the patch header (namely, a line that begins with a full
object name, possibly prefixed by "commit" or "From" plus a space)
as the beginning of a patch.  Even when it is *not* looking for one
(namely, when the previous call found the patch header and returned,
and then we are called again to skip the log message and process the
patch whose header was found by the previous invocation).

As a consequence, a line in the commit log message that begins with
one of these patterns can be mistaken to start another patch, with
current message entirely skipped (because we haven't even reached
the patch at all).

Allow the caller to tell us if it called us already and saw the
patch header (in which case we shouldn't be looking for another one,
until we see the "diff" part of the patch; instead we simply should
be skipping these lines as part of the commit log message), and skip
the header processing logic when that is the case.  In the helper
function, it also needs to flip this "are we looking for a header?"
bit, once it finished skipping the commit log message and started
processing the patches, as the patch header of the _next_ message is
the only clue in the input that the current patch is done.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agopatch-id: rewrite code that detects the beginning of a patch
Junio C Hamano [Tue, 30 Jul 2024 01:17:37 +0000 (18:17 -0700)] 
patch-id: rewrite code that detects the beginning of a patch

The get_one_patchid() function reads input lines until it finds a
patch header (the line that begins a patch), whose beginning is one
of:

 (1) an "<object name>", which is what "git diff-tree --stdin" shows;
 (2) "commit <object name>", which is what "git log" shows; or
 (3) "From <object name>",  which is what "git log --format=email" shows.

When it finds such a line, it returns to the caller, reporting the
<object name> it found, and the size of the "patch" it processed.

The caller then calls the function again, which then ignores the
commit log message, and then processes the lines in the patch part
until it hits another "beginning of a patch".

The above logic was fairly easy to see until 2bb73ae8 (patch-id: use
starts_with() and skip_prefix(), 2016-05-28) reorganized the code,
which made another logic that has nothing to do with the "where does
the next patch begin?" logic, which came from 2485eab5
(git-patch-id: do not trip over "no newline" markers, 2011-02-17)
that ignores the "\ No newline at the end", rolled into the same
single if() statement.

Let's split it out.  The "\ No newline at the end" marker is part of
the patch, should not appear before we start reading the patch part,
and does not belong to the detection of patch header.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agopatch-id: make get_one_patchid() more extensible
Junio C Hamano [Tue, 30 Jul 2024 01:17:36 +0000 (18:17 -0700)] 
patch-id: make get_one_patchid() more extensible

We pass two independent Boolean flags (i.e. do we want the stable
variant of patch-id?  do we want to hash the stuff verbatim?) into
the function as two separate parameters.  Before adding the third
one and make the interface even wider, let's consolidate them into
a single flag word.

No changes in behaviour.  Just a trivial interface change.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agopatch-id: call flush_current_id() only when needed
Junio C Hamano [Tue, 30 Jul 2024 01:17:35 +0000 (18:17 -0700)] 
patch-id: call flush_current_id() only when needed

The caller passes a flag that is used to become no-op when calling
flush_current_id().  Instead of calling something that becomes a
no-op, teach the caller not to call it in the first place.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agot4204: patch-id supports various input format
Junio C Hamano [Tue, 30 Jul 2024 01:17:34 +0000 (18:17 -0700)] 
t4204: patch-id supports various input format

"git patch-id" was first developed to read from "git diff-tree
--stdin -p" output.  Later it was enhanced to read from "git
diff-tree --stdin -p -v", which was the downstream of an early
imitation of "git log" ("git rev-list" run in the upstream of a pipe
to feed the "diff-tree").  These days, we also read from "git
format-patch".

Their output begins slightly differently, but the patch-id computed
over them for the same commit should be the same.  Ensure that we
won't accidentally break this expectation.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
10 months agonotes: do not trigger editor when adding an empty note
David Disseldorp [Mon, 29 Jul 2024 15:14:00 +0000 (17:14 +0200)] 
notes: do not trigger editor when adding an empty note

With "git notes add -C $blob", the given blob contents are to be made
into a note without involving an editor.  But when "--allow-empty" is
given, the editor is invoked, which can cause problems for
non-interactive callers[1].

This behaviour started with 90bc19b3ae (notes.c: introduce
'--separator=<paragraph-break>' option, 2023-05-27), which changed
editor invocation logic to check for a zero length note_data buffer.

Restore the original behaviour of "git note" that takes the contents
given via the "-m", "-C", "-F" options without invoking an editor, by
checking for any prior parameter callbacks, indicated by a non-zero
note_data.msg_nr.  Remove the now-unneeded note_data.given flag.

Add a test for this regression by checking whether GIT_EDITOR is
invoked alongside "git notes add -C $empty_blob --allow-empty"

[1] https://github.com/ddiss/icyci/issues/12

Signed-off-by: David Disseldorp <ddiss@suse.de>
[jc: enhanced the test with -m/-F options]
Signed-off-by: Junio C Hamano <gitster@pobox.com>