]> git.ipfire.org Git - thirdparty/git.git/log
thirdparty/git.git
2 years agorevision.[ch]: document and move code declared around "init"
Ævar Arnfjörð Bjarmason [Wed, 13 Apr 2022 20:01:37 +0000 (22:01 +0200)] 
revision.[ch]: document and move code declared around "init"

A subsequent commit will add "REV_INFO_INIT" macro adjacent to
repo_init_revisions(), unfortunately between the "struct rev_info"
itself and that function we've added various miscellaneous code
between the two over the years.

Let's move that code either lower in revision.h, giving it API docs
while we're at it, or in cases where it wasn't public API at all move
it into revision.c No lines of code are changed here, only moved
around. The only changes are the addition of new API comments.

The "tree_difference" variable could also be declared like this, which
I think would be a lot clearer, but let's leave that for now to keep
this a move-only change:

static enum {
REV_TREE_SAME,
REV_TREE_NEW, /* Only new files */
REV_TREE_OLD, /* Only files removed */
REV_TREE_DIFFERENT, /* Mixed changes */
} tree_difference = REV_TREE_SAME;

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agorevisions API users: add straightforward release_revisions()
Ævar Arnfjörð Bjarmason [Wed, 13 Apr 2022 20:01:36 +0000 (22:01 +0200)] 
revisions API users: add straightforward release_revisions()

Add a release_revisions() to various users of "struct rev_list" in
those straightforward cases where we only need to add the
release_revisions() call to the end of a block, and don't need to
e.g. refactor anything to use a "goto cleanup" pattern.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agorevision.[ch]: provide and start using a release_revisions()
Ævar Arnfjörð Bjarmason [Wed, 13 Apr 2022 20:01:35 +0000 (22:01 +0200)] 
revision.[ch]: provide and start using a release_revisions()

The users of the revision.[ch] API's "struct rev_info" are a major
source of memory leaks in the test suite under SANITIZE=leak, which in
turn adds a lot of noise when trying to mark up tests with
"TEST_PASSES_SANITIZE_LEAK=true".

The users of that API are largely one-shot, e.g. "git rev-list" or
"git log", or the "git checkout" and "git stash" being modified here

For these callers freeing the memory is arguably a waste of time, but
in many cases they've actually been trying to free the memory, and
just doing that in a buggy manner.

Let's provide a release_revisions() function for these users, and
start migrating them over per the plan outlined in [1]. Right now this
only handles the "pending" member of the struct, but more will be
added in subsequent commits.

Even though we only clear the "pending" member now, let's not leave a
trap in code like the pre-image of index_differs_from(), where we'd
start doing the wrong thing as soon as the release_revisions() learned
to clear its "diffopt". I.e. we need to call release_revisions() after
we've inspected any state in "struct rev_info".

This leaves in place e.g. clear_pathspec(&rev.prune_data) in
stash_working_tree() in builtin/stash.c, subsequent commits will teach
release_revisions() to free "prune_data" and other members that in
some cases are individually cleared by users of "struct rev_info" by
reaching into its members. Those subsequent commits will remove the
relevant calls to e.g. clear_pathspec().

We avoid amending code in index_differs_from() in diff-lib.c as well
as wt_status_collect_changes_index(), has_unstaged_changes() and
has_uncommitted_changes() in wt-status.c in a way that assumes that we
are already clearing the "diffopt" member. That will be handled in a
subsequent commit.

1. https://lore.kernel.org/git/87a6k8daeu.fsf@evledraar.gmail.com/

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agococci: add and apply free_commit_list() rules
Ævar Arnfjörð Bjarmason [Wed, 13 Apr 2022 20:01:34 +0000 (22:01 +0200)] 
cocci: add and apply free_commit_list() rules

Add and apply coccinelle rules to remove "if (E)" before
"free_commit_list(E)", the function can accept NULL, and further
change cases where "E = NULL" followed to also be unconditionally.

The code changes in this commit were entirely made by the coccinelle
rule being added here, and applied with:

    make contrib/coccinelle/free.cocci.patch
    patch -p1 <contrib/coccinelle/free.cocci.patch

The only manual intervention here is that the the relevant code in
commit.c has been manually re-indented.

Suggested-by: Phillip Wood <phillip.wood123@gmail.com>
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agoformat-patch: don't leak "extra_headers" or "ref_message_ids"
Ævar Arnfjörð Bjarmason [Wed, 13 Apr 2022 20:01:33 +0000 (22:01 +0200)] 
format-patch: don't leak "extra_headers" or "ref_message_ids"

Fix two memory leaks in "struct rev_info" by freeing that memory in
cmd_format_patch(). These two are unusual special-cases in being in
the "struct rev_info", but not being "owned" by the code in
revision.c. I.e. they're members of the struct so that this code in
"builtin/log.c" can conveniently pass information code in
"log-tree.c".

See e.g. the make_cover_letter() caller of log_write_email_headers()
here in "builtin/log.c", and [1] for a demonstration of where the
"extra_headers" and "ref_message_ids" struct members are used.

See 20ff06805c6 (format-patch: resurrect extra headers from config,
2006-06-02) and d1566f7883f (git-format-patch: Make the second and
subsequent mails replies to the first, 2006-07-14) for the initial
introduction of "extra_headers" and "ref_message_ids".

We can count on repo_init_revisions() memset()-ing this data to 0
however, so we can count on it being either NULL or something we
allocated. In the case of "extra_headers" let's add a local "char *"
variable to hold it, to avoid the eventual cast from "const char *"
when we free() it.

1. https://lore.kernel.org/git/220401.868rsoogxf.gmgdl@evledraar.gmail.com/

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agostring_list API users: use string_list_init_{no,}dup
Ævar Arnfjörð Bjarmason [Wed, 13 Apr 2022 20:01:32 +0000 (22:01 +0200)] 
string_list API users: use string_list_init_{no,}dup

Follow-up on the introduction of string_list_init_nodup() and
string_list_init_dup() in the series merged in bd4232fac33 (Merge
branch 'ab/struct-init', 2021-07-16) and convert code that implicitly
relied on xcalloc() being equivalent to the initializer to use
xmalloc() and string_list_init_{no,}dup() instead.

In the case of get_unmerged() in merge-recursive.c we used the
combination of xcalloc() and assigning "1" to "strdup_strings" to get
what we'd get via string_list_init_dup(), let's use that instead.

Adjacent code in cmd_format_patch() will be changed in a subsequent
commit, since we're changing that let's change the other in-tree
patterns that do the same. Let's also convert a "x == NULL" to "!x"
per our CodingGuidelines, as we need to change the "if" line anyway.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agoblame: use "goto cleanup" for cleanup_scoreboard()
Ævar Arnfjörð Bjarmason [Wed, 13 Apr 2022 20:01:31 +0000 (22:01 +0200)] 
blame: use "goto cleanup" for cleanup_scoreboard()

Amend a freeing pattern added in 0906ac2b54b (blame: use changed-path
Bloom filters, 2020-04-16) to use a "goto cleanup", so that we can be
sure that we call cleanup_scoreboard().

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agot/helper/test-fast-rebase.c: don't leak "struct strbuf"
Ævar Arnfjörð Bjarmason [Wed, 13 Apr 2022 20:01:30 +0000 (22:01 +0200)] 
t/helper/test-fast-rebase.c: don't leak "struct strbuf"

Fix a memory leak that's been with us since f9500261e0a (fast-rebase:
write conflict state to working tree, index, and HEAD, 2021-05-20)
changed this code to move these strbuf_release() into an if/else
block.

We'll also add to "reflog_msg" in the "else" arm of the "if" block
being modified here, and we'll append to "branch_msg" in both
cases. But after f9500261e0a only the "if" block would free these two
"struct strbuf".

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agoMerge branch 'ds/partial-bundle-more' into ab/plug-leak-in-revisions
Junio C Hamano [Sun, 3 Apr 2022 22:03:05 +0000 (15:03 -0700)] 
Merge branch 'ds/partial-bundle-more' into ab/plug-leak-in-revisions

* ds/partial-bundle-more:
  pack-objects: lazily set up "struct rev_info", don't leak
  bundle: output hash information in 'verify'
  bundle: move capabilities to end of 'verify'
  pack-objects: parse --filter directly into revs.filter
  pack-objects: move revs out of get_object_list()
  list-objects-filter: remove CL_ARG__FILTER

2 years agopack-objects: lazily set up "struct rev_info", don't leak
Ævar Arnfjörð Bjarmason [Mon, 28 Mar 2022 15:43:18 +0000 (17:43 +0200)] 
pack-objects: lazily set up "struct rev_info", don't leak

