Commit Graph

72282 Commits

Author SHA1 Message Date
Johannes Schindelin
df924c8ea7 rebase -i: rearrange fixup/squash lines using the rebase--helper
This operation has quadratic complexity, which is especially painful
on Windows, where shell scripts are *already* slow (mainly due to the
overhead of the POSIX emulation layer).

Let's reimplement this with linear complexity (using a hash map to
match the commits' subject lines) for the common case; Sadly, the
fixup/squash feature's design neglected performance considerations,
allowing arbitrary prefixes (read: `fixup! hell` will match the
commit subject `hello world`), which means that we are stuck with
quadratic performance in the worst case.

The reimplemented logic also happens to fix a bug where commented-out
lines (representing empty patches) were dropped by the previous code.

While at it, clarify how the fixup/squash feature works in `git rebase
-i`'s man page.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-05-09 23:41:28 +02:00
Johannes Schindelin
534946025b t3415: test fixup with wrapped oneline
The `git commit --fixup` command unwraps wrapped onelines when
constructing the commit message, without wrapping the result.

We need to make sure that `git rebase --autosquash` keeps handling such
cases correctly, in particular since we are about to move the autosquash
handling into the rebase--helper.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-05-09 23:41:28 +02:00
Johannes Schindelin
d9973f7d30 rebase -i: skip unnecessary picks using the rebase--helper
In particular on Windows, where shell scripts are even more expensive
than on MacOSX or Linux, it makes sense to move a loop that forks
Git at least once for every line in the todo list into a builtin.

Note: The original code did not try to skip unnecessary picks of root
commits but punts instead (probably --root was not considered common
enough of a use case to bother optimizing). We do the same, for now.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-05-09 23:41:27 +02:00
Johannes Schindelin
30039cd877 rebase -i: check for missing commits in the rebase--helper
In particular on Windows, where shell scripts are even more expensive
than on MacOSX or Linux, it makes sense to move a loop that forks
Git at least once for every line in the todo list into a builtin.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-05-09 23:41:27 +02:00
Johannes Schindelin
e138c3a0b2 t3404: relax rebase.missingCommitsCheck tests
These tests were a bit anal about the *exact* warning/error message
printed by git rebase. But those messages are intended for the *end
user*, therefore it does not make sense to test so rigidly for the
*exact* wording.

In the following, we will reimplement the missing commits check in
the sequencer, with slightly different words.

