Commit Graph

9251 Commits

Author SHA1 Message Date
Patrick Steinhardt
fabd477125 threads: split up OS-dependent thread-condition code 2016-10-01 17:40:39 +02:00
Patrick Steinhardt
1b8253168a threads: remove unused function pthread_cond_broadcast 2016-10-01 17:40:39 +02:00
Patrick Steinhardt
40b243bf5a threads: split up OS-dependent mutex code 2016-10-01 17:40:38 +02:00
Patrick Steinhardt
fc2b97dd4e threads: split up OS-dependent thread code 2016-10-01 17:40:38 +02:00
Sim Domingo
286e7dbd4b fix error message SHA truncation in git_odb__error_notfound() 2016-10-01 17:40:38 +02:00
David Brooks
4c06f3e7dc HTTP authentication scheme name is case insensitive. 2016-10-01 17:40:38 +02:00
Edward Thomson
ac44d354c8 checkout: use empty baseline when no index
When no index file exists and a baseline is not explicitly provided, use
an empty baseline instead of trying to load `HEAD`.
2016-10-01 17:40:38 +02:00
Edward Thomson
a574d84352 documentation: improve docs for checkout_head
`git_checkout_head` is sadly misunderstood as something that can
switch branches.  It cannot.  Update the documentation to reflect this.
2016-10-01 17:40:38 +02:00
Jason Haslam
27008e849f fetch: Fixed spurious update callback for existing tags. 2016-10-01 17:40:37 +02:00
Patrick Steinhardt
d1fb89dd2f global: clean up crt only after freeing tls data
The thread local storage is used to hold some global state that
is dynamically allocated and should be freed upon exit. On
Windows, we clean up the C run-time right after execution of
registered shutdown callbacks and before cleaning up the TLS.

When we clean up the CRT, we also cause it to analyze for memory
leaks. As we did not free the TLS yet this will lead to false
positives.

Fix the issue by first freeing the TLS and cleaning up the CRT
only afterwards.
2016-10-01 17:40:37 +02:00
Patrick Steinhardt
6e0d473bee tests: fix memory leaks in checkout::typechange 2016-10-01 17:40:37 +02:00
Patrick Steinhardt
246d25b3ce index: fix NULL pointer access in index_remove_entry
When removing an entry from the index by its position, we first
retrieve the position from the index's entries and then try to
remove the retrieved value from the index map with
`DELETE_IN_MAP`. When `index_remove_entry` returns `NULL` we try
to feed it into the `DELETE_IN_MAP` macro, which will
unconditionally call `idxentry_hash` and then happily dereference
the `NULL` entry pointer.

Fix the issue by not passing a `NULL` entry into `DELETE_IN_MAP`.
2016-10-01 17:40:37 +02:00
Patrick Steinhardt
1a70960436 transports: smart: fix potential invalid memory dereferences
When we receive a packet of exactly four bytes encoding its
length as those four bytes it can be treated as an empty line.
While it is not really specified how those empty lines should be
treated, we currently ignore them and do not return an error when
trying to parse it but simply advance the data pointer.

Callers invoking `git_pkt_parse_line` are currently not prepared
to handle this case as they do not explicitly check this case.
While they could always reset the passed out-pointer to `NULL`
before calling `git_pkt_parse_line` and determine if the pointer
has been set afterwards, it makes more sense to update
`git_pkt_parse_line` to set the out-pointer to `NULL` itself when
it encounters such an empty packet. Like this it is guaranteed
that there will be no invalid memory references to free'd
pointers.