In the preceding [1] (pack-objects: move revs out of
get_object_list(), 2022-03-22) the "repo_init_revisions()" was moved
to cmd_pack_objects() so that it unconditionally took place for all
invocations of "git pack-objects".

We'd thus start leaking memory, which is easily reproduced in
e.g. git.git by feeding e83c5163316 (Initial revision of "git", the
information manager from hell, 2005-04-07) to "git pack-objects";

    $ echo e83c5163316f89bfbde7d9ab23ca2e25604af290 | ./git pack-objects initial
    [...]
==19130==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 7120 byte(s) in 1 object(s) allocated from:
    #0 0x455308 in __interceptor_malloc (/home/avar/g/git/git+0x455308)
    #1 0x75b399 in do_xmalloc /home/avar/g/git/wrapper.c:41:8
    #2 0x75b356 in xmalloc /home/avar/g/git/wrapper.c:62:9
    #3 0x5d7609 in prep_parse_options /home/avar/g/git/diff.c:5647:2
    #4 0x5d415a in repo_diff_setup /home/avar/g/git/diff.c:4621:2
    #5 0x6dffbb in repo_init_revisions /home/avar/g/git/revision.c:1853:2
    #6 0x4f599d in cmd_pack_objects /home/avar/g/git/builtin/pack-objects.c:3980:2
    #7 0x4592ca in run_builtin /home/avar/g/git/git.c:465:11
    #8 0x457d81 in handle_builtin /home/avar/g/git/git.c:718:3
    #9 0x458ca5 in run_argv /home/avar/g/git/git.c:785:4
    #10 0x457b40 in cmd_main /home/avar/g/git/git.c:916:19
    #11 0x562259 in main /home/avar/g/git/common-main.c:56:11
    #12 0x7fce792ac7ec in __libc_start_main csu/../csu/libc-start.c:332:16
    #13 0x4300f9 in _start (/home/avar/g/git/git+0x4300f9)

SUMMARY: LeakSanitizer: 7120 byte(s) leaked in 1 allocation(s).
Aborted

Narrowly fixing that commit would have been easy, just add call
repo_init_revisions() right before get_object_list(), which is
effectively what was done before that commit.

But an unstated constraint when setting it up early is that it was
needed for the subsequent [2] (pack-objects: parse --filter directly
into revs.filter, 2022-03-22), i.e. we might have a --filter
command-line option, and need to either have the "struct rev_info"
setup when we encounter that option, or later.

Let's just change the control flow so that we'll instead set up the
"struct rev_info" only when we need it. Doing so leads to a bit more
verbosity, but it's a lot clearer what we're doing and why.

An earlier version of this commit[3] went behind
opt_parse_list_objects_filter()'s back by faking up a "struct option"
before calling it. Let's avoid that and instead create a blessed API
for this pattern.

We could furthermore combine the two get_object_list() invocations
here by having repo_init_revisions() invoked on &pfd.revs, but I think
clearly separating the two makes the flow clearer. Likewise
redundantly but explicitly (i.e. redundant v.s. a "{ 0 }") "0" to
"have_revs" early in cmd_pack_objects().

While we're at it add parentheses around the arguments to the OPT_*
macros in in list-objects-filter-options.h, as we need to change those
lines anyway. It doesn't matter in this case, but is good general
practice.

1. https://lore.kernel.org/git/619b757d98465dbc4995bdc11a5282fbfcbd3daa.1647970119.git.gitgitgadget@gmail.com
2. https://lore.kernel.org/git/97de926904988b89b5663bd4c59c011a1723a8f5.1647970119.git.gitgitgadget@gmail.com
3. https://lore.kernel.org/git/patch-1.1-193534b0f07-20220325T121715Z-avarab@gmail.com/

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agoThe 14th batch
Junio C Hamano [Wed, 23 Mar 2022 21:04:45 +0000 (14:04 -0700)] 
The 14th batch

Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agoMerge branch 'ab/plug-random-leaks'
Junio C Hamano [Wed, 23 Mar 2022 21:09:31 +0000 (14:09 -0700)] 
Merge branch 'ab/plug-random-leaks'

Double-free fix for a recently merged topic.

* ab/plug-random-leaks:
  diff.c: fix a double-free regression in a18d66cefb
  tests: demonstrate "show --word-diff --color-moved" regression

2 years agoMerge branch 'dc/complete-restore'
Junio C Hamano [Wed, 23 Mar 2022 21:09:31 +0000 (14:09 -0700)] 
Merge branch 'dc/complete-restore'

The command line completion support (in contrib/) learns to give
modified paths to the "git restore" command.

* dc/complete-restore:
  completion: tab completion of filenames for 'git restore'

2 years agoMerge branch 'jc/cat-file-batch-default-format-optim'
Junio C Hamano [Wed, 23 Mar 2022 21:09:31 +0000 (14:09 -0700)] 
Merge branch 'jc/cat-file-batch-default-format-optim'

Optimize away strbuf_expand() call with a hardcoded formatting logic
specific for the default format in the --batch and --batch-check
options of "git cat-file".

* jc/cat-file-batch-default-format-optim:
  cat-file: skip expanding default format

2 years agoMerge branch 'js/in-place-reverse-in-sequencer'
Junio C Hamano [Wed, 23 Mar 2022 21:09:31 +0000 (14:09 -0700)] 
Merge branch 'js/in-place-reverse-in-sequencer'

Code clean-up.

* js/in-place-reverse-in-sequencer:
  sequencer: use reverse_commit_list() helper

2 years agoMerge branch 'ac/test-lazy-fetch'
Junio C Hamano [Wed, 23 Mar 2022 21:09:30 +0000 (14:09 -0700)] 
Merge branch 'ac/test-lazy-fetch'

A new test to ensure a lazy fetching is not triggered when it
should not be.

* ac/test-lazy-fetch:
  partial-clone: add a partial-clone test case

2 years agoMerge branch 'ps/repack-with-server-info'
Junio C Hamano [Wed, 23 Mar 2022 21:09:30 +0000 (14:09 -0700)] 
Merge branch 'ps/repack-with-server-info'

"git repack" learned a new configuration to disable triggering of
age-old "update-server-info" command, which is rarely useful these
days.

* ps/repack-with-server-info:
  repack: add config to skip updating server info
  repack: refactor to avoid double-negation of update-server-info

2 years agoMerge branch 'ds/doc-maintenance-synopsis-fix'
Junio C Hamano [Wed, 23 Mar 2022 21:09:30 +0000 (14:09 -0700)] 
Merge branch 'ds/doc-maintenance-synopsis-fix'

Doc update.

* ds/doc-maintenance-synopsis-fix:
  maintenance: fix synopsis in documentation

2 years agoMerge branch 'ab/reflog-prep-fix'
Junio C Hamano [Wed, 23 Mar 2022 21:09:30 +0000 (14:09 -0700)] 
Merge branch 'ab/reflog-prep-fix'

Regression fix.

* ab/reflog-prep-fix:
  reflog: don't be noisy on empty reflogs

2 years agoMerge branch 'ep/remove-duplicated-includes'
Junio C Hamano [Wed, 23 Mar 2022 21:09:30 +0000 (14:09 -0700)] 
Merge branch 'ep/remove-duplicated-includes'

Code clean-up.

* ep/remove-duplicated-includes:
  attr.h: remove duplicate struct definition
  t/helper/test-run-command.c: delete duplicate include
  builtin/stash.c: delete duplicate include
  builtin/sparse-checkout.c: delete duplicate include
  builtin/gc.c: delete duplicate include
  attr.c: delete duplicate include

2 years agoMerge branch 'ep/t6423-modernize'
Junio C Hamano [Wed, 23 Mar 2022 21:09:29 +0000 (14:09 -0700)] 
Merge branch 'ep/t6423-modernize'

Code clean-up.

* ep/t6423-modernize:
  t6423-merge-rename-directories.sh: use the $(...) construct

2 years agoMerge branch 'jk/name-rev-w-genno'
Junio C Hamano [Wed, 23 Mar 2022 21:09:29 +0000 (14:09 -0700)] 
Merge branch 'jk/name-rev-w-genno'

"git name-rev" learned to use the generation numbers when setting
the lower bound of searching commits used to explain the revision,
when available, instead of committer time.

* jk/name-rev-w-genno:
  name-rev: use generation numbers if available

