Commit Graph

7534 Commits

Author SHA1 Message Date
Johannes Schindelin
0a8bdb7185 push: do not pretend to return int from die_push_simple()
This function is marked as `NORETURN`, and it indeed does not want to
return anything. So let's not declare it with the return type `int`.
This fixes the following warning when building with MSVC:

	C4646: function declared with 'noreturn' has non-void return type

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2019-04-10 14:11:26 +02:00
Johannes Schindelin
dc2ae9a382 Merge pull request #2119 from dscho/update-stash-to-current
Update the built-in `git stash` to the latest version
2019-03-11 19:58:29 +01:00
Johannes Schindelin
66af0b6eb8 built-in stash: handle :(glob) pathspecs again
When passing a list of pathspecs to, say, `git add`, we need to be
careful to use the original form, not the parsed form of the pathspecs.

This makes a difference e.g. when calling

	git stash -- ':(glob)**/*.txt'

where the original form includes the `:(glob)` prefix while the parsed
form does not.

However, in the built-in `git stash`, we passed the parsed (i.e.
incorrect) form, and `git add` would fail with the error message:

	fatal: pathspec '**/*.txt' did not match any files

at the stage where `git stash` drops the changes from the worktree, even
if `refs/stash` has been actually updated successfully.

This fixes https://github.com/git-for-windows/git/issues/2037

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2019-03-11 16:55:48 +01:00
Johannes Schindelin
a373469aa6 tests: add a special setup where stash.useBuiltin is off
Add a GIT_TEST_STASH_USE_BUILTIN=false test mode which is equivalent
to running with stash.useBuiltin=false. This is needed to spot that
we're not introducing any regressions in the legacy stash version
while we're carrying both it and the new built-in version.

This imitates the equivalent treatment for the built-in rebase in
62c23938fa (tests: add a special setup where rebase.useBuiltin is off,
2018-11-14).

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Thomas Gummerer <t.gummerer@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-03-11 16:55:48 +01:00
Johannes Schindelin
5de54543b0 stash: optionally use the scripted version again
We recently converted the `git stash` command from Unix shell scripts
to builtins.

Let's end users a way out when they discover a bug in the
builtin command: `stash.useBuiltin`.

As the file name `git-stash` is already in use, let's rename the
scripted backend to `git-legacy-stash`.

To make the test suite pass with `stash.useBuiltin=false`, this commit
also backports rudimentary support for `-q` (but only *just* enough
to appease the test suite), and adds a super-ugly hack to force exit
code 129 for `git stash -h`.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Thomas Gummerer <t.gummerer@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-03-11 16:55:48 +01:00
Paul-Sebastian Ungureanu
fade169bfa stash: convert stash--helper.c into stash.c
The old shell script `git-stash.sh`  was removed and replaced
entirely by `builtin/stash.c`. In order to do that, `create` and
`push` were adapted to work without `stash.sh`. For example, before
this commit, `git stash create` called `git stash--helper create
--message "$*"`. If it called `git stash--helper create "$@"`, then
some of these changes wouldn't have been necessary.

This commit also removes the word `helper` since now stash is
called directly and not by a shell script.

Signed-off-by: Paul-Sebastian Ungureanu <ungureanupaulsebastian@gmail.com>
Signed-off-by: Thomas Gummerer <t.gummerer@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-03-11 16:55:48 +01:00
Paul-Sebastian Ungureanu
b561b4aabd stash: replace all write-tree child processes with API calls
Avoid spawning write-tree child processes by replacing the calls with
in-core API calls.

Signed-off-by: Paul-Sebastian Ungureanu <ungureanupaulsebastian@gmail.com>
Signed-off-by: Thomas Gummerer <t.gummerer@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-03-11 16:55:48 +01:00
Paul-Sebastian Ungureanu
714dd7221a stash: optimize get_untracked_files() and check_changes()
This commits introduces a optimization by avoiding calling the
same functions again. For example, `git stash push -u`
would call at some points the following functions:

 * `check_changes()` (inside `do_push_stash()`)
 * `do_create_stash()`, which calls: `check_changes()` and
