Commit Graph

70772 Commits

Author SHA1 Message Date
Doug Kelly
c6febd1e91 Add a test demonstrating a problem with long submodule paths
[jes: adusted test number to avoid conflicts, fixed non-portable use of
the 'export' statement]

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-04-26 16:57:07 +02:00
Karsten Blees
c70cff3d40 fscache: load directories only once
If multiple threads access a directory that is not yet in the cache, the
directory will be loaded by each thread. Only one of the results is added
to the cache, all others are leaked. This wastes performance and memory.

On cache miss, add a future object to the cache to indicate that the
directory is currently being loaded. Subsequent threads register themselves
with the future object and wait. When the first thread has loaded the
directory, it replaces the future object with the result and notifies
waiting threads.

Signed-off-by: Karsten Blees <blees@dcon.de>
2017-04-26 16:57:06 +02:00
Karsten Blees
6c1a8941cf Win32: add a cache below mingw's lstat and dirent implementations
Checking the work tree status is quite slow on Windows, due to slow lstat
emulation (git calls lstat once for each file in the index). Windows
operating system APIs seem to be much better at scanning the status
of entire directories than checking single files.

Add an lstat implementation that uses a cache for lstat data. Cache misses
read the entire parent directory and add it to the cache. Subsequent lstat
calls for the same directory are served directly from the cache.

Also implement opendir / readdir / closedir so that they create and use
directory listings in the cache.

The cache doesn't track file system changes and doesn't plug into any
modifying file APIs, so it has to be explicitly enabled for git functions
that don't modify the working copy.

Note: in an earlier version of this patch, the cache was always active and
tracked file system changes via ReadDirectoryChangesW. However, this was
much more complex and had negative impact on the performance of modifying
git commands such as 'git checkout'.

Signed-off-by: Karsten Blees <blees@dcon.de>
2017-04-26 16:57:06 +02:00
Karsten Blees
52656cc0c3 add infrastructure for read-only file system level caches
Add a macro to mark code sections that only read from the file system,
along with a config option and documentation.

This facilitates implementation of relatively simple file system level
caches without the need to synchronize with the file system.

Enable read-only sections for 'git status' and preload_index.

Signed-off-by: Karsten Blees <blees@dcon.de>
2017-04-26 16:57:06 +02:00
Karsten Blees
8bebf69dbc Win32: make the lstat implementation pluggable
Emulating the POSIX lstat API on Windows via GetFileAttributes[Ex] is quite
slow. Windows operating system APIs seem to be much better at scanning the
status of entire directories than checking single files. A caching
implementation may improve performance by bulk-reading entire directories
or reusing data obtained via opendir / readdir.

Make the lstat implementation pluggable so that it can be switched at
runtime, e.g. based on a config option.

Signed-off-by: Karsten Blees <blees@dcon.de>
2017-04-26 16:57:06 +02:00
Karsten Blees
a59e778150 Win32: Make the dirent implementation pluggable
Emulating the POSIX dirent API on Windows via FindFirstFile/FindNextFile is
pretty staightforward, however, most of the information provided in the
WIN32_FIND_DATA structure is thrown away in the process. A more
sophisticated implementation may cache this data, e.g. for later reuse in
calls to lstat.

Make the dirent implementation pluggable so that it can be switched at
runtime, e.g. based on a config option.

Define a base DIR structure with pointers to readdir/closedir that match
the opendir implementation (i.e. similar to vtable pointers in OOP).
Define readdir/closedir so that they call the function pointers in the DIR
structure. This allows to choose the opendir implementation on a
call-by-call basis.

Move the fixed sized dirent.d_name buffer to the dirent-specific DIR
structure, as d_name may be implementation specific (e.g. a caching
implementation may just set d_name to point into the cache instead of
copying the entire file name string).

Signed-off-by: Karsten Blees <blees@dcon.de>
2017-04-26 16:57:05 +02:00
Karsten Blees
5afe4e23d7 Win32: dirent.c: Move opendir down
Move opendir down in preparation for the next patch.

Signed-off-by: Karsten Blees <blees@dcon.de>
2017-04-26 16:57:05 +02:00
Karsten Blees
429ea008a2 Win32: make FILETIME conversion functions public
Signed-off-by: Karsten Blees <blees@dcon.de>
2017-04-26 16:57:05 +02:00
Johannes Schindelin
96257e4f9d mingw: unset PERL5LIB by default
Git for Windows ships with its own Perl interpreter, and insists on
using it, so it will most likely wreak havoc if PERL5LIB is set before
launching Git.

