]> git.ipfire.org Git - thirdparty/git.git/log
thirdparty/git.git
4 years agobuilt-in add -p: handle diff.algorithm
Johannes Schindelin [Tue, 14 Jan 2020 18:43:46 +0000 (18:43 +0000)] 
built-in add -p: handle diff.algorithm

The Perl version of `git add -p` reads the config setting
`diff.algorithm` and if set, uses it to generate the diff using the
specified algorithm.

This patch ports that functionality to the C version.

Note: just like `git-add--interactive.perl`, we do _not_ respect this
config setting in `git add -i`'s `diff` command, but _only_ in the
`patch` command.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 years agobuilt-in add -p: support interactive.diffFilter
Johannes Schindelin [Tue, 14 Jan 2020 18:43:45 +0000 (18:43 +0000)] 
built-in add -p: support interactive.diffFilter

The Perl version supports post-processing the colored diff (that is
generated in addition to the uncolored diff, intended to offer a
prettier user experience) by a command configured via that config
setting, and now the built-in version does that, too.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 years agot3701: adjust difffilter test
Johannes Schindelin [Tue, 14 Jan 2020 18:43:44 +0000 (18:43 +0000)] 
t3701: adjust difffilter test

In 42f7d45428e (add--interactive: detect bogus diffFilter output,
2018-03-03), we added a test case that verifies that the diffFilter
feature complains appropriately when the output is too short.

In preparation for the upcoming change where the built-in `add -p` is
taught to respect that setting, let's adjust that test a little. The
problem is that `echo too-short` is configured as diffFilter, and it
does not read the `stdin`. When calling it through `pipe_command()`, it
is therefore possible that we try to feed the `diff` to it while it is
no longer listening, and we receive a `SIGPIPE`.

The Perl code apparently handles this in a way similar to an
end-of-file, but taking a step back, we realize that a diffFilter that
does not even _look_ at its standard input is very unrealistic. The
entire point of this feature is to transform the diff, not to ignore it
altogether.

So let's modify the test case to reflect that insight: instead of
printing some bogus text, let's use a diffFilter that deletes the first
line of the diff instead.

This still tests for the same thing, but it does not confuse the
built-in `add -p` with that `SIGPIPE`.

Helped-by: SZEDER Gábor <szeder.dev@gmail.com>
Helped-by: Jeff King <peff@peff.net>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 years agocommit --interactive: make it work with the built-in `add -i`
Johannes Schindelin [Sat, 21 Dec 2019 21:57:16 +0000 (21:57 +0000)] 
commit --interactive: make it work with the built-in `add -i`

The built-in `git add -i` machinery obviously has its `the_repository`
structure initialized at the point where `cmd_commit()` calls it, and
therefore does not look at the environment variable `GIT_INDEX_FILE`.

But when being called from `commit --interactive`, it has to, because
the index was already locked in that case, and we want to ask the
interactive add machinery to work on the `index.lock` file instead of
the `index` file.

Technically, we could teach `run_add_i()`, or for that matter
`run_add_p()`, to look specifically at that environment variable, but
the entire idea of passing in a parameter of type `struct repository *`
is to allow working on multiple repositories (and their index files)
independently.

So let's instead override the `index_file` field of that structure
temporarily.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 years agobuilt-in add -p: implement the "worktree" patch modes
Johannes Schindelin [Sat, 21 Dec 2019 21:57:15 +0000 (21:57 +0000)] 
built-in add -p: implement the "worktree" patch modes

This is a straight-forward port of 2f0896ec3ad4 (restore: support
--patch, 2019-04-25) which added support for `git restore -p`.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 years agobuilt-in add -p: implement the "checkout" patch modes
Johannes Schindelin [Sat, 21 Dec 2019 21:57:14 +0000 (21:57 +0000)] 
built-in add -p: implement the "checkout" patch modes

This patch teaches the built-in `git add -p` machinery all the tricks it
needs to know in order to act as the work horse for `git checkout -p`.

Apart from the minor changes (slightly reworded messages, different
`diff` and `apply --check` invocations), it requires a new function to
actually apply the changes, as `git checkout -p` is a bit special in
that respect: when the desired changes do not apply to the index, but
apply to the work tree, Git does not fail straight away, but asks the
user whether to apply the changes to the worktree at least.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 years agobuilt-in stash: use the built-in `git add -p` if so configured
Johannes Schindelin [Sat, 21 Dec 2019 21:57:13 +0000 (21:57 +0000)] 
built-in stash: use the built-in `git add -p` if so configured

The scripted version of `git stash` called directly into the Perl script
`git-add--interactive.perl`, and this was faithfully converted to C.

However, we have a much better way to do this now: call the internal API
directly, which will now incidentally also respect the
`add.interactive.useBuiltin` setting. Let's just do this.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 years agolegacy stash -p: respect the add.interactive.usebuiltin setting
Johannes Schindelin [Sat, 21 Dec 2019 21:57:12 +0000 (21:57 +0000)] 
legacy stash -p: respect the add.interactive.usebuiltin setting

As `git add` traditionally did not expose the `--patch=<mode>` modes via
command-line options, the scripted version of `git stash` had to call
`git add--interactive` directly.

But this prevents the built-in `add -p` from kicking in, as
`add--interactive` is the scripted version (which does not have a
"fall-back" to the built-in version).

So let's introduce support for internal switch for `git add` that the
scripted `git stash` can use to call the appropriate backend (scripted
or built-in, depending on `add.interactive.useBuiltin`).

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 years agobuilt-in add -p: implement the "stash" and "reset" patch modes
Johannes Schindelin [Sat, 21 Dec 2019 21:57:11 +0000 (21:57 +0000)] 
built-in add -p: implement the "stash" and "reset" patch modes

The `git stash` and `git reset` commands support a `--patch` option, and
both simply hand off to `git add -p` to perform that work. Let's teach
the built-in version of that command to be able to perform that work, too.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 years agobuilt-in add -p: prepare for patch modes other than "stage"
Johannes Schindelin [Sat, 21 Dec 2019 21:57:10 +0000 (21:57 +0000)] 
built-in add -p: prepare for patch modes other than "stage"

The Perl script backing `git add -p` is used not only for that command,
but also for `git stash -p`, `git reset -p` and `git checkout -p`.

In preparation for teaching the C version of `git add -p` to support
also the latter commands, let's abstract away what is "stage" specific
into a dedicated data structure describing the differences between the
patch modes.

Finally, please note that the Perl version tries to make sure that the
diffs are only generated for the modified files. This is not actually
necessary, as the calls to Git's diff machinery already perform that
work, and perform it well. This makes it unnecessary to port the
`FILTER` field of the `%patch_modes` struct, as well as the
`get_diff_reference()` function.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 years agobuilt-in add -p: show helpful hint when nothing can be staged
Johannes Schindelin [Fri, 13 Dec 2019 08:08:06 +0000 (08:08 +0000)] 
built-in add -p: show helpful hint when nothing can be staged

This patch will make `git add -p` show "No changes." or "Only binary
files changed." in that case.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 years agobuilt-in add -p: only show the applicable parts of the help text
Johannes Schindelin [Fri, 13 Dec 2019 08:08:05 +0000 (08:08 +0000)] 
built-in add -p: only show the applicable parts of the help text

When displaying the only hunk in a file's diff, the prompt already
excludes the commands to navigate to the previous/next hunk.

Let's also let the `?` command show only the help lines corresponding to
the commands that are displayed in the prompt.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 years agobuilt-in add -p: implement the 'q' ("quit") command
Johannes Schindelin [Fri, 13 Dec 2019 08:08:04 +0000 (08:08 +0000)] 
built-in add -p: implement the 'q' ("quit") command