2 years agoMerge branch 'jd/userdiff-kotlin'
Junio C Hamano [Wed, 23 Mar 2022 21:09:29 +0000 (14:09 -0700)] 
Merge branch 'jd/userdiff-kotlin'

A new built-in userdiff driver for kotlin.

* jd/userdiff-kotlin:
  userdiff: add builtin diff driver for kotlin language.

2 years agoMerge branch 'bc/block-sha1-without-gcc-asm-extension'
Junio C Hamano [Wed, 23 Mar 2022 21:09:29 +0000 (14:09 -0700)] 
Merge branch 'bc/block-sha1-without-gcc-asm-extension'

Get rid of one use of __asm__() GCC extension that does not help us
much these days, which has an added advantage of not having to
worry about -pedantic complaining.

* bc/block-sha1-without-gcc-asm-extension:
  block-sha1: remove use of obsolete x86 assembly

2 years agoMerge branch 'gc/submodule-update-part1'
Junio C Hamano [Wed, 23 Mar 2022 21:09:28 +0000 (14:09 -0700)] 
Merge branch 'gc/submodule-update-part1'

Rewrite of "git submodule update" in C (early part).

* gc/submodule-update-part1:
  submodule--helper update-clone: check for --filter and --init
  submodule update: add tests for --filter
  submodule--helper: remove ensure-core-worktree
  submodule--helper update-clone: learn --init
  submodule--helper: allow setting superprefix for init_submodule()
  submodule--helper: refactor get_submodule_displaypath()
  submodule--helper run-update-procedure: learn --remote
  submodule--helper: don't use bitfield indirection for parse_options()
  submodule--helper: get remote names from any repository
  submodule--helper run-update-procedure: remove --suboid
  submodule--helper: reorganize code for sh to C conversion
  submodule--helper: remove update-module-mode
  submodule tests: test for init and update failure output

2 years agobundle: output hash information in 'verify'
Derrick Stolee [Tue, 22 Mar 2022 17:28:39 +0000 (17:28 +0000)] 
bundle: output hash information in 'verify'

The previous change moved the 'filter' capability to the end of the 'git
bundle verify' output. Now, add the 'object-format' capability to the
output, when it exists.

This change makes 'git bundle verify' output the hash used in all cases,
even if the capability is not in the bundle. This means that v2 bundles
will always output that they use "sha1". This might look noisy to some
users, but it does simplify the implementation and the test strategy for
this feature.

Since 'verify' ends early when a prerequisite commit is missing, we need
to insert this hash message carefully into our expected test output
throughout t6020.

Signed-off-by: Derrick Stolee <derrickstolee@github.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agobundle: move capabilities to end of 'verify'
Derrick Stolee [Tue, 22 Mar 2022 17:28:38 +0000 (17:28 +0000)] 
bundle: move capabilities to end of 'verify'

The 'filter' capability was added in 105c6f14a (bundle: parse filter
capability, 2022-03-09), but was added in a strange place in the 'git
bundle verify' output.

The tests for this show output like the following:

The bundle contains these 2 refs:
<COMMIT1> <REF1>
<COMMIT2> <REF2>
The bundle uses this filter: blob:none
The bundle records a complete history.

This looks very odd if we have a thin bundle that contains boundary
commits instead of a complete history:

The bundle contains these 2 refs:
<COMMIT1> <REF1>
<COMMIT2> <REF2>
The bundle uses this filter: blob:none
The bundle requires these 2 refs:
<COMMIT3>
<COMMIT4>

This separation between tip refs and boundary refs is unfortunate. Move
the filter capability output to the end of the output. Update the
documentation to match.

Signed-off-by: Derrick Stolee <derrickstolee@github.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agopack-objects: parse --filter directly into revs.filter
Derrick Stolee [Tue, 22 Mar 2022 17:28:37 +0000 (17:28 +0000)] 
pack-objects: parse --filter directly into revs.filter

The previous change moved the 'revs' variable into cmd_pack_objects()
and now we can remove the global filter_options in favor of revs.filter.

Signed-off-by: Derrick Stolee <derrickstolee@github.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agopack-objects: move revs out of get_object_list()
Derrick Stolee [Tue, 22 Mar 2022 17:28:36 +0000 (17:28 +0000)] 
pack-objects: move revs out of get_object_list()

We intend to parse the --filter option directly into revs.filter, but we
first need to move the 'revs' variable out of get_object_list() and pass
it as a pointer instead. This change only deals with the issues of
making that work.

Signed-off-by: Derrick Stolee <derrickstolee@github.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agolist-objects-filter: remove CL_ARG__FILTER
Derrick Stolee [Tue, 22 Mar 2022 17:28:35 +0000 (17:28 +0000)] 
list-objects-filter: remove CL_ARG__FILTER

We have established the command-line interface for the --[no-]filter
options for a while now, so we do not need a helper to make this
editable in the future.

Signed-off-by: Derrick Stolee <derrickstolee@github.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agoThe thirteenth batch
Junio C Hamano [Mon, 21 Mar 2022 21:18:51 +0000 (14:18 -0700)] 
The thirteenth batch

Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agoMerge branch 'jy/gitweb-no-need-for-meta'
Junio C Hamano [Mon, 21 Mar 2022 22:14:24 +0000 (15:14 -0700)] 
Merge branch 'jy/gitweb-no-need-for-meta'

Remove unneeded <meta http-equiv=content-type...> from gitweb
output.

* jy/gitweb-no-need-for-meta:
  gitweb: remove invalid http-equiv="content-type"
  comment: fix typo

2 years agoMerge branch 'pw/single-key-interactive'
Junio C Hamano [Mon, 21 Mar 2022 22:14:24 +0000 (15:14 -0700)] 
Merge branch 'pw/single-key-interactive'

The single-key interactive operation used by "git add -p" has been
made more robust.

* pw/single-key-interactive:
  add -p: disable stdin buffering when interactive.singlekey is set
  terminal: set VMIN and VTIME in non-canonical mode
  terminal: pop signal handler when terminal is restored
  terminal: always reset terminal when reading without echo

2 years agoMerge branch 'ds/partial-bundles'
Junio C Hamano [Mon, 21 Mar 2022 22:14:24 +0000 (15:14 -0700)] 
Merge branch 'ds/partial-bundles'

Bundle file format gets extended to allow a partial bundle,
filtered by similar criteria you would give when making a
partial/lazy clone.

* ds/partial-bundles:
  clone: fail gracefully when cloning filtered bundle
  bundle: unbundle promisor packs
  bundle: create filtered bundles
  rev-list: move --filter parsing into revision.c
  bundle: parse filter capability
  list-objects: handle NULL function pointers
  MyFirstObjectWalk: update recommended usage
  list-objects: consolidate traverse_commit_list[_filtered]
  pack-bitmap: drop filter in prepare_bitmap_walk()
  pack-objects: use rev.filter when possible
  revision: put object filter into struct rev_info
  list-objects-filter-options: create copy helper
  index-pack: document and test the --promisor option

2 years agoMerge branch 'ep/test-malloc-check-with-glibc-2.34'
Junio C Hamano [Mon, 21 Mar 2022 22:14:23 +0000 (15:14 -0700)] 
Merge branch 'ep/test-malloc-check-with-glibc-2.34'

The method to trigger malloc check used in our tests no longer work
with newer versions of glibc.

* ep/test-malloc-check-with-glibc-2.34:
  test-lib: declare local variables as local
  test-lib.sh: Use GLIBC_TUNABLES instead of MALLOC_CHECK_ on glibc >= 2.34

2 years agoMerge branch 'sm/no-git-in-upstream-of-pipe-in-tests'
Junio C Hamano [Mon, 21 Mar 2022 22:14:23 +0000 (15:14 -0700)] 
Merge branch 'sm/no-git-in-upstream-of-pipe-in-tests'

Test fixes.

* sm/no-git-in-upstream-of-pipe-in-tests:
  t0030-t0050: avoid pipes with Git on LHS
  t0001-t0028: avoid pipes with Git on LHS
  t0003: avoid pipes with Git on LHS

2 years agodiff.c: fix a double-free regression in a18d66cefb
Ævar Arnfjörð Bjarmason [Thu, 17 Mar 2022 14:55:35 +0000 (15:55 +0100)] 
diff.c: fix a double-free regression in a18d66cefb

My a18d66cefb9 (diff.c: free "buf" in diff_words_flush(), 2022-03-04)
has what it retrospect is a rather obvious bug (I don't know what I
was thinking, if it all): We use the "emitted_symbols" allocation in
append_emitted_diff_symbol() N times, but starting with a18d66cefb9
we'd free it after its first use!