Let's just unset that environment variables when spawning processes.

To make this feature extensible (and overrideable), there is a new
config setting `core.unsetenvvars` that allows specifying a
comma-separated list of names to unset before spawning processes.

Reported by Gabriel Fuhrmann.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-04-26 16:57:04 +02:00
Johannes Schindelin
181700c80b Move Windows-specific config settings into compat/mingw.c
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-04-26 16:57:04 +02:00
Johannes Schindelin
cce713d087 Allow for platform-specific core.* config settings
In the Git for Windows project, we have ample precendent for config
settings that apply to Windows, and to Windows only.

Let's formalize this concept by introducing a platform_core_config()
function that can be #define'd in a platform-specific manner.

This will allow us to contain platform-specific code better, as the
corresponding variables no longer need to be exported so that they can
be defined in environment.c and be set in config.c

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-04-26 16:57:04 +02:00
Johannes Schindelin
b2185ebf1a Start the merging-rebase to upstream/maint
This commit starts the rebase of b213911f46 to 49800c9407

This merging rebase was started not because upstream's `maint` branch
advanced (it did not), but to replace a couple of patches with newer
iterations, as sent to the upstream Git project independently. In
particular, those are:

- The patch series merged by fe73baf344
  (jeffhostetler/jeffhostetler/quick_add_index_entry) was replaced by
  the most recent iteration of 'jh/add-index-entry-optim' (b986df5c35)

- The Pull Request jeffhostetler/jeffhostetler/string_list_realloc
  merged via c775bdd100 was replaced by the latest iteration of
  'jh/string-list-micro-optim' (950a234cbd)

- The jh/memihash-opt patches merged by 2862058e9d were replaced by the
  newest iteration (41b3eb4a6b)

- The bug fix where difftool used a buffer after freeing it
  (d33e487771) was replaced by the one that made it into upstream
  (882add136f)

- The patch in the `coverity` series that tried to fix a resource leak
  in git-am (a5208164e2) was replaced by a better patch submitted by
  Ren_ Scharfe (ac8ce18d89)

- The patch in the `coverity` series that tried to fix a resource leak
  in the `handle_ssh_variant()` function (f07be76f51) has been dropped,
  as a different patch had been accepted into `pu` already

- The rebase-i-extra patches (e1be548aaf) were replaced by the latest
  iteration (1d3d10b9e15)

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-04-26 16:55:54 +02:00
Johannes Schindelin
bf1cd086d6 Merge branch 'coverity'
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-04-26 12:24:06 +02:00
Johannes Schindelin
37dabece6d 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-04-26 12:24:05 +02:00
Johannes Schindelin
f07be76f51 handle_ssh_variant: plug memory leak
The split_cmdline() function either assigns an allocated array to the argv
parameter or NULL. In the first case, we have to free() it, in the latter
it does no harm.

Reported via Coverity.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-04-26 12:24:04 +02:00
Johannes Schindelin
a5208164e2 am: close input stream even in case of an error
Reported via Coverity.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-04-26 12:24:04 +02:00
Johannes Schindelin
6b88dd4e15 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-04-26 12:24:04 +02:00
Johannes Schindelin
219dce8722 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-04-26 12:24:03 +02:00
Johannes Schindelin
272448d64f 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-04-26 12:24:03 +02:00
Johannes Schindelin
25dc863baf 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-04-26 12:24:03 +02:00
Johannes Schindelin
2042ba35f6 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).