This command is actually very similar to the 'd' ("do not stage this
hunk or any of the later hunks in the file") command: it just does
something on top, namely leave the loop and return a value indicating
that we're quittin'.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 years agobuilt-in add -p: implement the '/' ("search regex") command
Johannes Schindelin [Fri, 13 Dec 2019 08:08:03 +0000 (08:08 +0000)] 
built-in add -p: implement the '/' ("search regex") command

This patch implements the hunk searching feature in the C version of
`git add -p`.

A test is added to verify that this behavior matches the one of the Perl
version of `git add -p`.

Note that this involves a change of behavior: the Perl version uses (of
course) the Perl flavor of regular expressions, while this patch uses
the regcomp()/regexec(), i.e. POSIX extended regular expressions. In
practice, this behavior change is unlikely to matter.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 years agobuilt-in add -p: implement the 'g' ("goto") command
Johannes Schindelin [Fri, 13 Dec 2019 08:08:02 +0000 (08:08 +0000)] 
built-in add -p: implement the 'g' ("goto") command

With this patch, it is now possible to see a summary of the available
hunks and to navigate between them (by number).

A test is added to verify that this behavior matches the one of the Perl
version of `git add -p`.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 years agobuilt-in add -p: implement hunk editing
Johannes Schindelin [Fri, 13 Dec 2019 08:08:01 +0000 (08:08 +0000)] 
built-in add -p: implement hunk editing

Just like `git add --edit` allows the user to edit the diff before it is
being applied to the index, this feature allows the user to edit the
diff *hunk*.

Naturally, it gets a bit more complicated here because the result has
to play well with the remaining hunks of the overall diff. Therefore,
we have to do a loop in which we let the user edit the hunk, then test
whether the result would work, and if not, drop the edits and let the
user decide whether to try editing the hunk again.

Note: in contrast to the Perl version, we use the same diff
"coalescing" (i.e. merging overlapping hunks into a single one) also for
the check after editing, and we introduce a new flag for that purpose
that asks the `reassemble_patch()` function to pretend that all hunks
were selected for use.

This allows us to continue to run `git apply` *without* the
`--allow-overlap` option (unlike the Perl version), and it also fixes
two known breakages in `t3701-add-interactive.sh` (which we cannot mark
as resolved so far because the Perl script version is still the default
and continues to have those breakages).

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 years agostrbuf: add a helper function to call the editor "on an strbuf"
Johannes Schindelin [Fri, 13 Dec 2019 08:08:00 +0000 (08:08 +0000)] 
strbuf: add a helper function to call the editor "on an strbuf"

This helper supports the scenario where Git has a populated `strbuf` and
wants to let the user edit it interactively.

In `git add -p`, we will use this to allow interactive hunk editing: the
diff hunks are already in memory, but we need to write them out to a
file so that an editor can be launched, then read everything back once
the user is done editing.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 years agobuilt-in add -p: coalesce hunks after splitting them
Johannes Schindelin [Fri, 13 Dec 2019 08:07:59 +0000 (08:07 +0000)] 
built-in add -p: coalesce hunks after splitting them

This is considered "the right thing to do", according to 933e44d3a0
("add -p": work-around an old laziness that does not coalesce hunks,
2011-04-06).

Note: we cannot simply modify the hunks while merging them; Once we
implement hunk editing, we will call `reassemble_patch()` whenever a
hunk is edited, therefore we must not modify the hunks (because the user
might e.g. hit `K` and change their mind whether to stage the previous
hunk).

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 years agobuilt-in add -p: implement the hunk splitting feature
Johannes Schindelin [Fri, 13 Dec 2019 08:07:58 +0000 (08:07 +0000)] 
built-in add -p: implement the hunk splitting feature

If this developer's workflow is any indication, then this is *the* most
useful feature of Git's interactive `add `command.

Note: once again, this is not a verbatim conversion from the Perl code
to C: the `hunk_splittable()` function, for example, essentially did all
the work of splitting the hunk, just to find out whether more than one
hunk would have been the result (and then tossed that result into the
trash). In C we instead count the number of resulting hunks (without
actually doing the work of splitting, but just counting the transitions
from non-context lines to context lines), and store that information
with the hunk, and we do that *while* parsing the diff in the first
place.

Another deviation: the built-in `git add -p` was designed with a single
strbuf holding the diff (and another one holding the colored diff, if
that one was asked for) in mind, and hunks essentially store just the
start and end offsets pointing into that strbuf. As a consequence, when
we split hunks, we now use a special mode where the hunk header is
generated dynamically, and only the rest of the hunk is stored using
such start/end offsets. This way, we also avoid the frequent
formatting/re-parsing of the hunk header of the Perl version.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 years agobuilt-in add -p: show different prompts for mode changes and deletions
Johannes Schindelin [Fri, 13 Dec 2019 08:07:57 +0000 (08:07 +0000)] 
built-in add -p: show different prompts for mode changes and deletions

Just like the Perl version, we now helpfully ask the user whether they
want to stage a mode change, or a deletion.

Note that we define the prompts in an array, in preparation for a later
patch that changes those prompts to yet different versions for `git
reset -p`, `git stash -p` and `git checkout -p` (which all call the `git
add -p` machinery to do the actual work).

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 years agobuilt-in app -p: allow selecting a mode change as a "hunk"
Johannes Schindelin [Fri, 13 Dec 2019 08:07:56 +0000 (08:07 +0000)] 
built-in app -p: allow selecting a mode change as a "hunk"

This imitates the way the Perl version treats mode changes: it offers
the mode change up for the user to decide, as if it was a diff hunk.

In contrast to the Perl version, we make use of the fact that the mode
line is the first hunk, and explicitly strip out that line from the diff
header if that "hunk" was not selected to be applied, and skipping that
hunk while coalescing the diff. The Perl version plays some kind of diff
line lego instead.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 years agobuilt-in add -p: handle deleted empty files
Johannes Schindelin [Fri, 13 Dec 2019 08:07:55 +0000 (08:07 +0000)] 
built-in add -p: handle deleted empty files

This addresses the same problem as 24ab81ae4d (add-interactive: handle
deletion of empty files, 2009-10-27), although in a different way: we
not only stick the "deleted file" line into its own pseudo hunk, but
also the entire remainder (if any) of the same diff.

That way, we do not have to play any funny games with regards to
coalescing the diff after the user selected what (possibly pseudo-)hunks
to stage.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 years agobuilt-in add -p: support multi-file diffs
Johannes Schindelin [Fri, 13 Dec 2019 08:07:54 +0000 (08:07 +0000)] 
built-in add -p: support multi-file diffs

For simplicity, the initial implementation in C handled only a single
modified file. Now it handles an arbitrary number of files.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 years agobuilt-in add -p: offer a helpful error message when hunk navigation failed
Johannes Schindelin [Fri, 13 Dec 2019 08:07:53 +0000 (08:07 +0000)] 
built-in add -p: offer a helpful error message when hunk navigation failed

... just like the Perl version currently does...

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 years agobuilt-in add -p: color the prompt and the help text
Johannes Schindelin [Fri, 13 Dec 2019 08:07:52 +0000 (08:07 +0000)] 
built-in add -p: color the prompt and the help text

... just like the Perl version ;-)

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 years agobuilt-in add -p: adjust hunk headers as needed
Johannes Schindelin [Fri, 13 Dec 2019 08:07:51 +0000 (08:07 +0000)] 
built-in add -p: adjust hunk headers as needed

When skipping a hunk that adds a different number of lines than it
removes, we need to adjust the subsequent hunk headers of non-skipped
hunks: in pathological cases, the context is not enough to determine
precisely where the patch should be applied.

This problem was identified in 23fea4c240 (t3701: add failing test for
pathological context lines, 2018-03-01) and fixed in the Perl version in
fecc6f3a68 (add -p: adjust offsets of subsequent hunks when one is
skipped, 2018-03-01).

And this patch fixes it in the C version of `git add -p`.