The correct way to free this data would have been to add the free() to
the existing free_diff_words_data() function, so let's do that. The
"ecbdata->diff_words->opt->emitted_symbols" might be NULL, so let's
add a trivial free_emitted_diff_symbols() helper next to the function
that appends to it.

This fixes the "no effect on show from" leak tested for in the
preceding commit. Perhaps confusingly this change will skip that test
under SANITIZE=leak, but otherwise opt-in the
"t4015-diff-whitespace.sh" test.

The reason is that a18d66cefb9 "fixed" the leak in the preceding "no
effect on diff" test, but for the first call to diff_words_flush() the
"wol->buf" would be NULL, so we wouldn't double-free (and
SANITIZE=address would see nothing amiss). With this change we'll
still pass that test, showing that we've also fixed leaks on this
codepath.

We then have to skip the new "no effect on show" test because it
happens to trip over an unrelated memory leak (in revision.c). The
same goes for "move detection with submodules". Both of them pass with
SANITIZE=address though, which would error on the "no effect on show"
test before this change.

Reported-by: Michael J Gruber <git@grubix.eu>
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agotests: demonstrate "show --word-diff --color-moved" regression
Michael J Gruber [Thu, 17 Mar 2022 14:55:34 +0000 (15:55 +0100)] 
tests: demonstrate "show --word-diff --color-moved" regression

Add a failing test which demonstrates a regression in
a18d66cefb ("diff.c: free "buf" in diff_words_flush()", 2022-03-04),
the regression is discussed in detail in the subsequent commit. With
it running `git show --word-diff --color-moved` with SANITIZE=address
would emit:

==31191==ERROR: AddressSanitizer: attempting double-free on 0x617000021100 in thread T0:
    #0 0x49f0a2 in free (git+0x49f0a2)
    #1 0x9b0e4d in diff_words_flush diff.c:2153:3
    #2 0x9aed5d in fn_out_consume diff.c:2354:3
    #3 0xe092ab in consume_one xdiff-interface.c:43:9
    #4 0xe072eb in xdiff_outf xdiff-interface.c:76:10
    #5 0xec7014 in xdl_emit_diffrec xdiff/xutils.c:53:6
    [...]

0x617000021100 is located 0 bytes inside of 768-byte region [0x617000021100,0x617000021400)
freed by thread T0 here:
    #0 0x49f0a2 in free (git+0x49f0a2)
    [...(same stacktrace)...]

previously allocated by thread T0 here:
    #0 0x49f603 in __interceptor_realloc (git+0x49f603)
    #1 0xde4da4 in xrealloc wrapper.c:126:8
    #2 0x995dc5 in append_emitted_diff_symbol diff.c:794:2
    #3 0x96c44a in emit_diff_symbol diff.c:1527:3
    [...]

This was not caught by the test suite because we test `diff
--word-diff --color-moved` only so far.

Therefore, add a test for `show`, too.

Signed-off-by: Michael J Gruber <git@grubix.eu>
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agoThe twelfth batch
Junio C Hamano [Thu, 17 Mar 2022 00:45:59 +0000 (17:45 -0700)] 
The twelfth batch

Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agoMerge branch 'ab/string-list-count-in-size-t'
Junio C Hamano [Thu, 17 Mar 2022 00:53:09 +0000 (17:53 -0700)] 
Merge branch 'ab/string-list-count-in-size-t'

Count string_list items in size_t, not "unsigned int".

* ab/string-list-count-in-size-t:
  string-list API: change "nr" and "alloc" to "size_t"
  gettext API users: don't explicitly cast ngettext()'s "n"

2 years agoMerge branch 'ab/racy-hooks'
Junio C Hamano [Thu, 17 Mar 2022 00:53:09 +0000 (17:53 -0700)] 
Merge branch 'ab/racy-hooks'

Code clean-up to allow callers of run_commit_hook() to learn if it
got "success" because the hook succeeded or because there wasn't
any hook.

* ab/racy-hooks:
  hooks: fix an obscure TOCTOU "did we just run a hook?" race
  merge: don't run post-hook logic on --no-verify

2 years agoMerge branch 'ab/keep-git-exit-codes-in-tests'
Junio C Hamano [Thu, 17 Mar 2022 00:53:09 +0000 (17:53 -0700)] 
Merge branch 'ab/keep-git-exit-codes-in-tests'

Updates tests around the use of "test $(git cmd) = constant".

* ab/keep-git-exit-codes-in-tests:
  rev-list simplify tests: don't ignore "git" exit code
  checkout tests: don't ignore "git <cmd>" exit code
  apply tests: don't ignore "git ls-files" exit code, drop sub-shell
  gettext tests: don't ignore "test-tool regex" exit code
  rev-list tests: don't hide abort() in "test_expect_failure"
  diff tests: don't ignore "git rev-list" exit code
  notes tests: don't ignore "git" exit code
  rev-parse tests: don't ignore "git reflog" exit code
  merge tests: use "test_must_fail" instead of ad-hoc pattern
  apply tests: use "test_must_fail" instead of ad-hoc pattern
  diff tests: don't ignore "git diff" exit code in "read" loop
  diff tests: don't ignore "git diff" exit code
  read-tree tests: check "diff-files" exit code on failure
  tests: use "test_stdout_line_count", not "test $(git [...] | wc -l)"
  tests: change some 'test $(git) = "x"' to test_cmp

2 years agoMerge branch 'tk/t7063-chmtime-dirs-too'
Junio C Hamano [Thu, 17 Mar 2022 00:53:09 +0000 (17:53 -0700)] 
Merge branch 'tk/t7063-chmtime-dirs-too'

Teach "test-chmtime" to work on a directory and use it to avoid
having to wait for a second in a few places in tests.

* tk/t7063-chmtime-dirs-too:
  t7063: mtime-mangling instead of delays in untracked cache testing
  t/helper/test-chmtime: update mingw to support chmtime on directories

2 years agoMerge branch 'ds/commit-graph-gen-v2-fixes'
Junio C Hamano [Thu, 17 Mar 2022 00:53:09 +0000 (17:53 -0700)] 
Merge branch 'ds/commit-graph-gen-v2-fixes'

Fixes to the way generation number v2 in the commit-graph files are
(not) handled.

* ds/commit-graph-gen-v2-fixes:
  commit-graph: declare bankruptcy on GDAT chunks
  commit-graph: fix generation number v2 overflow values
  commit-graph: start parsing generation v2 (again)
  commit-graph: fix ordering bug in generation numbers
  t5318: extract helpers to lib-commit-graph.sh
  test-read-graph: include extra post-parse info

2 years agoMerge branch 'jc/stash-drop'
Junio C Hamano [Thu, 17 Mar 2022 00:53:08 +0000 (17:53 -0700)] 
Merge branch 'jc/stash-drop'

"git stash drop" is reimplemented as an internal call to
reflog_delete() function, instead of invoking "git reflog delete"
via run_command() API.

* jc/stash-drop:
  stash: call reflog_delete() in reflog.c
  reflog: libify delete reflog function and helpers
  stash: add tests to ensure reflog --rewrite --updatref behavior

2 years agoMerge branch 'tb/rename-remote-progress'
Junio C Hamano [Thu, 17 Mar 2022 00:53:08 +0000 (17:53 -0700)] 
Merge branch 'tb/rename-remote-progress'

"git remote rename A B", depending on the number of remote-tracking
refs involved, takes long time renaming them.  The command has been
taught to show progress bar while making the user wait.

* tb/rename-remote-progress:
  builtin/remote.c: show progress when renaming remote references
  builtin/remote.c: parse options in 'rename'

2 years agoMerge branch 'vd/sparse-read-tree'
Junio C Hamano [Thu, 17 Mar 2022 00:53:08 +0000 (17:53 -0700)] 
Merge branch 'vd/sparse-read-tree'

"git read-tree" has been made to be aware of the sparse-index
feature.

* vd/sparse-read-tree:
  read-tree: make three-way merge sparse-aware
  read-tree: make two-way merge sparse-aware
  read-tree: narrow scope of index expansion for '--prefix'
  read-tree: integrate with sparse index
  read-tree: expand sparse checkout test coverage
  read-tree: explicitly disallow prefixes with a leading '/'
  status: fix nested sparse directory diff in sparse index
  sparse-index: prevent repo root from becoming sparse

2 years agoMerge branch 'ab/object-file-api-updates'
Junio C Hamano [Thu, 17 Mar 2022 00:53:08 +0000 (17:53 -0700)] 
Merge branch 'ab/object-file-api-updates'