As such, the issue has been fixed such that `git_pkt_parse_line`
always sets the packet out pointer to `NULL` when an empty packet
has been received and callers check for this condition, skipping
such packets.
2016-10-01 17:40:37 +02:00
Edward Thomson
11408f0e43 index_read_index: invalidate new paths in tree cache
When adding a new entry to an existing index via `git_index_read_index`,
be sure to remove the tree cache entry for that new path.  This will
mark all parent trees as dirty.
2016-10-01 17:40:37 +02:00
Edward Thomson
8be49681a6 test: ensure we can round-trip a written tree
Read a tree into an index, write the index, then re-open the index and
ensure that we are treesame to the original.
2016-10-01 17:40:37 +02:00
Edward Thomson
80745b1256 index_read_index: set flags for path_len correctly
Update the flags to reset the path_len (to emulate `index_insert`)
2016-10-01 17:40:36 +02:00
Edward Thomson
e755f79fd7 index_read_index: differentiate on mode
Treat index entries with different modes as different, which they
are, at least for the purposes of up-to-date calculations.
2016-10-01 17:40:36 +02:00
Edward Thomson
e6a0a85091 index_read_index: reset error correctly
Clear any error state upon each iteration.  If one of the iterations
ends (with an error of `GIT_ITEROVER`) we need to reset that error to 0,
lest we stop the whole process prematurely.
2016-10-01 17:40:36 +02:00
Edward Thomson
6c133a7575 round-trip trees through index_read_index
Read a tree into an index using `git_index_read_index` (by reading
a tree into a new index, then reading that index into the current
index), then write the index back out, ensuring that our new index
is treesame to the tree that we read.
2016-10-01 17:40:36 +02:00
Edward Thomson
feea2849f9 win32: clean up unused warnings in DllMain 2016-10-01 17:40:36 +02:00
Edward Thomson
efadf28d84 filebuf: fix uninitialized warning 2016-10-01 17:40:36 +02:00
Edward Thomson
bcef008f77 cleanup: unused warning 2016-10-01 17:40:35 +02:00
Elan Ruusamäe
68227c431a Update CMakeLists.txt
typo fix
2016-10-01 17:40:35 +02:00
Jason Haslam
85ef6ec5f0 Ignore submodules when checking for merge conflicts in the workdir. 2016-10-01 17:40:35 +02:00
Jason Haslam
70681ff740 checkout: handle dirty submodules correctly
Don't generate conflicts when checking out a modified submodule and the
submodule is dirty or modified in the workdir.
2016-10-01 17:40:35 +02:00
François Revol
26917fd9d1 test: Fix stat() test to mask out unwanted bits
Haiku and Hurd both pass extra bits in struct stat::st_mode.
2016-10-01 17:40:35 +02:00
François Revol
488937c22d CMakeLists: Add libnetwork for Haiku 2016-10-01 17:40:35 +02:00
Carl Edquist
78b5702ed5 Fix comment for GIT_FILEMODE_LINK
0120000 is symbolic link, not commit
2016-10-01 17:40:34 +02:00
Lucas Derraugh
849a1a4345 Fix unused variable 'message' warning 2016-10-01 17:40:34 +02:00
Patrick Steinhardt
cf0396a563 delta-apply: fix sign extension
We compute offsets by executing `off |= (*delta++ << 24)` for
multiple constants, where `off` is of type `size_t` and `delta`
is of type `unsigned char`. The usual arithmetic conversions (see
ISO C89 §3.2.1.5 "Usual arithmetic conversions") kick in here,
causing us to promote both operands to `int` and then extending
the result to an `unsigned long` when OR'ing it with `off`.
The integer promotion to `int` may result in wrong size
calculations for big values.

Fix the issue by making the constants `unsigned long`, causing both
operands to be promoted to `unsigned long`.
2016-10-01 17:40:34 +02:00
Patrick Steinhardt
1fb8a951b6 odb_loose: fix undefined behavior when computing size
An object's size is computed by reading the object header's size
field until the most significant bit is not set anymore. To get
the total size, we increase the shift on each iteration and add
the shifted value to the total size.

We read the current value into a variable of type `unsigned
char`, from which we then take all bits except the most
significant bit and shift the result. We will end up with a
maximum shift of 60, but this exceeds the width of the value's
type, resulting in undefined behavior.

Fix the issue by instead reading the values into a variable of
type `unsigned long`, which matches the required width. This is
equivalent to git.git, which uses an `unsigned long` as well.
2016-10-01 17:40:34 +02:00
Patrick Steinhardt
f627e19662 checkout: set ignorecase=0 when config lookup fails
When `git_repository__cvar` fails we may end up with a
`ignorecase` value of `-1`. As we subsequently check if
`ignorecase` is non-zero, we may end up reporting that data
should be removed when in fact it should not.