In contrast to the Perl version, we try to keep the extra text on the
hunk header (which typically contains the signature of the function
whose code is changed in the hunk) intact.

Note: while the C version does not support staging mode changes at this
stage, we already prepare for this by simply skipping the hunk header if
both old and new offset is 0 (this cannot happen for regular hunks, and
we will use this as an indicator that we are looking at a special hunk).

Likewise, we already prepare for hunk splitting by handling the absence
of extra text in the hunk header gracefully: only the first split hunk
will have that text, the others will not (indicated by an empty extra
text start/end range). Preparing for hunk splitting already at this
stage avoids an indentation change of the entire hunk header-printing
block later, and is almost as easy to review as without that handling.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 years agobuilt-in add -p: show colored hunks by default
Johannes Schindelin [Fri, 13 Dec 2019 08:07:50 +0000 (08:07 +0000)] 
built-in add -p: show colored hunks by default

Just like the Perl version, we now generate two diffs if `color.diff` is
set: one with and one without color. Then we parse them in parallel and
record which hunks start at which offsets in both.

Note that this is a (slight) deviation from the way the Perl version did
it: we are no longer reading the output of `diff-files` line by line
(which is more natural for Perl than for C), but in one go, and parse
everything later, so we might just as well do it in synchrony.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 years agobuilt-in add -i: wire up the new C code for the `patch` command
Johannes Schindelin [Fri, 13 Dec 2019 08:07:49 +0000 (08:07 +0000)] 
built-in add -i: wire up the new C code for the `patch` command

The code in `git-add--interactive.perl` that takes care of the `patch`
command can look quite intimidating. There are so many modes in which it
can be called, for example.

But for the `patch` command in `git add -i`, only one mode is relevant:
the `stage` mode. And we just implemented the beginnings of that mode in
C so far. So let's use it when `add.interactive.useBuiltin=true`.

Now, while the code in `add-patch.c` is far from reaching feature parity
with the code in `git-add--interactive.perl` (color is not implemented,
the diff algorithm cannot be configured, the colored diff cannot be
post-processed via `interactive.diffFilter`, many commands are
unimplemented yet, etc), hooking it all up with the part of `git add -i`
that is already converted to C makes it easier to test and develop it.

Note: at this stage, both the `add.interactive.useBuiltin` config
setting is still safely opt-in, and will probably be fore quite some
time, to allow for thorough testing "in the wild" without adversely
affecting existing users.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 years agobuilt-in add -i: start implementing the `patch` functionality in C
Johannes Schindelin [Fri, 13 Dec 2019 08:07:48 +0000 (08:07 +0000)] 
built-in add -i: start implementing the `patch` functionality in C

In the previous steps, we re-implemented the main loop of `git add -i`
in C, and most of the commands.

Notably, we left out the actual functionality of `patch`, as the
relevant code makes up more than half of `git-add--interactive.perl`,
and is actually pretty independent of the rest of the commands.

With this commit, we start to tackle that `patch` part. For better
separation of concerns, we keep the code in a separate file,
`add-patch.c`. The new code is still guarded behind the
`add.interactive.useBuiltin` config setting, and for the moment,
it can only be called via `git add -p`.

The actual functionality follows the original implementation of
5cde71d64aff (git-add --interactive, 2006-12-10), but not too closely
(for example, we use string offsets rather than copying strings around,
and after seeing whether the `k` and `j` commands are applicable, in the
C version we remember which previous/next hunk was undecided, and use it
rather than looking again when the user asked to jump).

As a further deviation from that commit, We also use a comma instead of
a slash to separate the available commands in the prompt, as the current
version of the Perl script does this, and we also add a line about the
question mark ("print help") to the help text.

While it is tempting to use this conversion of `git add -p` as an excuse
to work on `apply_all_patches()` so that it does _not_ want to read a
file from `stdin` or from a file, but accepts, say, an `strbuf` instead,
we will refrain from this particular rabbit hole at this stage.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 years agoapply --allow-overlap: fix a corner case
Johannes Schindelin [Fri, 6 Dec 2019 13:08:25 +0000 (13:08 +0000)] 
apply --allow-overlap: fix a corner case

Yes, yes, this is supposed to be only a band-aid option for `git add -p`
not Doing The Right Thing. But as long as we carry the `--allow-overlap`
option, we might just as well get it right.

This fixes the case where one hunk inserts a line before the first line,
and is followed by a hunk whose context overlaps with the first one's
and which appends a line at the end.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 years agogit add -p: use non-zero exit code when the diff generation failed
Johannes Schindelin [Fri, 6 Dec 2019 13:08:24 +0000 (13:08 +0000)] 
git add -p: use non-zero exit code when the diff generation failed

The first thing `git add -p` does is to generate a diff. If this diff
cannot be generated, `git add -p` should not continue as if nothing
happened, but instead fail.

What we *actually* do here is much broader: we now verify for *every*
`run_cmd_pipe()` call that the spawned process actually succeeded.

Note that we have to change two callers in this patch, as we need to
store the spawned process' output in a local variable, which means that
the callers can no longer decide whether to interpret the `return <$fh>`
in array or in scalar context.

This bug was noticed while writing a test case for the diff.algorithm
feature, and we let that test case double as a regression test for this
fixed bug, too.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 years agot3701: verify that the diff.algorithm config setting is handled
Johannes Schindelin [Fri, 6 Dec 2019 13:08:23 +0000 (13:08 +0000)] 
t3701: verify that the diff.algorithm config setting is handled

Without this patch, there is actually no test in Git's test suite that
covers the diff.algorithm feature. Let's add one.

We do this by passing a bogus value and then expecting `git diff-files`
to produce the appropriate error message.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 years agot3701: verify the shown messages when nothing can be added
Johannes Schindelin [Fri, 6 Dec 2019 13:08:22 +0000 (13:08 +0000)] 
t3701: verify the shown messages when nothing can be added

In preparation for re-implementing `git add -p` in pure C (where we will
purposefully keep the implementation of `git add -p` separate from the
implementation of `git add -i`), let's verify that the user is told the
same things as in the Perl version when the diff file is either empty or
contains only entries about binary files.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 years agot3701: add a test for the different `add -p` prompts
Johannes Schindelin [Fri, 6 Dec 2019 13:08:21 +0000 (13:08 +0000)] 
t3701: add a test for the different `add -p` prompts

The `git add -p` command offers different prompts for regular diff hunks
vs mode change pseudo hunks vs diffs deleting files.

Let's cover this in the regresion test suite, in preparation for
re-implementing `git add -p` in C.

For the mode change prompt, we use a trick that lets this test case pass
even on systems without executable bit, i.e. where `core.filemode =
false` (such as Windows): we first add the file to the index with `git
add --chmod=+x`, and then call `git add -p` with `core.filemode` forced
to `true`. The file on disk has no executable bit set, therefore we will
see a mode change.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 years agot3701: avoid depending on the TTY prerequisite
Johannes Schindelin [Fri, 6 Dec 2019 13:08:20 +0000 (13:08 +0000)] 
t3701: avoid depending on the TTY prerequisite

The TTY prerequisite is a rather heavy one: it not only requires Perl to
work, but also the IO/Pty.pm module (with native support, and it
requires pseudo terminals, too).

In particular, test cases marked with the TTY prerequisite would be
skipped in Git for Windows' SDK.

In the case of `git add -p`, we do not actually need that big a hammer,
as we do not want to test any functionality that requires a pseudo
terminal; all we want is for the interactive add command to use color,
even when being called from within the test suite.

And we found exactly such a trick earlier already: when we added a test
case to verify that the main loop of `git add -i` is colored
appropriately. Let's use that trick instead of the TTY prerequisite.

While at it, we avoid the pipes, as we do not want a SIGPIPE to break
the regression test cases (which will be much more likely when we do not
run everything through Perl because that is inherently slower).

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 years agot3701: add a test for advanced split-hunk editing
Johannes Schindelin [Fri, 6 Dec 2019 13:08:19 +0000 (13:08 +0000)] 
t3701: add a test for advanced split-hunk editing