Object-file API shuffling.

* ab/object-file-api-updates:
  object-file API: pass an enum to read_object_with_reference()
  object-file.c: add a literal version of write_object_file_prepare()
  object-file API: have hash_object_file() take "enum object_type"
  object API: rename hash_object_file_literally() to write_*()
  object-file API: split up and simplify check_object_signature()
  object API users + docs: check <0, not !0 with check_object_signature()
  object API docs: move check_object_signature() docs to cache.h
  object API: correct "buf" v.s. "map" mismatch in *.c and *.h
  object-file API: have write_object_file() take "enum object_type"
  object-file API: add a format_object_header() function
  object-file API: return "void", not "int" from hash_object_file()
  object-file.c: split up declaration of unrelated variables

2 years agoMerge branch 'mf/fix-type-in-config-h'
Junio C Hamano [Thu, 17 Mar 2022 00:53:07 +0000 (17:53 -0700)] 
Merge branch 'mf/fix-type-in-config-h'

"git config -h" did not describe the "--type" option correctly.

* mf/fix-type-in-config-h:
  config: correct "--type" option in "git config -h" output

2 years agoMerge branch 'ps/fetch-mirror-optim'
Junio C Hamano [Thu, 17 Mar 2022 00:53:07 +0000 (17:53 -0700)] 
Merge branch 'ps/fetch-mirror-optim'

Various optimization for "git fetch".

* ps/fetch-mirror-optim:
  refs/files-backend: optimize reading of symbolic refs
  remote: read symbolic refs via `refs_read_symbolic_ref()`
  refs: add ability for backends to special-case reading of symbolic refs
  fetch: avoid lookup of commits when not appending to FETCH_HEAD
  upload-pack: look up "want" lines via commit-graph

2 years agoMerge branch 'tk/empty-untracked-cache'
Junio C Hamano [Thu, 17 Mar 2022 00:53:07 +0000 (17:53 -0700)] 
Merge branch 'tk/empty-untracked-cache'

The untracked cache newly computed weren't written back to the
on-disk index file when there is no other change to the index,
which has been corrected.

* tk/empty-untracked-cache:
  untracked-cache: write index when populating empty untracked cache
  t7519: populate untracked cache before test
  t7519: avoid file to index mtime race for untracked cache

2 years agoMerge branch 'ab/grep-patterntype'
Junio C Hamano [Thu, 17 Mar 2022 00:53:06 +0000 (17:53 -0700)] 
Merge branch 'ab/grep-patterntype'

Test fix-up for a topic already in master.

* ab/grep-patterntype:
  log tests: fix "abort tests early" regression in ff37a60c369

2 years agopartial-clone: add a partial-clone test case
Abhradeep Chakraborty [Wed, 16 Mar 2022 09:46:09 +0000 (09:46 +0000)] 
partial-clone: add a partial-clone test case

In a blobless-cloned repo, `git log --follow -- <path>` (`<path>` have
an exact OID rename) shouldn't download blob of the file from where the
new file is renamed.

Add a test case to verify it.

Signed-off-by: Abhradeep Chakraborty <chakrabortyabhradeep79@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agosequencer: use reverse_commit_list() helper
Jayati Shrivastava [Wed, 16 Mar 2022 11:20:23 +0000 (11:20 +0000)] 
sequencer: use reverse_commit_list() helper

Instead of creating a new allocation, reverse the original list
in-place by calling the reverse_commit_list() helper.

The original code discards the list "bases" after storing its
reverse copy in a newly created list "reversed".  If the code that
followed from here used both "bases" and "reversed", the
modification would not have worked, but since the original list
"bases" gets discarded, we can simply reverse "bases" in-place with
the reverse_commit_list() helper and reuse the same variable in the
code that follows.

builtin/merge.c has been left unmodified, since in its case, the
original list is needed separately from its reverse copy by the
code.

Signed-off-by: Jayati Shrivastava <gaurijove@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agocompletion: tab completion of filenames for 'git restore'
David Cantrell [Tue, 15 Mar 2022 22:13:57 +0000 (22:13 +0000)] 
completion: tab completion of filenames for 'git restore'

If no --args are present after 'git restore', it assumes that you
want to tab-complete one of the files with unstaged uncommitted
changes.

If a file has been staged, we don't want to list it, as restoring those
requires a slightly more complex `git restore --staged`, so we only list
those files that are --modified. While --committable also looks like
a good candidate, that includes changes that have been staged.

Signed-off-by: David Cantrell <david@cantrell.org.uk>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agomaintenance: fix synopsis in documentation
Derrick Stolee [Tue, 15 Mar 2022 17:41:44 +0000 (17:41 +0000)] 
maintenance: fix synopsis in documentation

The synopsis for 'git maintenance' did not include the commands other
than the 'run' command. Update this to include the others. The 'start'
command is the only one of these that parses additional options, and
then only the --scheduler option.

Also move the 'register' command down after 'stop' and before
'unregister' for a logical grouping of the commands instead of an
alphabetical one. The diff makes it look as three other commands are
moved up.

Signed-off-by: Derrick Stolee <derrickstolee@github.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agocat-file: skip expanding default format
John Cai [Tue, 15 Mar 2022 02:40:36 +0000 (02:40 +0000)] 
cat-file: skip expanding default format

When format is passed into --batch, --batch-check, --batch-command,
the format gets expanded. When nothing is passed in, the default format
is set and the expand_format() gets called.

We can save on these cycles by hardcoding how to print the
information when nothing is passed as the format, or when the default
format is passed. There is no need for the fully expanded format with
the default. Since batch_object_write() happens on every object provided
in batch mode, we get a nice performance improvement.

git rev-list --all > /tmp/all-obj.txt

git cat-file --batch-check </tmp/all-obj.txt

with HEAD^:

Time (mean ± σ): 57.6 ms ± 1.7 ms [User: 51.5 ms, System: 6.2 ms]
Range (min … max): 54.6 ms … 64.7 ms 50 runs

with HEAD:

Time (mean ± σ): 49.8 ms ± 1.7 ms [User: 42.6 ms, System: 7.3 ms]
Range (min … max): 46.9 ms … 55.9 ms 56 runs

If nothing is provided as a format argument, or if the default format is
passed, skip expanding of the format and print the object info with a
default format.

See https://lore.kernel.org/git/87eecf8ork.fsf@evledraar.gmail.com/

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: John Cai <johncai86@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agorepack: add config to skip updating server info
Patrick Steinhardt [Mon, 14 Mar 2022 07:42:51 +0000 (08:42 +0100)] 
repack: add config to skip updating server info

By default, git-repack(1) will update server info that is required by
the dumb HTTP transport. This can be skipped by passing the `-n` flag,
but what we're noticably missing is a config option to permanently
disable updating this information.

Add a new option "repack.updateServerInfo" which can be used to disable
the logic. Most hosting providers have turned off the dumb HTTP protocol
anyway, and on the client-side it woudln't typically be useful either.
Giving a persistent way to disable this feature thus makes quite some
sense to avoid wasting compute cycles and storage.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agorepack: refactor to avoid double-negation of update-server-info
Patrick Steinhardt [Mon, 14 Mar 2022 07:42:46 +0000 (08:42 +0100)] 
repack: refactor to avoid double-negation of update-server-info

By default, git-repack(1) runs `update_server_info()` to generate info
required for the dumb HTTP protocol. This can be disabled via the `-n`
flag, which then sets the `no_update_server_info` flag. Further down the
code this leads to some double-negation logic, which is about to become
more confusing as we're about to add a new config which allows the user
to permanently disable generation of the info.

Refactor the code to avoid the double-negation and add some tests which
verify that the flag continues to work as expected.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agoattr.h: remove duplicate struct definition
Elia Pinto [Mon, 14 Mar 2022 00:23:27 +0000 (00:23 +0000)] 
attr.h: remove duplicate struct definition

struct index_state is declared more than once.

Signed-off-by: Elia Pinto <gitter.spiros@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agoThe eleventh batch
Junio C Hamano [Sun, 13 Mar 2022 22:50:24 +0000 (22:50 +0000)] 
The eleventh batch

Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agoMerge branch 'ab/plug-random-leaks'
Junio C Hamano [Sun, 13 Mar 2022 22:56:18 +0000 (22:56 +0000)] 
Merge branch 'ab/plug-random-leaks'

Plug random memory leaks.