`get_untracked_files()`

Note that `check_changes()` also calls `get_untracked_files()`.
So, `check_changes()` is called 2 times and `get_untracked_files()`
3 times.

The old function `check_changes()` now consists of two functions:
`get_untracked_files()` and `check_changes_tracked_files()`.

These are the call chains for `push` and `create`:

 * `push_stash()` -> `do_push_stash()` -> `do_create_stash()`

 * `create_stash()` -> `do_create_stash()`

To prevent calling the same functions over and over again,
`check_changes()` inside `do_create_stash()` is now placed
in the caller functions (`create_stash()` and `do_push_stash()`).
This way `check_changes()` and `get_untracked files()` are called
only one time.

Signed-off-by: Paul-Sebastian Ungureanu <ungureanupaulsebastian@gmail.com>
Signed-off-by: Thomas Gummerer <t.gummerer@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-03-11 16:55:48 +01:00
Paul-Sebastian Ungureanu
b8fad7d220 stash: convert save to builtin
Add stash save to the helper and delete functions which are no
longer needed (`show_help()`, `save_stash()`, `push_stash()`,
`create_stash()`, `clear_stash()`, `untracked_files()` and
`no_changes()`).

Signed-off-by: Paul-Sebastian Ungureanu <ungureanupaulsebastian@gmail.com>
Signed-off-by: Thomas Gummerer <t.gummerer@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-03-11 16:55:48 +01:00
Paul-Sebastian Ungureanu
fa8ae450e3 stash: make push -q quiet
There is a change in behaviour with this commit. When there was
no initial commit, the shell version of stash would still display
a message. This commit makes `push` to not display any message if
`--quiet` or `-q` is specified. Add tests for `--quiet`.

Signed-off-by: Paul-Sebastian Ungureanu <ungureanupaulsebastian@gmail.com>
Signed-off-by: Thomas Gummerer <t.gummerer@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-03-11 16:55:47 +01:00
Paul-Sebastian Ungureanu
ef1b5f497e stash: convert push to builtin
Add stash push to the helper.

Signed-off-by: Paul-Sebastian Ungureanu <ungureanupaulsebastian@gmail.com>
Signed-off-by: Thomas Gummerer <t.gummerer@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-03-11 16:55:47 +01:00
Paul-Sebastian Ungureanu
cad14d649e stash: convert create to builtin
Add stash create to the helper.

Signed-off-by: Paul-Sebastian Ungureanu <ungureanupaulsebastian@gmail.com>
Helped-by: Matthew Kraai <mkraai@its.jnj.com>
Signed-off-by: Thomas Gummerer <t.gummerer@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-03-11 16:55:47 +01:00
Johannes Schindelin
9b6e423d50 fixup: stash: convert store to builtin
This change was introduced upstream in an evil merge.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2019-03-11 16:55:45 +01:00
Paul-Sebastian Ungureanu
06b5b8fa31 stash: convert store to builtin
Add stash store to the helper and delete the store_stash function
from the shell script.

Signed-off-by: Paul-Sebastian Ungureanu <ungureanupaulsebastian@gmail.com>
Signed-off-by: Thomas Gummerer <t.gummerer@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-03-11 16:55:40 +01:00
Paul-Sebastian Ungureanu
bef7e56075 stash: convert show to builtin
Add stash show to the helper and delete the show_stash, have_stash,
assert_stash_like, is_stash_like and parse_flags_and_rev functions
from the shell script now that they are no longer needed.

In shell version, although `git stash show` accepts `--index` and
`--quiet` options, it ignores them. In C, both options are passed
further to `git diff`.