In this developer's workflows, it often happens that a hunk needs to be
edited in a way that adds lines, and sometimes even reduces the number
of context lines.

Let's add a regression test for this.

Note that just like the preceding test case, the new test case is *not*
handled gracefully by the current `git add -p`. It will be handled
correctly by the upcoming built-in `git add -p`, though.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 years agobuilt-in add -i: offer the `quit` command
Johannes Schindelin [Fri, 29 Nov 2019 21:11:49 +0000 (21:11 +0000)] 
built-in add -i: offer the `quit` command

We do not really want to `exit()` here, of course, as this is safely
libified code.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 years agobuilt-in add -i: re-implement the `diff` command
Johannes Schindelin [Fri, 29 Nov 2019 21:11:48 +0000 (21:11 +0000)] 
built-in add -i: re-implement the `diff` command

It is not only laziness that we simply spawn `git diff -p --cached`
here: this command needs to use the pager, and the pager needs to exit
when the diff is done. Currently we do not have any way to make that
happen if we run the diff in-process. So let's just spawn.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 years agobuilt-in add -i: implement the `patch` command
Johannes Schindelin [Fri, 29 Nov 2019 21:11:47 +0000 (21:11 +0000)] 
built-in add -i: implement the `patch` command

Well, it is not a full implementation yet. In the interest of making
this easy to review (and easy to keep bugs out), we still hand off to
the Perl script to do the actual work.

The `patch` functionality actually makes up for more than half of the
1,800+ lines of `git-add--interactive.perl`. It will be ported from Perl
to C incrementally, later.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 years agobuilt-in add -i: re-implement `add-untracked` in C
Johannes Schindelin [Fri, 29 Nov 2019 21:11:46 +0000 (21:11 +0000)] 
built-in add -i: re-implement `add-untracked` in C

This is yet another command, ported to C. It builds nicely on the
support functions introduced for other commands, with the notable
difference that only names are displayed for untracked files, no
file type or diff summary.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 years agobuilt-in add -i: re-implement `revert` in C
Johannes Schindelin [Fri, 29 Nov 2019 21:11:45 +0000 (21:11 +0000)] 
built-in add -i: re-implement `revert` in C

This is a relatively straight-forward port from the Perl version, with
the notable exception that we imitate `git reset -- <paths>` in the C
version rather than the convoluted `git ls-tree HEAD -- <paths> | git
update-index --index-info` followed by `git update-index --force-remove
-- <paths>` for the missed ones.

While at it, we fix the pretty obvious bug where the `revert` command
offers to unstage files that do not have staged changes.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 years agobuilt-in add -i: implement the `update` command
Johannes Schindelin [Fri, 29 Nov 2019 21:11:44 +0000 (21:11 +0000)] 
built-in add -i: implement the `update` command

After `status` and `help`, it is now time to port the `update` command
to C, the second command that is shown in the main loop menu of `git add
-i`.

This `git add -i` command is the first one which lets the user choose a
subset of a list of files, and as such, this patch lays the groundwork
for the other commands of that category:

- It teaches the `print_file_item()` function to show a unique prefix
  if we found any (the code to find it had been added already in the
  previous patch where we colored the unique prefixes of the main loop
  commands, but that patch uses the `print_command_item()` function to
  display the menu items).

- This patch also adds the help text that is shown when the user input
  to select items from the shown list could not be parsed.

- As `get_modified_files()` clears the list of files, it now has to take
  care of clearing the _full_ `prefix_item_list` lest the `sorted` and
  `selected` fields go stale and inconsistent.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 years agobuilt-in add -i: prepare for multi-selection commands
Johannes Schindelin [Fri, 29 Nov 2019 21:11:43 +0000 (21:11 +0000)] 
built-in add -i: prepare for multi-selection commands

The `update`, `revert` and `add-untracked` commands allow selecting
multiple entries. Let's extend the `list_and_choose()` function to
accommodate those use cases.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 years agobuilt-in add -i: allow filtering the modified files list
Johannes Schindelin [Fri, 29 Nov 2019 21:11:42 +0000 (21:11 +0000)] 
built-in add -i: allow filtering the modified files list

In the `update` command of `git add -i`, we are primarily interested in the
list of modified files that have worktree (i.e. unstaged) changes.

At the same time, we need to determine _also_ the staged changes, to be
able to produce the full added/deleted information.

The Perl script version of `git add -i` has a parameter of the
`list_modified()` function for that matter. In C, we can be a lot more
precise, using an `enum`.

The C implementation of the filter also has an easier time to avoid
unnecessary work, simply by using an adaptive order of the `diff-index`
and `diff-files` phases, and then skipping files in the second phase
when they have not been seen in the first phase.

Seeing as we change the meaning of the `phase` field, we rename it to
`mode` to reflect that the order depends on the exact invocation of the
`git add -i` command.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 years agoadd-interactive: make sure to release `rev.prune_data`
Johannes Schindelin [Fri, 29 Nov 2019 21:11:41 +0000 (21:11 +0000)] 
add-interactive: make sure to release `rev.prune_data`

During a review, Junio Hamano pointed out that the `rev.prune_data` was
copied from another pathspec but never cleaned up.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 years agobuilt-in add -i: implement the `help` command
Slavica Đukić [Fri, 15 Nov 2019 11:11:20 +0000 (11:11 +0000)] 
built-in add -i: implement the `help` command

This imitates the code to show the help text from the Perl script
`git-add--interactive.perl` in the built-in version.

To make sure that it renders exactly like the Perl version of `git add
-i`, we also add a test case for that to `t3701-add-interactive.sh`.

Signed-off-by: Slavica Đukić <slawica92@hotmail.com>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 years agobuilt-in add -i: use color in the main loop
Slavica Đukić [Fri, 15 Nov 2019 11:11:19 +0000 (11:11 +0000)] 
built-in add -i: use color in the main loop

The error messages as well as the unique prefixes are colored in `git
add -i` by default; We need to do the same in the built-in version.

Signed-off-by: Slavica Đukić <slawica92@hotmail.com>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 years agobuilt-in add -i: support `?` (prompt help)
Johannes Schindelin [Fri, 15 Nov 2019 11:11:18 +0000 (11:11 +0000)] 
built-in add -i: support `?` (prompt help)

With this change, we print out the same colored help text that the
Perl-based `git add -i` prints in the main loop when question mark is
entered.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 years agobuilt-in add -i: show unique prefixes of the commands
Johannes Schindelin [Fri, 15 Nov 2019 11:11:17 +0000 (11:11 +0000)] 
built-in add -i: show unique prefixes of the commands

Just like in the Perl script `git-add--interactive.perl`, for each
command a unique prefix is determined (if there exists any within the
given parameters), and shown in the list, and accepted as a shortcut for
the command.

To determine the unique prefixes, as well as to look up the command in
question, we use a copy of the list and sort it.

While this might seem like overkill for a single command, it will make
much more sense when all the commands are implemented, and when we reuse
the same logic to present a list of files to edit, with convenient
unique prefixes.

At the start of the development of this patch series, a dedicated data
structure was introduced that imitated the Trie that the Perl version
implements. However, this was deemed overkill, and we now simply sort
the list before determining the length of the unique prefixes by looking
at each item's neighbor. As a bonus, we now use the same sorted list to
perform a binary search using the user-provided prefix as search key.

Original-patch-by: Slavica Đukić <slawica92@hotmail.com>
Helped-by: SZEDER Gábor <szeder.dev@gmail.com>
Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 years agobuilt-in add -i: implement the main loop
Johannes Schindelin [Fri, 15 Nov 2019 11:11:16 +0000 (11:11 +0000)] 
built-in add -i: implement the main loop