* ab/plug-random-leaks:
  repository.c: free the "path cache" in repo_clear()
  range-diff: plug memory leak in read_patches()
  range-diff: plug memory leak in common invocation
  lockfile API users: simplify and don't leak "path"
  commit-graph: stop fill_oids_from_packs() progress on error and free()
  commit-graph: fix memory leak in misused string_list API
  submodule--helper: fix trivial leak in module_add()
  transport: stop needlessly copying bundle header references
  bundle: call strvec_clear() on allocated strvec
  remote-curl.c: free memory in cmd_main()
  urlmatch.c: add and use a *_release() function
  diff.c: free "buf" in diff_words_flush()
  merge-base: free() allocated "struct commit **" list
  index-pack: fix memory leaks

2 years agoMerge branch 'nj/read-tree-doc-reffix'
Junio C Hamano [Sun, 13 Mar 2022 22:56:18 +0000 (22:56 +0000)] 
Merge branch 'nj/read-tree-doc-reffix'

Documentation mark-up fix.

* nj/read-tree-doc-reffix:
  Documentation: git-read-tree: separate links using commas

2 years agoMerge branch 'ps/fetch-atomic-fixup'
Junio C Hamano [Sun, 13 Mar 2022 22:56:17 +0000 (22:56 +0000)] 
Merge branch 'ps/fetch-atomic-fixup'

Test simplification.

* ps/fetch-atomic-fixup:
  t5503: simplify setup of test which exercises failure of backfill

2 years agoMerge branch 'fs/gpgsm-update'
Junio C Hamano [Sun, 13 Mar 2022 22:56:17 +0000 (22:56 +0000)] 
Merge branch 'fs/gpgsm-update'

Newer version of GPGSM changed its output in a backward
incompatible way to break our code that parses its output.  It also
added more processes our tests need to kill when cleaning up.
Adjustments have been made to accommodate these changes.

* fs/gpgsm-update:
  t/lib-gpg: kill all gpg components, not just gpg-agent
  t/lib-gpg: reload gpg components after updating trustlist
  gpg-interface/gpgsm: fix for v2.3

2 years agoMerge branch 'gc/parse-tree-indirect-errors'
Junio C Hamano [Sun, 13 Mar 2022 22:56:17 +0000 (22:56 +0000)] 
Merge branch 'gc/parse-tree-indirect-errors'

Check the return value from parse_tree_indirect() to turn segfaults
into calls to die().

* gc/parse-tree-indirect-errors:
  checkout, clone: die if tree cannot be parsed

2 years agoMerge branch 'en/merge-ort-align-verbosity-with-recursive'
Junio C Hamano [Sun, 13 Mar 2022 22:56:17 +0000 (22:56 +0000)] 
Merge branch 'en/merge-ort-align-verbosity-with-recursive'

Align the level of verbose output from the ort backend during inner
merge to that of the recursive backend.

* en/merge-ort-align-verbosity-with-recursive:
  merge-ort: exclude messages from inner merges by default

2 years agoMerge branch 'ab/make-optim-noop'
Junio C Hamano [Sun, 13 Mar 2022 22:56:17 +0000 (22:56 +0000)] 
Merge branch 'ab/make-optim-noop'

Makefile refactoring with a bit of suffixes rule stripping to
optimize the runtime overhead.

* ab/make-optim-noop:
  Makefiles: add and use wildcard "mkdir -p" template
  Makefile: add "$(QUIET)" boilerplate to shared.mak
  Makefile: move $(comma), $(empty) and $(space) to shared.mak
  Makefile: move ".SUFFIXES" rule to shared.mak
  Makefile: define $(LIB_H) in terms of $(FIND_SOURCE_FILES)
  Makefile: disable GNU make built-in wildcard rules
  Makefiles: add "shared.mak", move ".DELETE_ON_ERROR" to it
  scalar Makefile: use "The default target of..." pattern

2 years agoMerge branch 'ps/fetch-atomic'
Junio C Hamano [Sun, 13 Mar 2022 22:56:16 +0000 (22:56 +0000)] 
Merge branch 'ps/fetch-atomic'

"git fetch" can make two separate fetches, but ref updates coming
from them were in two separate ref transactions under "--atomic",
which has been corrected.

* ps/fetch-atomic:
  fetch: make `--atomic` flag cover pruning of refs
  fetch: make `--atomic` flag cover backfilling of tags
  refs: add interface to iterate over queued transactional updates
  fetch: report errors when backfilling tags fails
  fetch: control lifecycle of FETCH_HEAD in a single place
  fetch: backfill tags before setting upstream
  fetch: increase test coverage of fetches

2 years agot/helper/test-run-command.c: delete duplicate include
Elia Pinto [Sun, 13 Mar 2022 19:55:36 +0000 (19:55 +0000)] 
t/helper/test-run-command.c: delete duplicate include

parse-options.h is included more than once.

Signed-off-by: Elia Pinto <gitter.spiros@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agobuiltin/stash.c: delete duplicate include
Elia Pinto [Sun, 13 Mar 2022 19:55:35 +0000 (19:55 +0000)] 
builtin/stash.c: delete duplicate include

 entry.h is included more than once.

Signed-off-by: Elia Pinto <gitter.spiros@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agobuiltin/sparse-checkout.c: delete duplicate include
Elia Pinto [Sun, 13 Mar 2022 19:55:34 +0000 (19:55 +0000)] 
builtin/sparse-checkout.c: delete duplicate include

cache.h is included more than once.

Signed-off-by: Elia Pinto <gitter.spiros@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agobuiltin/gc.c: delete duplicate include
Elia Pinto [Sun, 13 Mar 2022 19:55:33 +0000 (19:55 +0000)] 
builtin/gc.c: delete duplicate include

object-store.h is included more than once.

Signed-off-by: Elia Pinto <gitter.spiros@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agoattr.c: delete duplicate include
Elia Pinto [Sun, 13 Mar 2022 19:55:32 +0000 (19:55 +0000)] 
attr.c: delete duplicate include

dir.h is included more than once

Signed-off-by: Elia Pinto <gitter.spiros@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agot6423-merge-rename-directories.sh: use the $(...) construct
Elia Pinto [Sun, 13 Mar 2022 17:28:29 +0000 (17:28 +0000)] 
t6423-merge-rename-directories.sh: use the $(...) construct

The Git CodingGuidelines prefer the $(...) construct for command
substitution instead of using the backquotes `...`.

The backquoted form is the traditional method for command
substitution, and is supported by POSIX.  However, all but the
simplest uses become complicated quickly.  In particular, embedded
command substitutions and/or the use of double quotes require
careful escaping with the backslash character.

The patch was generated by:

for _f in $(find . -name "*.sh")
do
shellcheck -i SC2006 -f diff ${_f} | ifne git apply -p2
done

and then carefully proof-read.

Signed-off-by: Elia Pinto <gitter.spiros@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agoname-rev: use generation numbers if available
Jacob Keller [Sat, 12 Mar 2022 00:00:15 +0000 (16:00 -0800)] 
name-rev: use generation numbers if available

If a commit in a sequence of linear history has a non-monotonically
increasing commit timestamp, git name-rev might not properly name the
commit.

This occurs because name-rev uses a heuristic of the commit date to
avoid searching down tags which lead to commits that are older than the
named commit. This is intended to avoid work on larger repositories.

This heuristic impacts git name-rev, and by extension git describe
--contains which is built on top of name-rev.

Further more, if --all or --annotate-stdin is used, the heuristic is not
enabled because the full history has to be analyzed anyways. This
results in some confusion if a user sees that --annotate-stdin works but
a normal name-rev does not.

If the repository has a commit graph, we can use the generation numbers
instead of using the commit dates. This is essentially the same check
except that generation numbers make it exact, where the commit date
heuristic could be incorrect due to clock errors.

Since we're extending the notion of cutoff to more than one variable,
create a series of functions for setting and checking the cutoff. This
avoids duplication and moves access of the global cutoff and
generation_cutoff to as few functions as possible.

Add several test cases including a test that covers the new commitGraph
behavior, as well as tests for --all and --annotate-stdin with and
without commitGraphs.

Signed-off-by: Jacob Keller <jacob.keller@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agoreflog: don't be noisy on empty reflogs
Ævar Arnfjörð Bjarmason [Thu, 10 Mar 2022 22:56:11 +0000 (23:56 +0100)] 
reflog: don't be noisy on empty reflogs