Err on the safer side and set `ignorecase = 0` when
`git_repository__cvar` fails.
2016-10-01 17:40:34 +02:00
Carlos Martín Nieto
66633e836f odb: avoid inflating the full delta to read the header
When we read the header, we want to know the size and type of the
object. We're currently inflating the full delta in order to read the
first few bytes. This can mean hundreds of kB needlessly inflated for
large objects.

Instead use a packfile stream to read just enough so we can read the two
varints in the header and avoid inflating most of the delta.
2016-10-01 17:40:34 +02:00
Patrick Steinhardt
fc2ef5143b index: fix memory leak on error case 2016-10-01 17:40:34 +02:00
Edward Thomson
1aacaa3154 cmake: include threading libraries in pkg-config
Include any required threading libraries in our `libgit2.pc`.
2016-10-01 17:40:33 +02:00
Christian Schlack
b726c53991 Fix return value of openssl_read (infinite loop)
openssl_read should return -1 in case of error.

SSL_read returns values <= 0 in case of error.

A return value of 0 can lead to an infinite loop, so the return value
of ssl_set_error will be returned if SSL_read is not successful (analog
to openssl_write).
2016-10-01 17:40:33 +02:00
Carlos Martín Nieto
16541b864d tag: ignore extra header fields
While no extra header fields are defined for tags, git accepts them by
ignoring them and continuing the search for the message. There are a few
tags like this in the wild which git parses just fine, so we should do
the same.
2016-10-01 17:40:33 +02:00
Carlos Martín Nieto
211e117a05 Merge pull request #3739 from ethomson/0.24.1
Backport bug fixes to 0.24
2016-04-12 00:18:17 +02:00
Edward Thomson
8edadbf978 index::racy: force racy entry
Instead of hoping that we can get a racy entry by going real fast
and praying real hard, just create a racy entry.
2016-04-11 16:40:30 -04:00
Edward Thomson
ccfacb8bb1 leaks: call xdl_free_classifier 2016-04-11 16:17:04 -04:00
Edward Thomson
6a35e74cb3 leaks: fix some leaks in the tests 2016-04-11 16:16:55 -04:00
Carlos Martín Nieto
2c1bc36d56 Plug a few leaks 2016-04-11 16:15:33 -04:00
Edward Thomson
5cc7a5c7b3 tests: skip the unreadable file tests as root
When running as root, skip the unreadable file tests, because, well,
they're probably _not_ unreadable to root unless you've got some
crazy NSA clearance-level honoring operating system shit going on.
2016-04-11 16:05:51 -04:00
Edward Thomson
1d59c85aad status: update test to include valid OID 2016-04-11 15:59:12 -04:00
Edward Thomson
af753aba14 tree: drop the now-unnecessary entries vector
Remove the now-unnecessary entries vector.  Add `git_array_search`
to binary search through an array to accomplish this.
2016-04-11 15:58:59 -04:00
Carlos Martín Nieto
13ebf7bdbc tree: store the entries in a growable array
Take advantage of the constant size of tree-owned arrays and store them
in an array instead of a pool. This still lets us free them all at once
but lets the system allocator do the work of fitting them in.
2016-04-11 15:58:58 -04:00
Carlos Martín Nieto
26f2cefb81 tree: re-use the id and filename in the odb object
Instead of copying over the data into the individual entries, point to
the originals, which are already in a format we can use.
2016-04-11 15:58:58 -04:00
Carlos Martín Nieto
177890838a ignore: don't use realpath to canonicalize path
If we're looking for a symlink, realpath will give us the resolved path,
which is not what we're after, but a canonicalized version of the path
the user asked for.
2016-04-11 15:58:58 -04:00
Edward Thomson
21d8832e74 config::write::repeated: init our buffer 2016-04-11 15:58:58 -04:00
Edward Thomson
a13c1ec206 config: don't write section header if we're in it
If we hit the EOF while trying to write a new value, it may be that
we're already in the section that we were looking for.  If so, do not
write a (duplicate) section header, just write the value.
2016-04-11 15:58:58 -04:00