The reason why we did not start with the main loop to begin with is that
it is the first user of `list_and_choose()`, which uses the `list()`
function that we conveniently introduced for use by the `status`
command.

In contrast to the Perl version, in the built-in interactive `add`, we
will keep the `list()` function (which only displays items) and the
`list_and_choose()` function (which uses `list()` to display the items,
and only takes care of the "and choose" part) separate.

The `list_and_choose()` function, as implemented in
`git-add--interactive.perl` knows a few more tricks than the function we
introduce in this patch:

- There is a flag to let the user select multiple items.

- In multi-select mode, the list of items is prefixed with a marker
  indicating what items have been selected.

- Initially, for each item a unique prefix is determined (if there
  exists any within the given parameters), and shown in the list, and
  accepted as a shortcut for the selection.

These features will be implemented in the C version later.

This patch does not add any new main loop command, of course, the
built-in `git add -i` still only supports the `status` command. The
remaining commands to follow over the course of the next commits.

To accommodate for listing the commands in columns, preparing for the
commands that will be implemented over the course of the next
patches/patch series, we teach the `list()` function to do precisely
that.

Note that we only have a prompt ending in a single ">" at this stage;
later commits will add commands that display a double ">>" to indicate
that the user is in a different loop than the main one.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 years agobuilt-in add -i: color the header in the `status` command
Slavica Đukić [Wed, 13 Nov 2019 12:41:00 +0000 (12:41 +0000)] 
built-in add -i: color the header in the `status` command

For simplicity, we only implemented the `status` command without colors.
This patch starts adding color, matching what the Perl script
`git-add--interactive.perl` does.

Original-Patch-By: Daniel Ferreira <bnmvco@gmail.com>
Signed-off-by: Slavica Đukić <slawica92@hotmail.com>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 years agobuilt-in add -i: implement the `status` command
Daniel Ferreira [Wed, 13 Nov 2019 12:40:59 +0000 (12:40 +0000)] 
built-in add -i: implement the `status` command

This implements the `status` command of `git add -i`. The data
structures introduced in this commit will be extended later, as needed.

At this point, we re-implement only part of the `list_and_choose()`
function of the Perl script `git-add--interactive.perl` and call it
`list()`. It does not yet color anything, or do columns, or allow user
input.

Over the course of the next commits, we will introduce a
`list_and_choose()` function that uses `list()` to display the list of
options and let the user choose one or more of the displayed items. This
will be used to implement the main loop of the built-in `git add -i`, at
which point the new `status` command can actually be used.

Signed-off-by: Daniel Ferreira <bnmvco@gmail.com>
Signed-off-by: Slavica Đukić <slawica92@hotmail.com>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 years agodiff: export diffstat interface
Daniel Ferreira [Wed, 13 Nov 2019 12:40:58 +0000 (12:40 +0000)] 
diff: export diffstat interface

Make the diffstat interface (namely, the diffstat_t struct and
compute_diffstat) no longer be internal to diff.c and allow it to be used
by other parts of git.

This is helpful for code that may want to easily extract information
from files using the diff machinery, while flushing it differently from
how the show_* functions used by diff_flush() do it. One example is the
builtin implementation of git-add--interactive's status.

Signed-off-by: Daniel Ferreira <bnmvco@gmail.com>
Signed-off-by: Slavica Đukić <slawica92@hotmail.com>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 years agoStart to implement a built-in version of `git add --interactive`
Johannes Schindelin [Wed, 13 Nov 2019 12:40:57 +0000 (12:40 +0000)] 
Start to implement a built-in version of `git add --interactive`

Unlike previous conversions to C, where we started with a built-in
helper, we start this conversion by adding an interception in the
`run_add_interactive()` function when the new opt-in
`add.interactive.useBuiltin` config knob is turned on (or the
corresponding environment variable `GIT_TEST_ADD_I_USE_BUILTIN`), and
calling the new internal API function `run_add_i()` that is implemented
directly in libgit.a.

At this point, the built-in version of `git add -i` only states that it
cannot do anything yet. In subsequent patches/patch series, the
`run_add_i()` function will gain more and more functionality, until it
is feature complete. The whole arc of the conversion can be found in the
PRs #170-175 at https://github.com/gitgitgadget/git.

The "--helper approach" can unfortunately not be used here: on Windows
we face the very specific problem that a `system()` call in
Perl seems to close `stdin` in the parent process when the spawned
process consumes even one character from `stdin`. Which prevents us from
implementing the main loop in C and still trying to hand off to the Perl
script.

The very real downside of the approach we have to take here is that the
test suite won't pass with `GIT_TEST_ADD_I_USE_BUILTIN=true` until the
conversion is complete (the `--helper` approach would have let it pass,
even at each of the incremental conversion steps).

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 years agoGit 2.24 v2.24.0
Junio C Hamano [Mon, 4 Nov 2019 04:32:41 +0000 (13:32 +0900)] 
Git 2.24

Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 years agoMerge branch 'bc/doc-use-docbook-5'
Junio C Hamano [Mon, 4 Nov 2019 04:33:06 +0000 (13:33 +0900)] 
Merge branch 'bc/doc-use-docbook-5'

Finishing touches to the recent update to the build procedure for
the documentation.

* bc/doc-use-docbook-5:
  manpage-bold-literal.xsl: match for namespaced "d:literal" in template

4 years agoMerge branch 'ds/commit-graph-on-fetch'
Junio C Hamano [Mon, 4 Nov 2019 04:33:06 +0000 (13:33 +0900)] 
Merge branch 'ds/commit-graph-on-fetch'

Regression fix.

* ds/commit-graph-on-fetch:
  commit-graph: fix writing first commit-graph during fetch
  t5510-fetch.sh: demonstrate fetch.writeCommitGraph bug

4 years agoMerge branch 'jt/delay-fetch-if-missing'
Junio C Hamano [Mon, 4 Nov 2019 04:33:05 +0000 (13:33 +0900)] 
Merge branch 'jt/delay-fetch-if-missing'

Work-around a lazy fetch glitch.

* jt/delay-fetch-if-missing:
  fetch: delay fetch_if_missing=0 until after config

4 years agoMerge https://github.com/prati0100/git-gui
Junio C Hamano [Mon, 4 Nov 2019 04:29:38 +0000 (13:29 +0900)] 
Merge https://github.com/prati0100/git-gui

* https://github.com/prati0100/git-gui:
  git-gui: improve Japanese translation
  git-gui: add a readme
  git-gui: support for diff3 conflict style
  git-gui: use existing interface to query a path's attribute
  git-gui (Windows): use git-bash.exe if it is available
  treewide: correct several "up-to-date" to "up to date"
  Fix build with core.autocrlf=true

4 years agoMerge tag 'l10n-2.24.0-rnd2' of https://github.com/git-l10n/git-po
Junio C Hamano [Mon, 4 Nov 2019 04:25:13 +0000 (13:25 +0900)] 
Merge tag 'l10n-2.24.0-rnd2' of https://github.com/git-l10n/git-po

l10n-2.24.0-rnd2

* tag 'l10n-2.24.0-rnd2' of https://github.com/git-l10n/git-po:
  l10n: zh_CN: for git v2.24.0 l10n round 1~2
  l10n: de.po: Update German translation
  l10n: sv.po: Update Swedish translation (4695t0f0u)
  l10n: bg.po: Updated Bulgarian translation (4694)
  l10n: vi(4694t): Updated translation for v2.24.0
  l10n: es: 2.24.0 round 2
  l10n: it.po: update the Italian translation for Git 2.24.0 round #2
  l10n: fr v2.24.0 rnd2
  l10n: git.pot: v2.24.0 round 2 (1 new)
  l10n: it.po: update the Italian translation for Git 2.24.0
  l10n: fr 2.24.0 rnd 1
  l10n: git.pot: v2.24.0 round 1 (35 new, 16 removed)
  l10n: bg.po: Updated Bulgarian translation (4693)
  l10n: sv.po: Update Swedish translation (4674t0f0u)
  l10n: Update Catalan translation