So let's just test for the parts in the warning/error message that
we *really* care about, nothing more, nothing less.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-05-09 23:41:27 +02:00
Johannes Schindelin
49c672f964 rebase -i: also expand/collapse the SHA-1s via the rebase--helper
This is crucial to improve performance on Windows, as the speed is now
mostly dominated by the SHA-1 transformation (because it spawns a new
rev-parse process for *every* line, and spawning processes is pretty
slow from Git for Windows' MSYS2 Bash).

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-05-09 23:41:27 +02:00
Johannes Schindelin
ff92e0ae6e rebase -i: do not invent onelines when expanding/collapsing SHA-1s
To avoid problems with short SHA-1s that become non-unique during the
rebase, we rewrite the todo script with short/long SHA-1s before and
after letting the user edit the script. Since SHA-1s are not intuitive
for humans, rebase -i also provides the onelines (commit message
subjects) in the script, purely for the user's convenience.

It is very possible to generate a todo script via different means than
rebase -i and then to let rebase -i run with it; In this case, these
onelines are not required.

And this is where the expand/collapse machinery has a bug: it *expects*
that oneline, and failing to find one reuses the previous SHA-1 as
"oneline".

It was most likely an oversight, and made implementation in the (quite
limiting) shell script language less convoluted. However, we are about
to reimplement performance-critical parts in C (and due to spawning a
git.exe process for every single line of the todo script, the
expansion/collapsing of the SHA-1s *is* performance-hampering on
Windows), therefore let's fix this bug to make cross-validation with the
C version of that functionality possible.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-05-09 23:41:27 +02:00
Johannes Schindelin
422575f000 rebase -i: remove useless indentation
The commands used to be indented, and it is nice to look at, but when we
transform the SHA-1s, the indentation is removed. So let's do away with it.

For the moment, at least: when we will use the upcoming rebase--helper
to transform the SHA-1s, we *will* keep the indentation and can
reintroduce it. Yet, to be able to validate the rebase--helper against
the output of the current shell script version, we need to remove the
extra indentation.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-05-09 23:41:27 +02:00
Johannes Schindelin
1964146129 rebase -i: generate the script via rebase--helper
The first step of an interactive rebase is to generate the so-called "todo
script", to be stored in the state directory as "git-rebase-todo" and to
be edited by the user.

Originally, we adjusted the output of `git log <options>` using a simple
sed script. Over the course of the years, the code became more
complicated. We now use shell scripting to edit the output of `git log`
conditionally, depending whether to keep "empty" commits (i.e. commits
that do not change any files).

On platforms where shell scripting is not native, this can be a serious
drag. And it opens the door for incompatibilities between platforms when
it comes to shell scripting or to Unix-y commands.

Let's just re-implement the todo script generation in plain C, using the
revision machinery directly.

This is substantially faster, improving the speed relative to the
shell script version of the interactive rebase from 2x to 3x on Windows.

Note that the rearrange_squash() function in git-rebase--interactive
relied on the fact that we set the "format" variable to the config setting
rebase.instructionFormat. Relying on a side effect like this is no good,
hence we explicitly perform that assignment (possibly again) in
rearrange_squash().

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-05-09 23:41:26 +02:00
Johannes Schindelin
afbc2a5427 t3415: verify that an empty instructionFormat is handled as before
An upcoming patch will move the todo list generation into the
rebase--helper. An early version of that patch regressed on an empty
rebase.instructionFormat value (the shell version could not discern
between an empty one and a non-existing one, but the C version used the
empty one as if that was intended to skip the oneline from the `pick
<hash>` lines).

Let's verify that this still works as before.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-05-09 23:41:26 +02:00
Johannes Schindelin
e0df4975e3 Start the merging-rebase to v2.13.0
This commit starts the rebase of 2cb4c91b59 to 074ffb61b4, and marks
the final steps toward Git for Windows v2.13.0.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-05-09 23:32:12 +02:00
Johannes Schindelin
3994f3e499 Merge branch 'coverity-v4-plus-fixup'
Coverity is a tool to analyze code statically, trying to find common (or
not so common) problems before they occur in production.

Coverity offers its services to Open Source software, and just like
upstream Git, Git for Windows applied and was granted the use.

While Coverity reports a lot of false positives due to Git's (ab-)use of
the FLEX_ARRAY feature (where it declares a 0-byte or 1-byte array at the
end of a struct, and then allocates a variable-length data structure
holding a variable-length string at the end, so that the struct as well as
the string can be released with a single free()), there were a few issues
reported that are true positives, and not all of them were resource leaks
in builtins (for which it is considered kind of okay to not release memory
just before exit() is called anyway).

This topic branch tries to address a couple of those issues.

Note: there are a couple more issues left, either because they are tricky
to resolve (in some cases, the custody of occasionally-allocated memory is
very unclear) or because it is unclear whether they are false positives
(due to the hard-to-reason-about nature of the code). It's a start,
though.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-05-09 22:52:23 +02:00
Johannes Schindelin
8a20a46330 Merge branch 'drive-prefix'
This topic branch allows us to specify absolute paths without the drive
prefix e.g. when cloning.

Example:

	C:\Users\me> git clone https://github.com/git/git \upstream-git

This will clone into a new directory C:\upstream-git, in line with how
Windows interprets absolute paths.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-05-09 22:52:22 +02:00
Junio C Hamano
7d7acef258 fixup! checkout: fix memory leak 2017-05-09 22:52:20 +02:00
Johannes Schindelin
fd262f59fe submodule_uses_worktrees(): plug memory leak
There is really no reason why we would need to hold onto the allocated
string longer than necessary.

Reported by Coverity.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-05-09 22:52:20 +02:00
Johannes Schindelin
51d1b4ac56 show_worktree(): plug memory leak
The buffer allocated by shorten_unambiguous_ref() needs to be released.

Discovered by Coverity.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-05-09 22:52:20 +02:00
Johannes Schindelin
b9ca2ff028 name-rev: avoid leaking memory in the deref case
When the `name_rev()` function is asked to dereference the tip name, it
allocates memory. But when it turns out that another tip already
described the commit better than the current one, we forgot to release
the memory.

Pointed out by Coverity.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-05-09 22:52:20 +02:00
Johannes Schindelin
ad13b509c3 remote: plug memory leak in match_explicit()
The `guess_ref()` returns an allocated buffer of which `make_linked_ref()`
does not take custody (`alloc_ref()` makes a copy), therefore we need to
release the buffer afterwards.

Noticed via Coverity.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-05-09 22:52:20 +02:00
Johannes Schindelin
bfecffdace add_reflog_for_walk: avoid memory leak
We free()d the `log` buffer when dwim_log() returned 1, but not when it
returned a larger value (which meant that it still allocated the buffer
but we simply ignored it).

While in the vicinity, make sure that the `reflogs` structure as well as
the `branch` variable are released properly, too.

Identified by Coverity.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-05-09 22:52:20 +02:00
Johannes Schindelin
fbd4bf9853 shallow: avoid memory leak
Reported by Coverity.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-05-09 22:52:19 +02:00
Johannes Schindelin
d7a184271a line-log: avoid memory leak
Discovered by Coverity.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-05-09 22:52:19 +02:00
Johannes Schindelin
b4e3d8ca62 receive-pack: plug memory leak in update()
Reported via Coverity.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-05-09 22:52:19 +02:00
Johannes Schindelin
eb7cffb132 fast-export: avoid leaking memory in handle_tag()
Reported by, you guessed it, Coverity.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-05-09 22:52:19 +02:00
Johannes Schindelin
cd17533d07 mktree: plug memory leaks reported by Coverity
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-05-09 22:52:19 +02:00
Johannes Schindelin
82f76b9835 pack-redundant: plug memory leak
Identified via Coverity.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-05-09 22:52:19 +02:00
Johannes Schindelin
1806b41aff setup_discovered_git_dir(): plug memory leak
The setup_explicit_git_dir() function does not take custody of the string
passed as first parameter; we have to release it if we turned the value of
git_dir into an absolute path.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-05-09 22:52:19 +02:00
Johannes Schindelin
b0f2a371a1 setup_bare_git_dir(): help static analysis
Coverity reported a memory leak in this function. However, it can only
be called once, as setup_git_directory() changes global state and hence
is not reentrant.

Mark the variable as static to indicate that this is a singleton.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-05-09 22:52:19 +02:00
Johannes Schindelin
ab71278ba1 split_commit_in_progress(): simplify & fix memory leak
This function did a whole lot of unnecessary work, such as reading in
four files just to figure out that, oh, hey, we do not need to look at
them after all because the HEAD is not detached.

Simplify the entire function to return early when possible, to read in
the files only when necessary, and to release the allocated memory
always (there was a leak, reported via Coverity, where we failed to
release the allocated strings if the HEAD is not detached).

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-05-09 22:52:19 +02:00
Johannes Schindelin
1e833c9b78 checkout: fix memory leak
This change addresses part of the NEEDSWORK comment above the code,
therefore the comment needs to be adjusted, too.

Discovered via Coverity.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-05-09 22:52:18 +02:00
Johannes Schindelin
a62d38d6aa cat-file: fix memory leak
Discovered by Coverity.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-05-09 22:52:18 +02:00
Johannes Schindelin
6a390e2f47 mailinfo & mailsplit: check for EOF while parsing
While POSIX states that it is okay to pass EOF to isspace() (and it seems
to be implied that EOF should *not* be treated as whitespace), and also to
pass EOF to ungetc() (which seems to be intended to fail without buffering
the character), it is much better to handle these cases explicitly. Not
only does it reduce head-scratching (and helps static analysis avoid
reporting false positives), it also lets us handle files containing
nothing but whitespace by erroring out.

Reported via Coverity.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-05-09 22:52:18 +02:00
Johannes Schindelin
c7f3785a55 status: close file descriptor after reading git-rebase-todo
Reported via Coverity.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-05-09 22:52:18 +02:00
Johannes Schindelin
86093647b4 difftool: address a couple of resource/memory leaks
This change plugs a couple of memory leaks and makes sure that the file
descriptor is closed in run_dir_diff().

Spotted by Coverity.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-05-09 22:52:18 +02:00
Johannes Schindelin
1a1c6633a0 get_mail_commit_oid(): avoid resource leak
When we fail to read, or parse, the file, we still want to close the file
descriptor and release the strbuf.

Reported via Coverity.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-05-09 22:52:18 +02:00
Johannes Schindelin
0420e993d8 git_config_rename_section_in_file(): avoid resource leak
In case of errors, we really want the file descriptor to be closed.

Discovered by a Coverity scan.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-05-09 22:52:18 +02:00
Johannes Schindelin
9b17eed597 add_commit_patch_id(): avoid allocating memory unnecessarily
It would appear that we allocate (and forget to release) memory if the
patch ID is not even defined.

Reported by the Coverity tool.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-05-09 22:52:18 +02:00
Johannes Schindelin
f7360da314 winansi: avoid buffer overrun
When we could not convert the UTF-8 sequence into Unicode for writing to
the Console, we should not try to write an insanely-long sequence of
invalid wide characters (mistaking the negative return value for an
unsigned length).

Reported by Coverity.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-05-09 22:52:18 +02:00
Johannes Schindelin
2db95b62c9 Merge pull request #1149 from jeffhostetler/jeffhostetler/do_write_index_mtime
read-cache: close index.lock in do_write_index
2017-05-09 22:52:17 +02:00
Johannes Schindelin
bd71388d86 winansi: avoid use of uninitialized value
To initialize the foreground color attributes of "plain text", our ANSI
emulation tries to infer them from the currently attached console while
running the is_console() function. This function first tries to detect any
console attached to stdout, then it is called with stderr.

If neither stdout nor stderr has any console attached, it does not
actually matter what we use for "plain text" attributes, as we never need
to output any text to any console in that case.

However, after working on stdout and stderr, is_console() is called with
stdin, and it still tries to initialize the "plain text" attributes if
they had not been initialized earlier. In this case, we cannot detect any
attributes, and we used an uninitialized value for them.

Naturally, Coverity complained about this use case because it could not
reason about the code deeply enough to figure out that we do not even use
those attributes in that case.

Let's just initialize the value to 0 in that case, both to avoid future
Coverity reports, and to help catch future regressions in case anybody
changes the order of the is_console() calls (which would make the text
black on black).

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-05-09 22:52:17 +02:00
Johannes Schindelin
293aa074be mingw: avoid memory leak when splitting PATH
In the (admittedly, concocted) case that PATH consists only of path
delimiters, we would leak the duplicated string.

Reported by Coverity.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-05-09 22:52:17 +02:00
Johannes Schindelin
0eae91cf8d Merge 'case-insensitive-abspath' into HEAD 2017-05-09 22:52:16 +02:00
Johannes Schindelin
436dcd62f2 Merge branch 'skip-gettext-when-possible'
This topic branch allows us to skip the gettext initialization
when the locale directory does not even exist.

This saves 150ms out of 210ms for a simply `git version` call on
Windows, and it most likely will help scripts that call out to
`git.exe` hundreds of times.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-05-09 22:49:14 +02:00
Johannes Schindelin
a487e16fa0 mingw: fix isatty() after dup2()
We newly handle isatty() by special-casing the stdin/stdout/stderr file
descriptors, caching the return value. However, we missed the case where
dup2() overrides the respective file descriptor.

That poses a problem e.g. where the `show` builtin asks for a pager very
early, the `setup_pager()` function sets the pager depending on the
return value of `isatty()` and then redirects stdout. Subsequently,
`cmd_log_init_finish()` calls `setup_pager()` *again*. What should
happen now is that `isatty()` reports that stdout is *not* a TTY and
consequently stdout should be left alone.

Let's override dup2() to handle this appropriately.

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

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-05-09 22:49:13 +02:00
Johannes Schindelin
9f36ae665e Merge branch 'dup-gui' of PhilipOakley/git-gui.git
This resolves a couple of Git GUI issues that seem not to have been
picked up from https://github.com/patthoyts/git-gui/pull/10 yet.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-05-09 22:49:13 +02:00
Johannes Schindelin
e4952fdce0 Merge branch 'strg-t-in-git-gui'
This does not (yet) resolve the problem that Strg+T with multiple
selected lines fails to (un)stage them all, but it addresses one of
the reported Ctrl+T issues.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-05-09 22:49:12 +02:00
Johannes Schindelin
8cde3d9cdc mingw: make is_hidden tests in t0001/t5611 more robust
We should not actually expect the first `attrib.exe` in the PATH to
be the one we are looking for. Or that it is in the PATH, for that
matter.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-05-09 22:49:12 +02:00
Johannes Schindelin
5eeb857723 mingw: ensure valid CTYPE
A change between versions 2.4.1 and 2.6.0 of the MSYS2 runtime modified
how Cygwin's runtime (and hence Git for Windows' MSYS2 runtime
derivative) handles locales: d16a56306d (Consolidate wctomb/mbtowc calls
for POSIX-1.2008, 2016-07-20).

