Commit Graph

10765 Commits

Author SHA1 Message Date
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
Edward Thomson
955c99c214 checkout: don't try to calculate oid for directories
When trying to determine if we can safely overwrite an existing workdir
item, we may need to calculate the oid for the workdir item to determine
if its identical to the old side (and eligible for removal).

We previously did this regardless of the type of entry in the workdir;
if it was a directory, we would open(2) it and then try to read(2).
The read(2) of a directory fails on many platforms, so we would treat it
as if it were unmodified and continue to perform the checkout.

On FreeBSD, you _can_ read(2) a directory, so this pattern failed.  We
would calculate an oid from the data read and determine that the
directory was modified and would therefore generate a checkout conflict.

This reliance on read(2) is silly (and was most likely accidentally
giving us the behavior we wanted), we should be explicit about the
directory test.
2016-09-14 10:28:24 +01:00
Edward Thomson
89c332e41b Merge pull request #3929 from libgit2/vmg/time
time: Export `git_time_monotonic`
2016-09-13 16:16:20 +02:00
Vicent Marti
2749ff46d8 time: Export git_time_monotonic 2016-09-13 15:52:43 +02:00
Patrick Steinhardt
bba704adf7 Merge pull request #3925 from pks-t/pks/cmake-library-dirs
cmake: add curl library path
2016-09-09 08:45:33 +02:00
Edward Thomson
9ad07fc003 Merge pull request #3923 from libgit2/ethomson/diff-read-empty-binary
Read binary patches (with no binary data)
2016-09-06 10:43:21 -05:00
Patrick Steinhardt
46035d984f Merge pull request #3882 from pks-t/pks/fix-fetch-refspec-dst-parsing
refspec: do not set empty rhs for fetch refspecs
2016-09-06 11:21:29 +02:00
Edward Thomson
adedac5aba diff: treat binary patches with no data special
When creating and printing diffs, deal with binary deltas that have
binary data specially, versus diffs that have a binary file but lack the
actual binary data.
2016-09-05 12:26:47 -05:00
Patrick Steinhardt
528b2f7df8 cmake: add curl library path
The `PKG_CHECK_MODULES` function searches a pkg-config module and
then proceeds to set various variables containing information on
how to link to the library. In contrast to the `FIND_PACKAGE`
function, the library path set by `PKG_CHECK_MODULES` will not
necessarily contain linking instructions with a complete path to
the library, though. So when a library is not installed in a
standard location, the linker might later fail due to being
unable to locate it.

While we already honor this when configuring libssh2 by adding
`LIBSSH2_LIBRARY_DIRS` to the link directories, we fail to do so
for libcurl, preventing us to build libgit2 on e.g. FreeBSD. Fix
the issue by adding the curl library directory to the linker
search path.
2016-09-05 13:24:07 +02:00
Edward Thomson
f4e3dae75f diff_print: change test for skipping binary printing
Instead of skipping printing a binary diff when there is no data, skip
printing when we have a status of `UNMODIFIED`.  This is more in-line
with our internal data model and allows us to expand the notion of
binary data.

In the future, there may have no data because the files were unmodified
(there was no data to produce) or it may have no data because there was
no data given to us in a patch.  We want to treat these cases
separately.
2016-09-02 11:26:16 -05:00
Edward Thomson
4bfd7c63fc patch: error on diff callback failure 2016-09-02 11:22:33 -05:00
Edward Thomson
ce54e77c70 Merge pull request #3922 from pks-t/pks/diff-only-load-binaries-when-requested
patch_generate: only calculate binary diffs if requested
2016-09-02 08:50:08 -05:00
Patrick Steinhardt
4b34f687bd patch_generate: only calculate binary diffs if requested
When generating diffs for binary files, we load and decompress
the blobs in order to generate the actual diff, which can be very
costly. While we cannot avoid this for the case when we are
called with the `GIT_DIFF_SHOW_BINARY` flag, we do not have to
load the blobs in the case where this flag is not set, as the
caller is expected to have no interest in the actual content of
binary files.

Fix the issue by only generating a binary diff when the caller is
actually interested in the diff. As libgit2 uses heuristics to
determine that a blob contains binary data by inspecting its size
without loading from the ODB, this saves us quite some time when
diffing in a repository with binary files.
2016-09-01 15:14:25 +02:00
Carlos Martín Nieto
40b08124f2 Merge pull request #3915 from pks-t/pks/index-collision-test-leak
tests: index: do not re-allocate index
2016-08-30 12:11:02 +02:00
Patrick Steinhardt
a08e88259f Merge pull request #3907 from steffhip/git_checkout_tree-fix 2016-08-30 08:22:49 +02:00
Stefan Huber
88cfe61497 git_checkout_tree options fix
According to the reference the git_checkout_tree and git_checkout_head
functions should accept NULL in the opts field

This was broken since the opts field was dereferenced and thus lead to a
crash.
2016-08-30 08:04:28 +02:00
Edward Thomson
dfd7957696 Merge pull request #3914 from pks-t/pks/libqgit2-binding-url
README: adjust URL to libqgit2 repository
2016-08-29 09:39:03 -05:00
Patrick Steinhardt
86e88534d6 tests: index: do not re-allocate index
Plug a memory leak caused by re-allocating a `git_index`
structure which has already been allocated by the test suite's
initializer.
2016-08-29 13:29:01 +02:00
Patrick Steinhardt
8044ee42f5 README: adjust URL to libqgit2 repository 2016-08-29 09:38:20 +02:00
Patrick Steinhardt
ace0d36be9 Merge pull request #3900 from pks-t/pks/http-close-substream-on-connect
transports: http: set substream as disconnected after closing
2016-08-29 09:29:34 +02:00
Richard Ipsum
452bf57cbe Make symbolic ref target validation optional
Introduce GIT_OPT_ENABLE_SYMBOLIC_REF_TARGET_VALIDATION option.
Setting this option to 0 allows
validation of a symbolic ref's target to be bypassed.
This option is enabled by default.

This mechanism is added primarily to address a discrepancy between git
behaviour and libgit2 behaviour, whereby the former allows the symbolic
ref target to carry an arbitrary string and the latter does not, so:

    $ git symbolic-ref refs/heads/foo bar
    $ cat .git/refs/heads/foo
    ref: bar

where as attempting the same via libgit2 raises an error:

    The given reference name 'bar' is not valid

this mechanism also allows those that might want to make use of
git's more lenient treatment of symbolic ref targets to do so.
2016-08-27 18:25:02 +01:00