4 years agol10n: zh_CN: for git v2.24.0 l10n round 1~2
Jiang Xin [Tue, 29 Oct 2019 02:50:30 +0000 (10:50 +0800)] 
l10n: zh_CN: for git v2.24.0 l10n round 1~2

Translate 36 new messages (4694t0f0u) for git 2.24.0.

Signed-off-by: Jiang Xin <worldhello.net@gmail.com>
4 years agoRelNotes/2.24.0: fix self-contradictory note
Elijah Newren [Wed, 30 Oct 2019 20:21:18 +0000 (20:21 +0000)] 
RelNotes/2.24.0: fix self-contradictory note

As per Wikipedia, "In current technical usage, for one to state that a
feature is deprecated is merely a recommendation against using it."  It
is thus contradictory to claim that something is not "officially
deprecated" and then to immediately state that we are both discouraging
its use and pointing people elsewhere.

Signed-off-by: Elijah Newren <newren@gmail.com>
Reviewed-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 years agomanpage-bold-literal.xsl: match for namespaced "d:literal" in template
Martin Ågren [Thu, 31 Oct 2019 06:22:27 +0000 (07:22 +0100)] 
manpage-bold-literal.xsl: match for namespaced "d:literal" in template

We recently regressed our rendering with Asciidoctor of "literal"
elements in our manpages, i.e, stuff we have placed within `backticks`
in order to render as monospace. In particular, we lost the bold
rendering of such literal text.

The culprit is f6461b82b9 ("Documentation: fix build with Asciidoctor 2",
2019-09-15), where we switched from DocBook 4.5 to DocBook 5 with
Asciidoctor. As part of the switch, we started using the namespaced
DocBook XSLT stylesheets rather than the non-namespaced ones. (See
f6461b82b9 for more details on why we changed to the namespaced ones.)

The bold literals are implemented as an XSLT snippet <xsl:template
match="literal">...</xsl:template>. Now that we use namespaces, this
doesn't pick up our literals like it used to.

Match for "d:literal" in addition to just "literal", after defining the
d namespace. ("d" is what
http://docbook.sourceforge.net/release/xsl-ns/current/manpages/docbook.xsl
uses.) Note that we need to keep matching without the namespace for
AsciiDoc.