Signed-off-by: Paul-Sebastian Ungureanu <ungureanupaulsebastian@gmail.com>
Signed-off-by: Thomas Gummerer <t.gummerer@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-03-11 16:55:40 +01:00
Paul-Sebastian Ungureanu
1e3b9c2135 stash: convert list to builtin
Add stash list to the helper and delete the list_stash function
from the shell script.

Signed-off-by: Paul-Sebastian Ungureanu <ungureanupaulsebastian@gmail.com>
Signed-off-by: Thomas Gummerer <t.gummerer@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-03-11 16:55:39 +01:00
Joel Teichroeb
c85d792c29 stash: convert pop to builtin
Add stash pop to the helper and delete the pop_stash, drop_stash,
assert_stash_ref functions from the shell script now that they
are no longer needed.

Signed-off-by: Joel Teichroeb <joel@teichroeb.net>
Signed-off-by: Paul-Sebastian Ungureanu <ungureanupaulsebastian@gmail.com>
Signed-off-by: Thomas Gummerer <t.gummerer@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-03-11 16:55:39 +01:00
Joel Teichroeb
6fe783f5a6 stash: convert branch to builtin
Add stash branch to the helper and delete the apply_to_branch
function from the shell script.

Checkout does not currently provide a function for checking out
a branch as cmd_checkout does a large amount of sanity checks
first that we require here.

Signed-off-by: Joel Teichroeb <joel@teichroeb.net>
Signed-off-by: Paul-Sebastian Ungureanu <ungureanupaulsebastian@gmail.com>
Signed-off-by: Thomas Gummerer <t.gummerer@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-03-11 16:55:39 +01:00
Joel Teichroeb
4d733c4f1d stash: convert drop and clear to builtin
Add the drop and clear commands to the builtin helper. These two
are each simple, but are being added together as they are quite
related.

We have to unfortunately keep the drop and clear functions in the
shell script as functions are called with parameters internally
that are not valid when the commands are called externally. Once
pop is converted they can both be removed.

Signed-off-by: Joel Teichroeb <joel@teichroeb.net>
Signed-off-by: Paul-Sebastian Ungureanu <ungureanupaulsebastian@gmail.com>
Signed-off-by: Thomas Gummerer <t.gummerer@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-03-11 16:55:39 +01:00
Johannes Schindelin
c58e38df53 fixup: stash: convert apply to builtin
This change was introduced upstream in an evil merge.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2019-03-11 16:55:37 +01:00
Johannes Schindelin
73f47ba2a0 fixup: stash: convert apply to builtin
This change was introduced upstream in an evil merge.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2019-03-11 16:55:14 +01:00
Joel Teichroeb
4f6218c91b stash: convert apply to builtin
Add a builtin helper for performing stash commands. Converting
all at once proved hard to review, so starting with just apply
lets conversion get started without the other commands being
finished.

The helper is being implemented as a drop in replacement for
stash so that when it is complete it can simply be renamed and
the shell script deleted.

Delete the contents of the apply_stash shell function and replace
it with a call to stash--helper apply until pop is also
converted.