Identified by Coverity.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-04-26 12:24:03 +02:00
Johannes Schindelin
1d3003b2d7 shallow: avoid memory leak
Reported by Coverity.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-04-26 12:24:03 +02:00
Johannes Schindelin
9b4901d6f5 line-log: avoid memory leak
Discovered by Coverity.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-04-26 12:24:03 +02:00
Johannes Schindelin
58a3b2b273 receive-pack: plug memory leak in update()
Reported via Coverity.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-04-26 12:24:03 +02:00
Johannes Schindelin
297da394ed fast-export: avoid leaking memory in handle_tag()
Reported by, you guessed it, Coverity.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-04-26 12:24:02 +02:00
Johannes Schindelin
c7e0a2e8ec mktree: plug memory leaks reported by Coverity
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-04-26 12:24:02 +02:00
Johannes Schindelin
c867f5692f pack-redundant: plug memory leak
Identified via Coverity.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-04-26 12:24:02 +02:00
Johannes Schindelin
7a8ea2c461 setup_discovered_git_dir(): fix memory leak
Identified by Coverity.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-04-26 12:24:02 +02:00
Johannes Schindelin
52b6bc73ac setup_bare_git_dir(): fix memory leak
Reported by Coverity.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-04-26 12:24:02 +02:00
Johannes Schindelin
c1de0a778e split_commit_in_progress(): fix memory leak
Reported via Coverity.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-04-26 12:24:02 +02:00
Johannes Schindelin
665a95f7e7 checkout: fix memory leak
Discovered via Coverity.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-04-26 12:24:02 +02:00
Johannes Schindelin
7cc78ac6fc cat-file: fix memory leak
Discovered by Coverity.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-04-26 12:24:01 +02:00
Johannes Schindelin
917eead1fb Check for EOF while parsing mails
Reported via Coverity.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-04-26 12:24:01 +02:00
Johannes Schindelin
152312932e status: close file descriptor after reading git-rebase-todo
Reported via Coverity.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-04-26 12:24:01 +02:00
Johannes Schindelin
48c8dccc9b difftool: close file descriptors after reading
Spotted by Coverity.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-04-26 12:24:01 +02:00
Johannes Schindelin
34fa615f97 http-backend: avoid memory leaks
Reported via Coverity.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-04-26 12:24:01 +02:00
Johannes Schindelin
cf05da96a3 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-04-26 12:24:01 +02:00
Johannes Schindelin
523ea055e8 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-04-26 12:24:01 +02:00
Johannes Schindelin
5fe7e42028 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-04-26 12:24:00 +02:00
Johannes Schindelin
a655c11256 sequencer: plug resource leak when skipping unnecessary picks
The resource leak only happens in case of an error writing or truncating
the file, therefore it seems less critical, but we should still fix it
nonetheless.

Discovered by Coverity.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-04-26 12:24:00 +02:00
Johannes Schindelin
09b998a6af 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-04-26 12:24:00 +02:00
Johannes Schindelin
2c9bc7ed8d winansi: avoid use of uninitialized value
When stdout is not connected to a Win32 console, we incorrectly used an
uninitialized value for the "plain" character attributes.

Detected by Coverity.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-04-26 12:24:00 +02:00
Johannes Schindelin
edffb73b20 mingw: avoid memory leak when splitting PATH
In the (admittedly, concocted) case that PATH consists only of colons, we
would leak the duplicated string.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-04-26 12:24:00 +02:00
Johannes Schindelin
f811241018 fixup! Help debugging with MSys2 by optionally executing bash with strace
Identified by Coverity.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-04-26 12:24:00 +02:00
Johannes Schindelin
57295d8f55 fixup! mingw: use domain information for default email
Noticed by Coverity.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-04-26 12:23:59 +02:00
Johannes Schindelin
156b911e83 mingw: allow absolute paths without drive prefix
When specifying an absolute path without a drive prefix, we convert that
path internally. Let's make sure that we handle that case properly, too
;-)

This fixes the command

	git clone https://github.com/git-for-windows/git \G4W

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-04-26 12:23:58 +02:00
Johannes Schindelin
ce8b4c0617 mingw: demonstrate a problem with certain absolute paths
On Windows, there are several categories of absolute paths. One such
category starts with a backslash and is implicitly relative to the
drive associated with the current working directory. Example:

	c:
	git clone https://github.com/git-for-windows/git \G4W

should clone into C:\G4W.

There is currently a problem with that, in that mingw_mktemp() does not
expect the _wmktemp() function to prefix the absolute path with the
drive prefix, and as a consequence, the resulting path does not fit into
the originally-passed string buffer. The symptom is a "Result too large"
error.

Reported by Juan Carlos Arevalo Baeza.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-04-26 12:23:58 +02:00
Johannes Schindelin
91e25e0ef0 Merge pull request #1149 from jeffhostetler/jeffhostetler/do_write_index_mtime
read-cache: close index.lock in do_write_index
2017-04-26 12:00:24 +02:00
Jeff Hostetler
d32cf6ff61 read-cache: close index.lock in do_write_index
Teach do_write_index() to close the index.lock file
before getting the mtime and updating the istate.timestamp
fields.

On Windows, a file's mtime is not updated until the file is
closed.  On Linux, the mtime is set after the last flush.

Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com>
2017-04-25 15:25:49 -04:00
Johannes Schindelin
d14a8f8640 abspath_part_inside_repo: respect core.fileMode
If the file system is case-insensitive, we really must be careful to
ignore differences in case only.

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

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-04-12 21:12:42 +02:00