This boldness was introduced by 5121a6d993 ("Documentation: option to
render literal text as bold for manpages", 2009-03-27) and made the
default in 5945717009 ("Documentation: bold literals in man",
2016-05-31).

One reason this was not caught in review is that our doc-diff tool diffs
without any boldness, i.e., it "only" compares text. As pointed out by
Peff in review of this patch, one can use `MAN_KEEP_FORMATTING=1
./doc-diff <...>`

This has been optically tested with AsciiDoc 8.6.10, Asciidoctor 1.5.5
and Asciidoctor 2.0.10. I've also verified that doc-diff produces the
empty output for all three programs, as expected, and that with the
MAN_KEEP_FORMATTING trick, AsciiDoc yields no diff, whereas with
Asciidoctor, we get bold literals, just like we want.

Signed-off-by: Martin Ågren <martin.agren@gmail.com>
Acked-by: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 years agoRelNotes/2.24.0: typofix
Elijah Newren [Wed, 30 Oct 2019 20:21:17 +0000 (20:21 +0000)] 
RelNotes/2.24.0: typofix

Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 years agol10n: de.po: Update German translation
Matthias Rüster [Wed, 23 Oct 2019 17:13:19 +0000 (19:13 +0200)] 
l10n: de.po: Update German translation

Signed-off-by: Matthias Rüster <matthias.ruester@gmail.com>
Reviewed-by: Ralf Thielow <ralf.thielow@gmail.com>
Reviewed-by: Phillip Szelat <phillip.szelat@gmail.com>
4 years agol10n: sv.po: Update Swedish translation (4695t0f0u)
Peter Krefting [Wed, 30 Oct 2019 22:22:13 +0000 (23:22 +0100)] 
l10n: sv.po: Update Swedish translation (4695t0f0u)

Signed-off-by: Peter Krefting <peter@softwolves.pp.se>
4 years agoGit 2.24-rc2 v2.24.0-rc2
Junio C Hamano [Wed, 30 Oct 2019 06:12:53 +0000 (15:12 +0900)] 
Git 2.24-rc2

Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 years agoMerge branch 'wb/fsmonitor-bitmap-fix'
Junio C Hamano [Wed, 30 Oct 2019 06:13:13 +0000 (15:13 +0900)] 
Merge branch 'wb/fsmonitor-bitmap-fix'

Comment update.

* wb/fsmonitor-bitmap-fix:
  t7519-status-fsmonitor: improve comments

4 years agoMerge branch 'rl/gitweb-blame-prev-fix'
Junio C Hamano [Wed, 30 Oct 2019 06:13:13 +0000 (15:13 +0900)] 
Merge branch 'rl/gitweb-blame-prev-fix'

Fix a rather old bug in gitweb---incremental blame output in
javascript actions mode never worked.

* rl/gitweb-blame-prev-fix:
  gitweb: correctly store previous rev in javascript-actions mode

4 years agoMerge branch 'js/mingw-needs-hiding-fix'
Junio C Hamano [Wed, 30 Oct 2019 06:13:13 +0000 (15:13 +0900)] 
Merge branch 'js/mingw-needs-hiding-fix'

Fix for a (rather old) buffer-overrun bug.

* js/mingw-needs-hiding-fix:
  mingw: avoid a buffer overrun in `needs_hiding()`

4 years agoMerge branch 'master' of github.com:vnwildman/git
Jiang Xin [Wed, 30 Oct 2019 06:07:58 +0000 (14:07 +0800)] 
Merge branch 'master' of github.com:vnwildman/git

* 'master' of github.com:vnwildman/git:
  l10n: vi(4694t): Updated translation for v2.24.0

4 years agoMerge branch 'next' of github.com:ChrisADR/git-po
Jiang Xin [Wed, 30 Oct 2019 06:02:22 +0000 (14:02 +0800)] 
Merge branch 'next' of github.com:ChrisADR/git-po

* 'next' of github.com:ChrisADR/git-po:
  l10n: es: 2.24.0 round 2

4 years agot7519-status-fsmonitor: improve comments
William Baker [Wed, 16 Oct 2019 19:35:47 +0000 (19:35 +0000)] 
t7519-status-fsmonitor: improve comments

The comments for the staging/unstaging test did not accurately
describe the scenario being tested.  It is not essential that
the test files being staged/unstaged appear at the end of the
index.  All that is required is that the test files are not
flagged with CE_FSMONITOR_VALID and have a position in the
index greater than the number of entries in the index after
unstaging.

The comment for this test has been updated to be more
accurate with respect to the scenario that's being tested.

Signed-off-by: William Baker <William.Baker@microsoft.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 years agol10n: bg.po: Updated Bulgarian translation (4694)
Alexander Shopov [Tue, 29 Oct 2019 10:37:45 +0000 (11:37 +0100)] 
l10n: bg.po: Updated Bulgarian translation (4694)

Signed-off-by: Alexander Shopov <ash@kambanaria.org>
4 years agol10n: vi(4694t): Updated translation for v2.24.0
Tran Ngoc Quan [Tue, 29 Oct 2019 07:38:42 +0000 (14:38 +0700)] 
l10n: vi(4694t): Updated translation for v2.24.0

Signed-off-by: Tran Ngoc Quan <vnwildman@gmail.com>
4 years agol10n: es: 2.24.0 round 2
Christopher Diaz Riveros [Sun, 15 Sep 2019 21:56:56 +0000 (23:56 +0200)] 
l10n: es: 2.24.0 round 2

Signed-off-by: Christopher Diaz Riveros <christopher.diaz.riv@gmail.com>
4 years agoMerge branch 'l10n/it/update-italian-translation'
Jiang Xin [Mon, 28 Oct 2019 23:27:51 +0000 (07:27 +0800)] 
Merge branch 'l10n/it/update-italian-translation'

* 'update-italian-translation' of github.com:AlessandroMenti/git-po:
  l10n: it.po: update the Italian translation for Git 2.24.0 round #2

4 years agol10n: it.po: update the Italian translation for Git 2.24.0 round #2
Alessandro Menti [Mon, 28 Oct 2019 19:44:05 +0000 (20:44 +0100)] 
l10n: it.po: update the Italian translation for Git 2.24.0 round #2

Signed-off-by: Alessandro Menti <alessandro.menti@alessandromenti.it>
4 years agol10n: fr v2.24.0 rnd2
Jean-Noël Avila [Mon, 28 Oct 2019 19:36:01 +0000 (20:36 +0100)] 
l10n: fr v2.24.0 rnd2

Signed-off-by: Jean-Noël Avila <jn.avila@free.fr>
4 years agol10n: git.pot: v2.24.0 round 2 (1 new)
Jiang Xin [Mon, 28 Oct 2019 05:16:31 +0000 (13:16 +0800)] 
l10n: git.pot: v2.24.0 round 2 (1 new)

Generate po/git.pot from v2.24.0-rc1 for git v2.24.0 l10n round 2.

Signed-off-by: Jiang Xin <worldhello.net@gmail.com>
4 years agoMerge tag 'v2.24.0-rc1' of github.com:git/git into master
Jiang Xin [Mon, 28 Oct 2019 05:18:55 +0000 (13:18 +0800)] 
Merge tag 'v2.24.0-rc1' of github.com:git/git into master

Git 2.24-rc1

* tag 'v2.24.0-rc1' of github.com:git/git:
  Git 2.24-rc1
  repo-settings: read an int for index.version
  ci: fix GCC install in the Travis CI GCC OSX job
  Eleventh batch
  ci(osx): use new location of the `perforce` cask
  t7419: change test_must_fail to ! for grep
  t4014: make output-directory tests self-contained
  ci(visual-studio): actually run the tests in parallel
  ci(visual-studio): use strict compile flags, and optimization
  userdiff: fix some corner cases in dts regex
  test-progress: fix test failures on big-endian systems
  completion: clarify installation instruction for zsh
  grep: avoid leak of chartables in PCRE2
  grep: make PCRE2 aware of custom allocator
  grep: make PCRE1 aware of custom allocator
  remote-curl: pass on atomic capability to remote side
  diff-highlight: fix a whitespace nit
  fsmonitor: don't fill bitmap with entries to be removed

4 years agomingw: avoid a buffer overrun in `needs_hiding()`
Johannes Schindelin [Fri, 25 Oct 2019 14:13:36 +0000 (14:13 +0000)] 
mingw: avoid a buffer overrun in `needs_hiding()`

When this function is passed a path with a trailing slash, it runs right
over the end of that path.

Let's fix this.

Co-authored-by: Alexandr Miloslavskiy <alexandr.miloslavskiy@syntevo.com>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 years agogitweb: correctly store previous rev in javascript-actions mode
Robert Luberda [Sun, 27 Oct 2019 09:14:26 +0000 (10:14 +0100)] 
gitweb: correctly store previous rev in javascript-actions mode

Without this change, the setting

 $feature{'javascript-actions'}{'default'} = [1];

in gitweb.conf breaks gitweb's blame page: clicking on line numbers
displayed in the second column on the page has no effect.

For comparison, with javascript-actions disabled, clicking on line
numbers loads the previous version of the line.

Addresses https://bugs.debian.org/741883.

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Robert Luberda <robert@debian.org>
Acked-by: Jakub Narębski <jnareb@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 years agocommit-graph: fix writing first commit-graph during fetch
Derrick Stolee [Thu, 24 Oct 2019 13:40:42 +0000 (13:40 +0000)] 
commit-graph: fix writing first commit-graph during fetch

The previous commit includes a failing test for an issue around
fetch.writeCommitGraph and fetching in a repo with a submodule. Here, we
fix that bug and set the test to "test_expect_success".

The problem arises with this set of commands when the remote repo at
<url> has a submodule. Note that --recurse-submodules is not needed to
demonstrate the bug.

$ git clone <url> test
$ cd test
$ git -c fetch.writeCommitGraph=true fetch origin
Computing commit graph generation numbers: 100% (12/12), done.
BUG: commit-graph.c:886: missing parent <hash1> for commit <hash2>
Aborted (core dumped)

As an initial fix, I converted the code in builtin/fetch.c that calls
write_commit_graph_reachable() to instead launch a "git commit-graph
write --reachable --split" process. That code worked, but is not how we
want the feature to work long-term.

That test did demonstrate that the issue must be something to do with
internal state of the 'git fetch' process.

The write_commit_graph() method in commit-graph.c ensures the commits we
plan to write are "closed under reachability" using close_reachable().
This method walks from the input commits, and uses the UNINTERESTING
flag to mark which commits have already been visited. This allows the
walk to take O(N) time, where N is the number of commits, instead of
O(P) time, where P is the number of paths. (The number of paths can be
exponential in the number of commits.)

However, the UNINTERESTING flag is used in lots of places in the
codebase. This flag usually means some barrier to stop a commit walk,
such as in revision-walking to compare histories. It is not often
cleared after the walk completes because the starting points of those
walks do not have the UNINTERESTING flag, and clear_commit_marks() would
stop immediately.

This is happening during a 'git fetch' call with a remote. The fetch
negotiation is comparing the remote refs with the local refs and marking
some commits as UNINTERESTING.

I tested running clear_commit_marks_many() to clear the UNINTERESTING
flag inside close_reachable(), but the tips did not have the flag, so
that did nothing.

It turns out that the calculate_changed_submodule_paths() method is at
fault. Thanks, Peff, for pointing out this detail! More specifically,
for each submodule, the collect_changed_submodules() runs a revision
walk to essentially do file-history on the list of submodules. That
revision walk marks commits UNININTERESTING if they are simplified away
by not changing the submodule.

Instead, I finally arrived on the conclusion that I should use a flag
that is not used in any other part of the code. In commit-reach.c, a
number of flags were defined for commit walk algorithms. The REACHABLE
flag seemed like it made the most sense, and it seems it was not
actually used in the file. The REACHABLE flag was used in early versions
of commit-reach.c, but was removed by 4fbcca4 (commit-reach: make
can_all_from_reach... linear, 2018-07-20).

Add the REACHABLE flag to commit-graph.c and use it instead of
UNINTERESTING in close_reachable(). This fixes the bug in manual
testing.

Reported-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Helped-by: Jeff King <peff@peff.net>
Helped-by: Szeder Gábor <szeder.dev@gmail.com>
Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 years agot5510-fetch.sh: demonstrate fetch.writeCommitGraph bug
Derrick Stolee [Thu, 24 Oct 2019 13:40:41 +0000 (13:40 +0000)] 
t5510-fetch.sh: demonstrate fetch.writeCommitGraph bug

While dogfooding, Johannes found a bug in the fetch.writeCommitGraph
config behavior. His example initially happened during a clone with
--recurse-submodules, we found that this happens with the first fetch
after cloning a repository that contains a submodule:

$ git clone <url> test
$ cd test
$ git -c fetch.writeCommitGraph=true fetch origin
Computing commit graph generation numbers: 100% (12/12), done.
BUG: commit-graph.c:886: missing parent <hash1> for commit <hash2>
Aborted (core dumped)

In the repo I had cloned, there were really 60 commits to scan, but
only 12 were in the list to write when calling
compute_generation_numbers(). A commit in the list expects to see a
parent, but that parent is not in the list.

A follow-up will fix the bug, but first we create a test that
demonstrates the problem. This test must be careful about an existing
commit-graph file, since GIT_TEST_COMMIT_GRAPH=1 will cause the repo we
are cloning to already have one. This then prevents the incremtnal
commit-graph write during the first 'git fetch'.

Helped-by: Jeff King <peff@peff.net>
Helped-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Helped-by: Szeder Gábor <szeder.dev@gmail.com>
Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 years agoGit 2.24-rc1 v2.24.0-rc1
Junio C Hamano [Thu, 24 Oct 2019 04:33:49 +0000 (13:33 +0900)] 
Git 2.24-rc1

Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 years agoMerge branch 'sg/ci-osx-gcc8-fix'
Junio C Hamano [Thu, 24 Oct 2019 04:34:03 +0000 (13:34 +0900)] 
Merge branch 'sg/ci-osx-gcc8-fix'

CI build fix.

* sg/ci-osx-gcc8-fix:
  ci: fix GCC install in the Travis CI GCC OSX job

4 years agoMerge branch 'ds/feature-macros'
Junio C Hamano [Thu, 24 Oct 2019 04:34:02 +0000 (13:34 +0900)] 
Merge branch 'ds/feature-macros'

The codepath that reads the index.version configuration was broken
with a recent update, which has been corrected.

* ds/feature-macros:
  repo-settings: read an int for index.version

4 years agoMerge branch 'js/azure-ci-osx-fix'
Junio C Hamano [Thu, 24 Oct 2019 04:34:02 +0000 (13:34 +0900)] 
Merge branch 'js/azure-ci-osx-fix'

Update installation procedure for Perforce on MacOS in the CI jobs
running on Azure pipelines, which was failing.

* js/azure-ci-osx-fix:
  ci(osx): use new location of the `perforce` cask

4 years agoMerge branch 'bw/format-patch-o-create-leading-dirs'
Junio C Hamano [Thu, 24 Oct 2019 04:34:02 +0000 (13:34 +0900)] 
Merge branch 'bw/format-patch-o-create-leading-dirs'

Test update.

* bw/format-patch-o-create-leading-dirs:
  t4014: make output-directory tests self-contained

4 years agoMerge branch 'dl/submodule-set-branch'
Junio C Hamano [Thu, 24 Oct 2019 04:34:02 +0000 (13:34 +0900)] 
Merge branch 'dl/submodule-set-branch'

Test update.

* dl/submodule-set-branch:
  t7419: change test_must_fail to ! for grep

4 years agofetch: delay fetch_if_missing=0 until after config
Jonathan Tan [Wed, 23 Oct 2019 23:34:03 +0000 (16:34 -0700)] 
fetch: delay fetch_if_missing=0 until after config

Suppose, from a repository that has ".gitmodules", we clone with
--filter=blob:none:

  git clone --filter=blob:none --no-checkout \
    https://kernel.googlesource.com/pub/scm/git/git

Then we fetch:

  git -C git fetch

This will cause a "unable to load config blob object", because the
fetch_config_from_gitmodules() invocation in cmd_fetch() will attempt to
load ".gitmodules" (which Git knows to exist because the client has the
tree of HEAD) while fetch_if_missing is set to 0.

fetch_if_missing is set to 0 too early - ".gitmodules" here should be
lazily fetched.  Git must set fetch_if_missing to 0 before the fetch
because as part of the fetch, packfile negotiation happens (and we do
not want to fetch any missing objects when checking existence of
objects), but we do not need to set it so early. Move the setting of
fetch_if_missing to the earliest possible point in cmd_fetch(), right
before any fetching happens.

Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 years agorepo-settings: read an int for index.version
Derrick Stolee [Wed, 23 Oct 2019 20:38:57 +0000 (20:38 +0000)] 
repo-settings: read an int for index.version

Several config options were combined into a repo_settings struct in
ds/feature-macros, including a move of the "index.version" config
setting in 7211b9e (repo-settings: consolidate some config settings,
2019-08-13).

Unfortunately, that file looked like a lot of boilerplate and what is
clearly a factor of copy-paste overload, the config setting is parsed
with repo_config_ge_bool() instead of repo_config_get_int(). This means
that a setting "index.version=4" would not register correctly and would
revert to the default version of 3.

I caught this while incorporating v2.24.0-rc0 into the VFS for Git
codebase, where we really care that the index is in version 4.

This was not caught by the codebase because the version checks placed
in t1600-index.sh did not test the "basic" scenario enough. Here, we
modify the test to include these normal settings to not be overridden by
features.manyFiles or GIT_INDEX_VERSION. While the "default" version is
3, this is demoted to version 2 in do_write_index() when not necessary.

Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 years agoci: fix GCC install in the Travis CI GCC OSX job
SZEDER Gábor [Thu, 24 Oct 2019 00:20:40 +0000 (02:20 +0200)] 
ci: fix GCC install in the Travis CI GCC OSX job

A few days ago Travis CI updated their existing OSX images, including
the Homebrew database in the xcode10.1 OSX image that we use.  Since
then installing dependencies in the 'osx-gcc' job fails when it tries
to link gcc@8:

  + brew link gcc@8
  Error: No such keg: /usr/local/Cellar/gcc@8

GCC8 is still installed but not linked to '/usr/local' in the updated
image, as it was before this update, but now we have to link it by
running 'brew link gcc'.  So let's do that then, and fall back to
linking gcc@8 if it doesn't, just to be sure.

Our builds on Azure Pipelines are unaffected by this issue.  The OSX
image over there doesn't contain the gcc@8 package, so we have to
'brew install' it, which already takes care of linking it to
'/usr/local'.  After that the 'brew link gcc' command added by this
patch fails, but the ||-chained fallback 'brew link gcc@8' command
succeeds with an "already linked" warning.

Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 years agoEleventh batch
Junio C Hamano [Wed, 23 Oct 2019 05:42:27 +0000 (14:42 +0900)] 
Eleventh batch

The tenth was at -rc0 ;-)

Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 years agoMerge branch 'cb/pcre2-chartables-leakfix'
Junio C Hamano [Wed, 23 Oct 2019 05:43:11 +0000 (14:43 +0900)] 
Merge branch 'cb/pcre2-chartables-leakfix'