Signed-off-by: Joel Teichroeb <joel@teichroeb.net>
Signed-off-by: Paul-Sebastian Ungureanu <ungureanupaulsebastian@gmail.com>
Signed-off-by: Thomas Gummerer <t.gummerer@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-03-11 16:37:00 +01:00
Johannes Schindelin
f0adfd761f fixup! stash: convert apply to builtin
In preparation for a newer patch series.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2019-03-11 16:36:18 +01:00
Johannes Schindelin
2b8b36b1e0 fixup! stash: convert drop and clear to builtin
In preparation for a newer patch series.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2019-03-11 16:36:17 +01:00
Johannes Schindelin
35eac1e64d fixup! stash: convert branch to builtin
In preparation for a newer patch series.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2019-03-11 16:36:17 +01:00
Johannes Schindelin
566be3a203 fixup! stash: convert pop to builtin
In preparation for a newer patch series.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2019-03-11 16:36:17 +01:00
Johannes Schindelin
fd928add8d fixup! stash: convert list to builtin
In preparation for a newer patch series.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2019-03-11 16:36:16 +01:00
Johannes Schindelin
6f1ce35dc4 fixup! stash: convert show to builtin
In preparation for a newer patch series.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2019-03-11 16:36:16 +01:00
Johannes Schindelin
2b45b40686 fixup! stash: convert store to builtin
In preparation for a newer patch series.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2019-03-11 16:36:16 +01:00
Johannes Schindelin
c341b4ea07 fixup! stash: convert create to builtin
In preparation for a newer patch series.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2019-03-11 16:36:15 +01:00
Johannes Schindelin
ca9031fea0 fixup! stash: convert push to builtin
In preparation for a newer patch series.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2019-03-11 16:36:15 +01:00
Johannes Schindelin
666ae6eea8 fixup! stash: make push -q quiet
In preparation for a newer patch series.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2019-03-11 16:36:15 +01:00
Johannes Schindelin
de276357c9 fixup! stash: convert save to builtin
In preparation for a newer patch series.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2019-03-11 16:36:14 +01:00
Johannes Schindelin
2b4813df50 fixup! stash: optimize get_untracked_files() and check_changes()
In preparation for a newer patch series.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2019-03-11 16:36:14 +01:00
Johannes Schindelin
7f224087fe fixup! stash: replace all write-tree child processes with API calls
In preparation for a newer patch series.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2019-03-11 16:36:14 +01:00
Johannes Schindelin
19ba7d4a3b fixup! stash: convert stash--helper.c into stash.c
In preparation for a newer patch series.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2019-03-11 16:36:13 +01:00
Johannes Schindelin
1a179124f1 fixup! stash: optionally use the scripted version again
In preparation for a newer patch series.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2019-03-11 16:36:13 +01:00
Johannes Schindelin
1acb791d83 fixup! tests: add a special setup where stash.useBuiltin is off
In preparation for a newer patch series.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2019-03-11 16:36:12 +01:00
Johannes Schindelin
b95677fed3 fixup! stash: fix segmentation fault when files were added with intent
In preparation for a newer patch series.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2019-03-11 16:36:12 +01:00
Johannes Schindelin
c6f8916538 fixup! stash: discard in-process cache after spawning index-changing processes
In preparation for a newer patch series.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2019-03-11 16:36:11 +01:00
Johannes Schindelin
41fef97f02 fixup! stash: avoid unnecessary reset_tree() call
In preparation for a newer patch series.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2019-03-11 16:36:11 +01:00
Johannes Schindelin
1a02835a1e Merge pull request #2111 from gitgitgadget/jk/no-sigpipe-during-network-transport
Fix t5570 flakiness on macOS
2019-03-07 16:34:37 +01:00
Johannes Schindelin
1c5bf602cb built-in rebase: set ORIG_HEAD just once, before the rebase
Technically, the scripted version set ORIG_HEAD only in two spots (which
really could have been one, because it called `git checkout $onto^0` to
start the rebase and also if it could take a shortcut, and in both cases
it called `git update-ref $orig_head`).

Practically, it *implicitly* reset ORIG_HEAD whenever `git reset --hard`
was called.

However, what we really want is that it is set exactly once, at the
beginning of the rebase.

So let's do that.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2019-03-07 10:23:57 +01:00
Johannes Schindelin
f13cff1f64 built-in rebase: use the correct reflog when switching branches
By mistake, we used the reflog intended for ORIG_HEAD.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2019-03-07 10:22:59 +01:00
Johannes Schindelin
6264310893 built-in rebase: no need to check out onto twice
In the case that the rebase boils down to a fast-forward, the built-in
rebase reset the working tree twice: once to start the rebase at `onto`,
then realizing that the original (pre-rebase) HEAD was an ancestor and
we basically already fast-forwarded to the post-rebase HEAD,
`reset_head()` was called to update the original ref and to point HEAD
back to it.