Fix a regression in my daf1d8285ee (reflog expire: don't use
lookup_commit_reference_gently(), 2021-12-22), in changing from
lookup_commit_reference_gently() to lookup_commit() we stopped trying
to call deref_tag() and parse_object() on the provided OID, but we
also started returning non-NULL for the null_oid().

As a result we'd emit an error() via mark_reachable() later in this
function as we tried to invoke parse_commit() on it.

Reported-by: Johannes Sixt <j6t@kdbg.org>
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Tested-by: Johannes Sixt <j6t@kdbg.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agouserdiff: add builtin diff driver for kotlin language.
Jaydeep P Das [Sat, 12 Mar 2022 04:48:32 +0000 (10:18 +0530)] 
userdiff: add builtin diff driver for kotlin language.

The xfuncname pattern finds func/class declarations
in diffs to display as a hunk header. The word_regex
pattern finds individual tokens in Kotlin code to generate
appropriate diffs.

This patch adds xfuncname regex and word_regex for Kotlin
language.

Signed-off-by: Jaydeep P Das <jaydeepjd.8914@gmail.com>
Acked-by: Johannes Sixt <j6t@kdbg.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agot0030-t0050: avoid pipes with Git on LHS
Shubham Mishra [Sat, 12 Mar 2022 06:21:26 +0000 (11:51 +0530)] 
t0030-t0050: avoid pipes with Git on LHS

Pipes ignore error codes of LHS command and thus we should not use
them with Git in tests. As an alternative, use a 'tmp' file to write
the Git output so we can test the exit code.

Signed-off-by: Shubham Mishra <shivam828787@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agot0001-t0028: avoid pipes with Git on LHS
Shubham Mishra [Sat, 12 Mar 2022 06:21:25 +0000 (11:51 +0530)] 
t0001-t0028: avoid pipes with Git on LHS

Pipes ignore error codes of LHS command and thus we should not use
them with Git in tests. As an alternative, use a 'tmp' file to write
the Git output so we can test the exit code.

Signed-off-by: Shubham Mishra <shivam828787@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agoblock-sha1: remove use of obsolete x86 assembly
brian m. carlson [Thu, 10 Mar 2022 17:47:50 +0000 (17:47 +0000)] 
block-sha1: remove use of obsolete x86 assembly

In the block SHA-1 code, we have special assembly code for i386 and
amd64 to perform rotations with assembly.  This is supposed to help pick
the correct rotation operation depending on which rotation is smaller,
which can help some systems perform slightly better, since any circular
rotation can be specified as either a rotate left or a rotate right.
However, this isn't needed, so we should remove it.

First, SHA-1, like SHA-2, uses fixed constant rotates.  Thus, all
rotation amounts are known at compile time and are in fact baked into
the code.  Fortunately, peephole optimizers recognize rotations
specified in the normal way and automatically emit the correct code,
including a preference for choosing a rotate left versus a rotate right.
This has been the case for well over a decade, and is a standard example
of the utility of a peephole optimizer.

Moreover, all modern CPUs, with the exception of extremely limited
embedded CPUs such as some Cortex-M processors, provide a barrel
shifter, which lets the CPU perform rotates of any bit amount in
constant time.  This is valuable for many cryptographic algorithms to
improve performance, and is required to prevent timing attacks in
algorithms which use data-dependent rotations (which don't include the
hash algorithms we use).  As a result, even though the compiler does the
correct optimization, it isn't even needed here and either a left or a
right rotate is equally acceptable.

In fact, the SHA-256 code already takes this into account and just
writes the simple code using an inline function to let the compiler
optimize it for us.

The downside of using this code, however, is that it uses a GCC
extension, which makes the compiler complain when using -pedantic unless
it's prefixed with __extension__.  We could fix that, but since it's
not needed, let's just remove it.  We haven't noticed this because
almost everyone uses the SHA1DC code instead, but it still shows up for
some people.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agotest-lib: declare local variables as local
Michael J Gruber [Wed, 9 Mar 2022 21:41:43 +0000 (22:41 +0100)] 
test-lib: declare local variables as local