Leakfix.

* cb/pcre2-chartables-leakfix:
  grep: avoid leak of chartables in PCRE2
  grep: make PCRE2 aware of custom allocator
  grep: make PCRE1 aware of custom allocator

4 years agoMerge branch 'bc/smart-http-atomic-push'
Junio C Hamano [Wed, 23 Oct 2019 05:43:11 +0000 (14:43 +0900)] 
Merge branch 'bc/smart-http-atomic-push'

The atomic push over smart HTTP transport did not work, which has
been corrected.

* bc/smart-http-atomic-push:
  remote-curl: pass on atomic capability to remote side

4 years agoMerge branch 'wb/fsmonitor-bitmap-fix'
Junio C Hamano [Wed, 23 Oct 2019 05:43:10 +0000 (14:43 +0900)] 
Merge branch 'wb/fsmonitor-bitmap-fix'

A segfault fix.

* wb/fsmonitor-bitmap-fix:
  fsmonitor: don't fill bitmap with entries to be removed

4 years agoMerge branch 'sb/userdiff-dts'
Junio C Hamano [Wed, 23 Oct 2019 05:43:10 +0000 (14:43 +0900)] 
Merge branch 'sb/userdiff-dts'

Tweak userdiff patterns for dts.

* sb/userdiff-dts:
  userdiff: fix some corner cases in dts regex

4 years agoMerge branch 'sg/progress-fix'
Junio C Hamano [Wed, 23 Oct 2019 05:43:09 +0000 (14:43 +0900)] 
Merge branch 'sg/progress-fix'

Byte-order fix the recent update to progress display code.

* sg/progress-fix:
  test-progress: fix test failures on big-endian systems