That second `reset_head()` call does not need to touch the working tree,
though, as it does not change the actual tip commit (and therefore the
working tree should stay unchanged anyway): only the ref needs to be
updated (because the rebase detached the HEAD, and we want to go back to
the branch on which the rebase was started).

But that second `reset_head()` was called without the flag to leave the
working tree alone (the reason: when that call was introduced, that flag
was not yet even thought of). Let's avoid that unnecessary work by
passing that flag.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2019-03-07 10:22:59 +01:00
Jeff King
143588949c fetch: ignore SIGPIPE during network operation
The default SIGPIPE behavior can be useful for a command that generates
a lot of output: if the receiver of our output goes away, we'll be
notified asynchronously to stop generating it (typically by killing the
program).

But for a command like fetch, which is primarily concerned with
receiving data and writing it to disk, an unexpected SIGPIPE can be
awkward. We're already checking the return value of all of our write()
calls, and dying due to the signal takes away our chance to gracefully
handle the error.

On Linux, we wouldn't generally see SIGPIPE at all during fetch. If the
other side of the network connection hangs up, we'll see ECONNRESET. But
on OS X, we get a SIGPIPE, and the process is killed. This causes t5570
to racily fail, as we sometimes die by signal (instead of the expected
die() call) when the server side hangs up.

Let's ignore SIGPIPE during the network portion of the fetch, which will
cause our write() to return EPIPE, giving us consistent behavior across
platforms.

This fixes the test flakiness, but note that it stops short of fixing
the larger problem. The server side hit a fatal error, sent us an "ERR"
packet, and then hung up. We notice the failure because we're trying to
write to a closed socket. But by dying immediately, we never actually
read the ERR packet and report its content to the user. This is a (racy)
problem on all platforms. So this patch lays the groundwork from which
that problem might be fixed consistently, but it doesn't actually fix
it.

Note the placement of the SIGPIPE handling. The absolute minimal change
would be to ignore SIGPIPE only when we're writing. But twiddling the
signal handler for each write call is inefficient and maintenance
burden. On the opposite end of the spectrum, we could simply declare
that fetch does not need SIGPIPE handling, since it doesn't generate a
lot of output, and we could just ignore it at the start of cmd_fetch().

This patch takes a middle ground. It ignores SIGPIPE during the network
operation (which is admittedly most of the program, since the actual
network operations are all done under the hood by the transport code).
So it's still pretty coarse.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-03-05 15:02:18 +09:00
Johannes Schindelin
2481c4cbe9 Merge pull request #2091 from dscho/symlink-attr-extra
Touch up symlink .gitattributes support
2019-02-26 17:13:28 +01:00
Johannes Schindelin
ec3a6e598e Merge pull request #2093 from dscho/release-gc-repack
Drop duplicate patch
2019-02-25 21:09:32 +01:00
Johannes Schindelin
7da09845f1 fixup! gc/repack: release packs when needed
This drops the patch that made it already upstream (and Git for Windows
added the line *another* time)...

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2019-02-25 08:14:54 +01:00
Johannes Schindelin
65225ba2dd Introduce helper to create symlinks that knows about index_state
On Windows, symbolic links actually have a type depending on the target:
it can be a file or a directory.

In certain circumstances, this poses problems, e.g. when a symbolic link
is supposed to point into a submodule that is not checked out, so there
is no way for Git to auto-detect the type.

To help with that, we will add support over the course of the next
commits to specify that symlink type via the Git attributes. This
requires an index_state, though, something that Git for Windows'
`symlink()` replacement cannot know about because the function signature
is defined by the POSIX standard and not ours to change.

So let's introduce a helper function to create symbolic links that
*does* know about the index_state.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2019-02-24 22:03:28 +01:00