An unintended side-effect is that "cold-calling" into the POSIX
emulation will start with a locale based on the current code page,
something that Git for Windows is very ill-prepared for, as it expects
to be able to pass a command-line containing non-ASCII characters to the
shell without having those characters munged.

One symptom of this behavior: when `git clone` or `git fetch` shell out
to call `git-upload-pack` with a path that contains non-ASCII
characters, the shell tried to interpret the entire command-line
(including command-line parameters) as executable path, which obviously
must fail.

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

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-05-09 22:49:12 +02:00
Johannes Schindelin
e5f5c41fd3 Merge pull request #994 from jeffhostetler/jeffhostetler/fscache_nfd
fscache: add not-found directory cache to fscache
2017-05-09 22:49:12 +02:00
Johannes Schindelin
07a9e8c987 Merge pull request #1032 from max630/gitgui_GIT_GIT_unset
git-gui: correctly restore GIT_DIR after invoking commands
2017-05-09 22:49:11 +02:00
Johannes Schindelin
6dacabc51c Merge branch 'test-unc-alternates'
The fix we introduced in Git for Windows will be made obsolete by a more
general fix that has been already accepted into upstream Git's `next`
branch.

But we still can introduce a regression test that verifies that this bug
will be caught very quickly, if reintroduced.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-05-09 22:49:10 +02:00