131b94a10a ("test-lib.sh: Use GLIBC_TUNABLES instead of MALLOC_CHECK_ on
glibc >= 2.34", 2022-03-04) introduced "local" variables without
declaring them as such. This conflicts with their use in some tests (at
least when running them with dash), leading to test failures in:

t0006-date.sh
t2002-checkout-cache-u.sh
t3430-rebase-merges.sh
t4138-apply-ws-expansion.sh
t4124-apply-ws-rule.sh

Declare those variables as local to let the tests pass again.

Signed-off-by: Michael J Gruber <git@grubix.eu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agoThe tenth batch
Junio C Hamano [Wed, 9 Mar 2022 21:38:46 +0000 (13:38 -0800)] 
The tenth batch

Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agoMerge branch 'ab/help-fixes'
Junio C Hamano [Wed, 9 Mar 2022 21:38:24 +0000 (13:38 -0800)] 
Merge branch 'ab/help-fixes'

Updates to how command line options to "git help" are handled.

* ab/help-fixes:
  help: don't print "\n" before single-section output
  help: add --no-[external-commands|aliases] for use with --all
  help: error if [-a|-g|-c] and [-i|-m|-w] are combined
  help: correct usage & behavior of "git help --all"
  help: note the option name on option incompatibility
  help.c: split up list_all_cmds_help() function
  help tests: test "git" and "git help [-a|-g] spacing
  help.c: use puts() instead of printf{,_ln}() for consistency
  help doc: add missing "]" to "[-a|--all]"

2 years agoMerge branch 'ab/c99-variadic-macros'
Junio C Hamano [Wed, 9 Mar 2022 21:38:24 +0000 (13:38 -0800)] 
Merge branch 'ab/c99-variadic-macros'

Remove the escape hatch we added when we introduced the weather
balloon to use variadic macros unconditionally, to make it official
that we now have a hard dependency on the feature.

* ab/c99-variadic-macros:
  C99: remove hardcoded-out !HAVE_VARIADIC_MACROS code
  git-compat-util.h: clarify GCC v.s. C99-specific in comment

2 years agoMerge branch 'hn/reftable-no-empty-keys'
Junio C Hamano [Wed, 9 Mar 2022 21:38:24 +0000 (13:38 -0800)] 
Merge branch 'hn/reftable-no-empty-keys'

General clean-up in reftable implementation, including
clarification of the API documentation, tightening the code to
honor documented length limit, etc.

* hn/reftable-no-empty-keys:
  reftable: rename writer_stats to reftable_writer_stats
  reftable: add test for length of disambiguating prefix
  reftable: ensure that obj_id_len is >= 2 on writing
  reftable: avoid writing empty keys at the block layer
  reftable: add a test that verifies that writing empty keys fails
  reftable: reject 0 object_id_len
  Documentation: object_id_len goes up to 31

2 years agoMerge branch 'jc/cat-file-batch-commands'
Junio C Hamano [Wed, 9 Mar 2022 21:38:24 +0000 (13:38 -0800)] 
Merge branch 'jc/cat-file-batch-commands'

"git cat-file" learns "--batch-command" mode, which is a more
flexible interface than the existing "--batch" or "--batch-check"
modes, to allow different kinds of inquiries made.

* jc/cat-file-batch-commands:
  cat-file: add --batch-command mode
  cat-file: add remove_timestamp helper
  cat-file: introduce batch_mode enum to replace print_contents
  cat-file: rename cmdmode to transform_mode

2 years agoMerge branch 'pw/xdiff-alloc-fail'
Junio C Hamano [Wed, 9 Mar 2022 21:38:23 +0000 (13:38 -0800)] 
Merge branch 'pw/xdiff-alloc-fail'

Improve failure case behaviour of xdiff library when memory
allocation fails.

* pw/xdiff-alloc-fail:
  xdiff: handle allocation failure when merging
  xdiff: refactor a function
  xdiff: handle allocation failure in patience diff
  xdiff: fix a memory leak

2 years agoMerge branch 'en/present-despite-skipped'
Junio C Hamano [Wed, 9 Mar 2022 21:38:23 +0000 (13:38 -0800)] 
Merge branch 'en/present-despite-skipped'

In sparse-checkouts, files mis-marked as missing from the working tree
could lead to later problems.  Such files were hard to discover, and
harder to correct.  Automatically detecting and correcting the marking
of such files has been added to avoid these problems.

* en/present-despite-skipped:
  repo_read_index: add config to expect files outside sparse patterns
  Accelerate clear_skip_worktree_from_present_files() by caching
  Update documentation related to sparsity and the skip-worktree bit
  repo_read_index: clear SKIP_WORKTREE bit from files present in worktree
  unpack-trees: fix accidental loss of user changes
  t1011: add testcase demonstrating accidental loss of user modifications

2 years agoclone: fail gracefully when cloning filtered bundle
Derrick Stolee [Wed, 9 Mar 2022 16:01:43 +0000 (16:01 +0000)] 
clone: fail gracefully when cloning filtered bundle

Users can create a new repository using 'git clone <bundle-file>'. The
new "@filter" capability for bundles means that we can generate a bundle
that does not contain all reachable objects, even if the header has no
negative commit OIDs.

It is feasible to think that we could make a filtered bundle work with
the command

  git clone --filter=$filter --bare <bundle-file>

or possibly replacing --bare with --no-checkout. However, this requires
having some repository-global config that specifies the specified object
filter and notifies Git about the existence of promisor pack-files.
Without a remote, that is currently impossible.

As a stop-gap, parse the bundle header during 'git clone' and die() with
a helpful error message instead of the current behavior of failing due
to "missing objects".

Most of the existing logic for handling bundle clones actually happens
in fetch-pack.c, but that logic is the same as if the user specified
'git fetch <bundle>', so we want to avoid failing to fetch a filtered
bundle when in an existing repository that has the proper config set up
for at least one remote.

Carefully comment around the test that this is not the desired long-term
behavior of 'git clone' in this case, but instead that we need to do
more work before that is possible.

Signed-off-by: Derrick Stolee <derrickstolee@github.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agobundle: unbundle promisor packs
Derrick Stolee [Wed, 9 Mar 2022 16:01:42 +0000 (16:01 +0000)] 
bundle: unbundle promisor packs

In order to have a valid pack-file after unbundling a bundle that has
the 'filter' capability, we need to generate a .promisor file. The
bundle does not promise _where_ the objects can be found, but we can
expect that these bundles will be unbundled in repositories with
appropriate promisor remotes that can find those missing objects.

Use the 'git index-pack --promisor=<message>' option to create this
.promisor file. Add "from-bundle" as the message to help anyone diagnose
issues with these promisor packs.

Signed-off-by: Derrick Stolee <derrickstolee@github.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agobundle: create filtered bundles
Derrick Stolee [Wed, 9 Mar 2022 16:01:41 +0000 (16:01 +0000)] 
bundle: create filtered bundles

A previous change allowed Git to parse bundles with the 'filter'
capability. Now, teach Git to create bundles with this option.

Some rearranging of code is required to get the option parsing in the
correct spot. There are now two reasons why we might need capabilities
(a new hash algorithm or an object filter) so that is pulled out into a
place where we can check both at the same time.

The --filter option is parsed as part of setup_revisions(), but it
expected the --objects flag, too. That flag is somewhat implied by 'git
bundle' because it creates a pack-file walking objects, but there is
also a walk that walks the revision range expecting only commits. Make
this parsing work by setting 'revs.tree_objects' and 'revs.blob_objects'
before the call to setup_revisions().

Signed-off-by: Derrick Stolee <derrickstolee@github.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agorev-list: move --filter parsing into revision.c
Derrick Stolee [Wed, 9 Mar 2022 16:01:40 +0000 (16:01 +0000)] 
rev-list: move --filter parsing into revision.c

Now that 'struct rev_info' has a 'filter' member and most consumers of
object filtering are using that member instead of an external struct,
move the parsing of the '--filter' option out of builtin/rev-list.c and
into revision.c.

This use within handle_revision_pseudo_opt() allows us to find the
option within setup_revisions() if the arguments are passed directly. In
the case of a command such as 'git blame', the arguments are first
scanned and checked with parse_revision_opt(), which complains about the
option, so 'git blame --filter=blob:none <file>' does not become valid
with this change.

Some commands, such as 'git diff' gain this option without having it
make an effect. And 'git diff --objects' was already possible, but does
not actually make sense in that builtin.

The key addition that is coming is 'git bundle create --filter=<X>' so
we can create bundles containing promisor packs. More work is required
to make them fully functional, but that will follow.

Signed-off-by: Derrick Stolee <derrickstolee@github.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agobundle: parse filter capability
Derrick Stolee [Wed, 9 Mar 2022 16:01:39 +0000 (16:01 +0000)] 
bundle: parse filter capability

The v3 bundle format has capabilities, allowing newer versions of Git to
create bundles with newer features. Older versions that do not
understand these new capabilities will fail with a helpful warning.

Create a new capability allowing Git to understand that the contained
pack-file is filtered according to some object filter. Typically, this
filter will be "blob:none" for a blobless partial clone.

This change teaches Git to parse this capability, place its value in the
bundle header, and demonstrate this understanding by adding a message to
'git bundle verify'.

Since we will use gently_parse_list_objects_filter() outside of
list-objects-filter-options.c, make it an external method and move its
API documentation to before its declaration.

Signed-off-by: Derrick Stolee <derrickstolee@github.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agolist-objects: handle NULL function pointers
Ævar Arnfjörð Bjarmason [Wed, 9 Mar 2022 16:01:38 +0000 (16:01 +0000)] 
list-objects: handle NULL function pointers

If a caller to traverse_commit_list() specifies the options for the
--objects flag but does not specify a show_object function pointer, the
result is a segfault. This is currently visible by running 'git bundle
create --objects HEAD'.

We could fix this problem by supplying a no-op callback in
builtin/bundle.c, but that only solves the problem for one builtin,
leaving this segfault open for other callers.

Replace all callers of the show_commit and show_object function pointers
in list-objects.c to call helper functions show_commit() and
show_object() which check that the given context has non-NULL functions
before passing the necessary data. One extra benefit is that it reduces
duplication due to passing ctx->show_data to every caller.

Test that this segfault no longer occurs for 'git bundle'.

Co-authored-by: Derrick Stolee <derrickstolee@github.com>
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Derrick Stolee <derrickstolee@github.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agoMyFirstObjectWalk: update recommended usage
Derrick Stolee [Wed, 9 Mar 2022 16:01:37 +0000 (16:01 +0000)] 
MyFirstObjectWalk: update recommended usage

The previous change consolidated traverse_commit_list() and
traverse_commit_list_filtered(). This allows us to simplify the
recommended usage in MyFirstObjectWalk.txt to use this new set of
values.

While here, add some clarification on the difference between the two
methods.

Signed-off-by: Derrick Stolee <derrickstolee@github.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agolist-objects: consolidate traverse_commit_list[_filtered]
Derrick Stolee [Wed, 9 Mar 2022 16:01:36 +0000 (16:01 +0000)] 
list-objects: consolidate traverse_commit_list[_filtered]

Now that all consumers of traverse_commit_list_filtered() populate the
'filter' member of 'struct rev_info', we can drop that parameter from
the method prototype to simplify things. In addition, the only thing
different now between traverse_commit_list_filtered() and
traverse_commit_list() is the presence of the 'omitted' parameter, which
is only non-NULL for one caller. We can consolidate these two methods by
having one call the other and use the simpler form everywhere the
'omitted' parameter would be NULL.

Signed-off-by: Derrick Stolee <derrickstolee@github.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agopack-bitmap: drop filter in prepare_bitmap_walk()
Derrick Stolee [Wed, 9 Mar 2022 16:01:35 +0000 (16:01 +0000)] 
pack-bitmap: drop filter in prepare_bitmap_walk()

Now that all consumers of prepare_bitmap_walk() have populated the
'filter' member of 'struct rev_info', we can drop that extra parameter
from the method and access it directly from the 'struct rev_info'.

Signed-off-by: Derrick Stolee <derrickstolee@github.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agopack-objects: use rev.filter when possible
Derrick Stolee [Wed, 9 Mar 2022 16:01:34 +0000 (16:01 +0000)] 
pack-objects: use rev.filter when possible

In builtin/pack-objects.c, we use a 'filter_options' global to populate
the --filter=<X> argument. The previous change created a pointer to a
filter option in 'struct rev_info', so we can use that pointer here as a
start to simplifying some usage of object filters.

Signed-off-by: Derrick Stolee <derrickstolee@github.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 years agorevision: put object filter into struct rev_info
Derrick Stolee [Wed, 9 Mar 2022 16:01:33 +0000 (16:01 +0000)] 
revision: put object filter into struct rev_info

Placing a 'struct list_objects_filter_options' within 'struct rev_info'
will assist making some bookkeeping around object filters in the future.

For now, let's use this new member to remove a static global instance of
the struct from builtin/rev-list.c.

Signed-off-by: Derrick Stolee <derrickstolee@github.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>