Commit Graph

6521 Commits

Author SHA1 Message Date
Edward Thomson
1c2c0ae2a4 packbuilder: honor git_object__synchronized_writing
Honor `git_object__synchronized_writing` when creating a packfile and
corresponding index.
2017-02-28 13:27:50 +00:00
Edward Thomson
e6ed0d2f03 odb_loose: fsync tests
Introduce a simple counter that `p_fsync` implements.  This is useful
for ensuring that `p_fsync` is called when we expect it to be, for
example when we have enabled an odb backend to perform `fsync`s when
writing objects.
2017-02-28 13:27:49 +00:00
Edward Thomson
6d3ad7e09e Add ENABLE_SYNCHRONIZED_OBJECT_CREATION option
Allow users to enable `SYNCHRONIZED_OBJECT_CREATION` with a setting.
2017-02-28 13:27:49 +00:00
Edward Thomson
fc27fe213c odb_loose: actually honor the fsync option
We've had an fsync option for a long time, but it was "ignored".
Stop ignoring it.
2017-02-28 13:27:49 +00:00
Edward Thomson
fc77891f63 git_filebuf: optionally fsync when committing 2017-02-28 13:27:49 +00:00
Richard Ipsum
1255a9ac0c Fix: make reflog include "(merge)" for merge commits
This fixes issue #4094
2017-02-27 23:53:12 +00:00
Patrick Steinhardt
7f875fb4f6 Merge pull request #4133 from stinb/khash-cleanup-regression
fix regression from #4092
2017-02-24 08:51:50 +01:00
Jason Haslam
685f22519c pack: fix looping over cache entries
Fixes a regression from #4092. This is a crash on 32-bit and I assume that
it doesn't do the right thing on 64-bit either. MSVC emits a warning for this,
but of course, it's easy to get lost among all of the similar 'possible loss
of data' warnings.
2017-02-22 09:29:00 -07:00
Carlos Martín Nieto
c03f00ea9c Merge pull request #4131 from pks-t/pks/attrcache-cleanups
Attrcache cleanups
2017-02-22 16:30:57 +01:00
Edward Thomson
aa5ea47f73 Provide error on gcc < 4.1 when THREADSAFE
Provide a descriptive error message when compiling THREADSAFE on gcc
versions < 4.1.  We require the atomic primitives (eg
`__sync_synchronize`) that were introduced in that version.

(Note, clang setes `__GNUC__` but appears to set its version > 4.1.)
2017-02-22 11:21:56 +00:00
Patrick Steinhardt
ce6f61daf0 attrcache: remove useless do_init indirection
Remove useless indirection from `git_attr_cache__init` to
`git_attr_cache__do_init`. The difference is that the
`git_attr_cache__init` macro first checks if the cache is already
initialized and, if so, not call `git_attr_cache__do_init`. But
actually, `git_attr_cache__do_init` already does the same thing and
returns immediately if the cache is already initialized.

Remove the indirection.
2017-02-21 16:17:36 +01:00
Patrick Steinhardt
c11510103d attrcache: replace existing file entry with git__swap
When doing an upsert of a file, we used to use `git__compare_and_swap`,
comparing the entry's file which is to be replaced with itself. This can
be more easily formulated by using `git__swap`, which unconditionally
replaces the value.
2017-02-21 16:17:36 +01:00
Patrick Steinhardt
b8ab782a6d attrcache: do not lock/unlock the mutex directly
Improve encapsulation by not referencing the attrcache mutex directly
but instead using the `attr_cache_lock` and `attr_cache_unlock`
functions.
2017-02-21 16:17:31 +01:00
Edward Thomson
b13f0da153 Merge pull request #4130 from libgit2/ethomson/clar_messages
Improve clar messages
2017-02-17 16:32:14 +00:00
Edward Thomson
cc17264270 p_snprintf: no need for arguments to a format
`snprintf` requires a _format_ but does not require _arguments_ to the
format.  eg: `snprintf(buf, 42, "hi")` is perfectly legal.  Expand the
macro to match.

Without this, `p_sprintf(buf, 42, "hi")` errors with:

```
error: expected expression
                p_snprintf(msg, 42, "hi");
                ^
src/unix/posix.h:53:34: note: expanded from macro 'p_snprintf'
                                 ^
/usr/include/secure/_stdio.h:57:73: note: expanded from macro 'snprintf'
  __builtin___snprintf_chk (str, len, 0, __darwin_obsz(str),
__VA_ARGS__)
```
2017-02-17 12:10:19 +00:00
Patrick Steinhardt
8f1ff26bd3 idxmap: remove GIT__USE_IDXMAP 2017-02-17 11:41:06 +01:00
Patrick Steinhardt
cee9ca6609 idxmap: convert to use functions instead of macros 2017-02-17 11:41:06 +01:00
Patrick Steinhardt
8f5fe903d6 offmap: remove GIT__USE_OFFMAP macro 2017-02-17 11:41:06 +01:00
Patrick Steinhardt
cf6124d68b offmap: convert to use functions instead of macros 2017-02-17 11:41:06 +01:00
Patrick Steinhardt
0d71690549 oidmap: remove GIT__USE_OIDMAP macro 2017-02-17 11:41:06 +01:00
Patrick Steinhardt
659f5d07d5 oidmap: convert macros to functions 2017-02-17 11:41:06 +01:00
Patrick Steinhardt
13c3bc9adf strmap: remove GIT__USE_STRMAP macro 2017-02-17 11:41:06 +01:00
Patrick Steinhardt
a13cfd2af2 strmap: convert macros to functions 2017-02-17 11:41:06 +01:00
Patrick Steinhardt
f14f75d4a1 khash: avoid using kh_resize directly 2017-02-17 11:41:06 +01:00
Patrick Steinhardt
73028af85c khash: avoid using macro magic to get return address 2017-02-17 11:41:06 +01:00
Patrick Steinhardt
85d2748c6f khash: avoid using kh_key/kh_val as lvalue 2017-02-17 11:41:06 +01:00
Patrick Steinhardt
f31cb45ad2 khash: avoid using kh_put directly 2017-02-17 11:41:06 +01:00
Patrick Steinhardt
a8cd560b10 khash: avoid using kh_del directly 2017-02-17 11:41:06 +01:00
Patrick Steinhardt
71a54317ef khash: avoid using kh_key directly 2017-02-17 11:41:06 +01:00
Patrick Steinhardt
cb18386f72 khash: avoid using kh_val/kh_value directly 2017-02-17 11:41:06 +01:00
Patrick Steinhardt
76e671a653 khash: avoid using kh_exist directly 2017-02-17 11:41:06 +01:00
Patrick Steinhardt
c37b069b9f khash: avoid using kh_clear directly 2017-02-17 11:41:06 +01:00
Patrick Steinhardt
a853c52723 khash: avoid using kh_get directly 2017-02-17 11:41:06 +01:00
Patrick Steinhardt
64e46dc3b5 khash: avoid using kh_end directly 2017-02-17 11:41:06 +01:00
Patrick Steinhardt
036daa59e9 khash: use git_map_exists where applicable 2017-02-17 11:41:06 +01:00
Patrick Steinhardt
9694d9ba79 khash: avoid using kh_foreach/kh_foreach_value directly 2017-02-17 11:41:06 +01:00
Patrick Steinhardt
63e914cbf4 khash: avoid using kh_size directly 2017-02-17 11:41:06 +01:00
Patrick Steinhardt
a1b23df58c offmap: remove unused macro git_offmap_insert2 2017-02-17 11:41:06 +01:00
Patrick Steinhardt
bff9b7a5a3 strmap: remove unused macro git_strmap_insert2 2017-02-17 11:41:06 +01:00
Patrick Steinhardt
6da6b425d8 refdb: catch additional per-worktree refs
The upstream git.git project currently identifies all references inside
of `refs/bisect/` as well as `HEAD` as per-worktree references. This is
already incorrect and is currently being fixed by an in-flight topic
[1]. The new behavior will be to match all pseudo-references outside of
the `refs/` hierarchy as well as `refs/bisect/`.

Our current behavior is to mark a selection of pseudo-references as
per-worktree, only. This matches more pseudo-references than current
git, but forgets about `refs/bisect/`. Adjust behavior to match the
in-flight topic, that is classify the following references as
per-worktree:

- everything outside of `refs/`
- everything inside of `refs/bisect/`

[1]: <20170213152011.12050-1-pclouds@gmail.com>
2017-02-15 09:06:56 +01:00
Edward Thomson
a59545de5e Merge pull request #4122 from pks-t/pks/signature-dbl-free
Signature cleanups
2017-02-13 14:38:12 +00:00
Patrick Steinhardt
ade0d9c658 commit: avoid possible use-after-free
When extracting a commit's signature, we first free the object and only
afterwards put its signature contents into the result buffer. This works
in most cases - the free'd object will normally be cached anyway, so we
only end up decrementing its reference count without actually freeing
its contents. But in some more exotic setups, where caching is disabled,
this can definitly be a problem, as we might be the only instance
currently holding a reference to this object.

Fix this issue by first extracting the contents and freeing the object
afterwards only.
2017-02-13 13:50:52 +01:00
Patrick Steinhardt
dc851d9eae commit: clear user-provided buffers
The functions `git_commit_header_field` and
`git_commit_extract_signature` both receive buffers used to hand back
the results to the user. While these functions called `git_buf_sanitize`
on these buffers, this is not the right thing to do, as it will simply
initialize or zero-terminate passed buffers. As we want to overwrite
contents, we instead have to call `git_buf_clear` to completely reset
them.
2017-02-13 13:50:52 +01:00
Edward Thomson
c576d4fff2 Merge pull request #4115 from gsaralms/users/gsaral/optionalOfsDelta
Changes to provide option to turn off/on ofs_delta
2017-02-13 12:46:00 +00:00
Patrick Steinhardt
cdb2c2a0bf buffer: clarify how git_buf_sanitize handles non-NULL input
When `git_buf_sanitize` gets called, it converts a buffer with NULL
content to be correctly initialized. This is done by pointing it to
`git_buf__initbuf`. While the method's documentation states this
clearly, it may also lead to the conclusion that it will do the same to
buffers which do _not_ have NULL contents.

Clarify behavior when passing a buffer with non-NULL contents, where
`git_buf_sanitize` will ensure that the contents are `\0`-terminated.
2017-02-13 13:31:37 +01:00
Patrick Steinhardt
1ba242c9ab worktree: extract git_worktree_is_prunable 2017-02-13 11:13:08 +01:00
Patrick Steinhardt
39abd3adaa worktree: compute workdir for worktrees opened via their gitdir
When opening a worktree via the gitdir of its parent repository
we fail to correctly set up the worktree's working directory. The
problem here is two-fold: we first fail to see that the gitdir
actually is a gitdir of a working tree and then subsequently
fail to determine the working tree location from the gitdir.

The first problem of not noticing a gitdir belongs to a worktree
can be solved by checking for the existence of a `gitdir` file in
the gitdir. This file points back to the gitlink file located in
the working tree's working directory. As this file only exists
for worktrees, it should be sufficient indication of the gitdir
belonging to a worktree.

The second problem, that is determining the location of the
worktree's working directory, can then be solved by reading the
`gitdir` file in the working directory's gitdir. When we now
resolve relative paths and strip the final `.git` component, we
have the actual worktree's working directory location.
2017-02-13 11:08:57 +01:00
Patrick Steinhardt
84f56cb05a repository: rename path_repository and path_gitlink
The `path_repository` variable is actually confusing to think
about, as it is not always clear what the repository actually is.
It may either be the path to the folder containing worktree and
.git directory, the path to .git itself, a worktree or something
entirely different. Actually, the intent of the variable is to
hold the path to the gitdir, which is either the .git directory
or the bare repository.

Rename the variable to `gitdir` to avoid confusion. While at it,
also rename `path_gitlink` to `gitlink` to improve consistency.
2017-02-13 11:07:52 +01:00
Patrick Steinhardt
384518d09d repository: restrict checking out checked out branches
If a branch is already checked out in a working tree we are not
allowed to check out that branch in another repository. Introduce
this restriction when setting a repository's HEAD.
2017-02-13 11:06:52 +01:00
Patrick Steinhardt
143e539fd0 branch: restrict branch deletion for worktrees
Restrict the ability to delete branches that are checked out in
any linked repository.
2017-02-13 11:05:57 +01:00
Patrick Steinhardt
e3acd37b70 branch: implement git_branch_is_checked_out
Implement a new function that is able to determine if a branch is
checked out in any repository connected to the current
repository. In particular, this is required to check if for a
given repository and branch, there exists any working tree
connected to that repository that is referencing this branch.
2017-02-13 11:04:57 +01:00
Patrick Steinhardt
04fb12abb2 worktree: implement functions reading HEAD
Implement `git_repository_head_for_worktree` and
`git_repository_head_detached_for_worktree` for directly accessing a
worktree's HEAD without opening it as a `git_repository` first.
2017-02-13 11:03:01 +01:00
Patrick Steinhardt
f0cfc34105 worktree: implement git_worktree_prune
Implement the `git_worktree_prune` function. This function can be
used to delete working trees from a repository. According to the
flags passed to it, it can either delete the working tree's
gitdir only or both gitdir and the working directory.
2017-02-13 11:02:03 +01:00
Patrick Steinhardt
2a503485fa worktree: implement locking mechanisms
Working trees support locking by creating a file `locked` inside
the tree's gitdir with an optional reason inside. Support this
feature by adding functions to get and set the locking status.
2017-02-13 11:01:09 +01:00
Patrick Steinhardt
dea7488e93 worktree: implement git_worktree_add
Implement the `git_worktree_add` function which can be used to create
new working trees for a given repository.
2017-02-13 11:00:17 +01:00
Patrick Steinhardt
372dc9ff6a worktree: implement git_worktree_validate
Add a new function that checks wether a given `struct
git_worktree` is valid. The validation includes checking if the
gitdir, parent directory and common directory are present.
2017-02-13 10:59:16 +01:00
Patrick Steinhardt
8c8d726ef7 worktree: implement git_repository_open_from_worktree
Add function `git_repository_open_from_worktree`, which allows to open a
`git_worktree` as repository.
2017-02-13 10:59:04 +01:00
Patrick Steinhardt
d3bc09e816 worktree: introduce struct git_worktree
Introduce a new `struct git_worktree`, which holds information
about a possible working tree connected to a repository.
Introduce functions to allow opening working trees for a
repository.
2017-02-13 10:28:15 +01:00
Patrick Steinhardt
45f2b7a43f worktree: implement git_worktree_list
Add new module for working trees with the `git_worktree_list`
function. The function lists names for all working trees of a
certain repository.
2017-02-13 10:28:15 +01:00
Patrick Steinhardt
854b5c70e3 repository: expose repo_init_create_head
Expose the function `repo_init_create_head` as
`git_repository_create_head`.
2017-02-13 10:28:15 +01:00
Patrick Steinhardt
4292837d50 config: open configuration in commondir
A repository's configuartion file can always be found in the
GIT_COMMON_DIR, which has been newly introduced. For normal
repositories this does change nothing, but for working trees this
change allows to access the shared configuration file.
2017-02-13 10:28:15 +01:00
Patrick Steinhardt
e9403024fe refdb: look for reflog in commondir 2017-02-13 10:28:15 +01:00
Patrick Steinhardt
e0a6c28eb3 refdb: introduce commondir awareness
The refdb_fs_backend is not aware of the git commondir, which
stores common objects like the o bject database and packed/loose
refereensces when worktrees are used.

Make refdb_fs_backend aware of the common directory by
introducing a new commonpath variable that points to the actual
common path of the database and using it instead of the gitdir
for the mentioned objects.
2017-02-13 10:28:15 +01:00
Patrick Steinhardt
71dd086195 refdb: rename refdb_fs_backend's .path to .gitpath
The variable '.path' of the refdb_fs_backend struct becomes
confusing regarding the introduction of the git commondir. It
does not immediatly become obvious what it should point to.

Fix this problem by renaming the variable to `gitpath`,
clarifying that it acutally points to the `.git` directory of the
repository, in contrast to the commonpath directory, which points
to the directory containing shared objects like references and
the object store.
2017-02-13 10:28:15 +01:00
Patrick Steinhardt
79ab3ef69f repository: introduce is_worktree variable 2017-02-13 10:28:15 +01:00
Patrick Steinhardt
c5f3da9692 repository: use git_repository_item_path
The recent introduction of the commondir variable of a repository
requires callers to distinguish whether their files are part of
the dot-git directory or the common directory shared between
multpile worktrees. In order to take the burden from callers and
unify knowledge on which files reside where, the
`git_repository_item_path` function has been introduced which
encapsulate this knowledge.

Modify most existing callers of `git_repository_path` to use
`git_repository_item_path` instead, thus making them implicitly
aware of the common directory.
2017-02-13 10:28:15 +01:00
Patrick Steinhardt
cb3269c970 repository: add function to retrieve paths for repo items 2017-02-13 10:28:15 +01:00
Patrick Steinhardt
c09fd54e2e repository: introduce commondir variable
The commondir variable stores the path to the common directory.
The common directory is used to store objects and references
shared across multiple repositories. A current use case is the
newly introduced `git worktree` feature, which sets up a separate
working copy, where the backing git object store and references
are pointed to by the common directory.
2017-02-13 10:13:02 +01:00
Edward Thomson
b0c3fa36c1 Merge pull request #4112 from cbargren/fix/proxy-env-vars
Add support for lowercase proxy environment variables
2017-02-10 16:15:41 +00:00
Christopher Bargren
61189a115b Fixing a code style issue 2017-02-10 07:59:22 -07:00
Edward Thomson
683ff4f323 Merge pull request #4111 from pks-t/pks/dos-prefix
dirname with DOS prefixes
2017-02-10 11:01:23 +00:00
Gaurav Saral
61acc9fade Changes to provide option to turn off/on ofs_delta
This change provides an option in git_libgit2_opt_t which can be used in git_libgit2_opts to turn off/on ofs_delta capability in libGit2
2017-02-10 15:22:00 +05:30
Edward Thomson
191474a1f4 diff: don't do rename detection on submodules 2017-02-09 22:35:09 +00:00
Edward Thomson
95367366b2 merge: don't do rename detection on submodules 2017-02-09 18:28:39 +00:00
Edward Thomson
b4bd5e8453 Merge pull request #4104 from cbargren/fix/windows-digest-proxy
Fix digest credentials for proxy in windows
2017-02-09 09:27:04 +00:00
Christopher Bargren
2af282d835 Addressing PR feedback 2017-02-08 15:01:30 -07:00
Christopher Bargren
5f3276c7e6 Add support for lowercase proxy environment variables
curl supports HTTPS_PROXY in addition to https_proxy (and their http counterparts). This change ensures parity with curl's behavior.
2017-02-08 15:01:24 -07:00
Patrick Steinhardt
9e8d75c7d4 path: ensure dirname on Win32 prefix always has a trailing '/'
When calling `git_path_dirname_r` on a Win32 prefix, e.g. a drive
or network share prefix, we always want to return the trailing
'/'. This does not work currently when passing in a path like
'C:', where the '/' would not be appended correctly.

Fix this by appending a '/' if we try to normalize a Win32 prefix
and there is no trailing '/'.
2017-02-08 12:05:47 +01:00
Patrick Steinhardt
5d59520ccd path: get correct dirname for Windows root
Getting the dirname of a filesystem root should return the filesystem
root itself. E.g. the dirname of "/" is always "/". On Windows, we
emulate this behavior and as such, we should return e.g. "C:/" if
calling dirname on "C:/". But we currently fail to do so and instead
return ".", as we do not check if we actually have a Windows prefix
before stripping off the last directory component.

Fix this by calling out to `win32_prefix_length` immediately after
stripping trailing slashes, returning early if we have a prefix.
2017-02-08 12:03:49 +01:00
Patrick Steinhardt
d8c06070a8 path: extract win32_path_prefix function
Extract code which determines if a path is at a Windows system's root.
This incluses drive prefixes (e.g. "C:\") as well as network computer
names (e.g. "//computername/").
2017-02-08 12:03:45 +01:00
Christopher Bargren
1e929eb5e2 Pass proxy options payload to credentials callback 2017-02-06 11:00:06 -07:00
Chris Bargren
fa2dfcf924 Fix digest credentials for proxy in windows 2017-02-06 10:56:00 -07:00
Patrick Steinhardt
f47db3c799 vector: do not reverse a vector if it is empty
The code reversing a vector initially determines the rear-pointer by
simply subtracting 1 from the vector's length. Obviously, this fails if
the vector is empty, in which case we have an integer overflow.

Fix the issue by returning early if the vector is empty.
2017-02-02 16:02:57 +01:00
tyler wanek
39e76bb346 Do not discard proxy_options that have been set when auto is specified 2017-01-27 16:16:39 -07:00
Matthew Plough
d0c418c0bb Fix uninitialized variable warning
Fix the following warning emitted by clang:
[ 16%] Building C object CMakeFiles/libgit2_clar.dir/src/submodule.c.o
/Users/mplough/devel/external/libgit2/src/submodule.c:408:6: warning: variable 'i' is used uninitialized whenever 'if' condition is true
      [-Wsometimes-uninitialized]
        if ((error = load_submodule_names(names, cfg)))
            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/mplough/devel/external/libgit2/src/submodule.c:448:20: note: uninitialized use occurs here
        git_iterator_free(i);
                          ^
/Users/mplough/devel/external/libgit2/src/submodule.c:408:2: note: remove the 'if' if its condition is always false
        if ((error = load_submodule_names(names, cfg)))
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/mplough/devel/external/libgit2/src/submodule.c:404:17: note: initialize the variable 'i' to silence this warning
        git_iterator *i;
                       ^
                        = NULL
1 warning generated.
2017-01-27 12:49:48 -05:00
Carlos Martín Nieto
8df1cfc9d7 Merge pull request #4086 from libgit2/ethomson/fixes
WIP: some coverity & compiler warning fixes
2017-01-24 21:26:41 +00:00
Carlos Martín Nieto
9b51cc82ff Merge pull request #4050 from ethomson/ethomson/winhttp_errmsgs
WinHTTP: set proper error messages when SSL fails
2017-01-24 21:10:46 +00:00
Edward Thomson
7f66a70eec attr_cache_remove: don't remove given file
If `attr_cache_lookup_entry` fails to find the given file, make sure
that we do not try to free the given file.
2017-01-23 23:23:54 +00:00
Edward Thomson
a0d3847983 mac: on 32 bit, use __builtin_umull_overflow 2017-01-23 22:29:58 +00:00
Edward Thomson
60c2bf47e4 submodule: only examine idx & head given a config 2017-01-23 22:29:57 +00:00
Edward Thomson
0fbff82b57 submodule: don't double free during load failure
When we fail to load submodules, don't free the list; it is later freed
unconditionally.
2017-01-23 22:24:40 +00:00
Etienne Samson
e2b3dc16b9 variable 'i' is used uninitialized whenever 'if' condition is true 2017-01-23 13:32:34 +01:00
Edward Thomson
185fe9c1c1 Merge pull request #4051 from tiennou/clang-analyzer-1
Clang analyzer run
2017-01-21 23:58:41 +00:00
Edward Thomson
048c5ea7c0 Merge pull request #4053 from chescock/extend-packfile-by-pages
Extend packfile in increments of page_size.
2017-01-21 23:55:21 +00:00
Edward Thomson
8d3b39a6ad Merge branch 'pr/3912' 2017-01-21 23:50:38 +00:00
Edward Thomson
28d0ba0ba5 symbolic ref target validation: fixups
Fixups requested in #3912.
2017-01-21 23:45:23 +00:00
Edward Thomson
1910a04adb winhttp: set proper cert failure error messages
Set up a WinHTTP status callback; inspect the WinHTTP status for
WINHTTP_CALLBACK_STATUS_SECURE_FAILURE, and convert the status code
to a useful message for callers.
2017-01-21 23:15:54 +00:00
Edward Thomson
44e8af8f29 Merge pull request #3892 from mitesch/shared_buffer
Use a shared buffer in calls of git_treebuilder_write to avoid heap contention
2017-01-21 22:51:50 +00:00
Edward Thomson
9e78b7279d Merge branch 'master' into pr/3938 2017-01-21 22:39:59 +00:00
Edward Thomson
87b7a7051b indexer: avoid warning about idx->pack
It must be non-NULL to have a valid `git_indexer`.
2017-01-21 15:44:57 -05:00
Edward Thomson
bf339ab0ef indexer: introduce git_packfile_close
Encapsulation!
2017-01-21 15:21:29 -05:00
Edward Thomson
98f5387233 Merge pull request #4016 from novalis/submodule-optimization
Submodule optimization
2017-01-21 18:57:28 +00:00
Edward Thomson
52949c806b Merge branch 'pr/4060' 2017-01-21 18:30:12 +00:00
Edward Thomson
d030bba9fa indexer: only delete temp file if it was unused
Only try to `unlink` our temp file when we know that we didn't copy it
into its permanent location.
2017-01-21 17:15:33 +00:00
Brock Peabody
673dff88a2 Skip submodule head/index update when caching.
`git_submodule_status` is very slow, bottlenecked on
`git_repository_head_tree`, which it uses through `submodule_update_head`.  If
the user has requested submodule caching, assume that they want this status
cached too and skip it.

Signed-off-by: David Turner <dturner@twosigma.com>
2017-01-20 17:33:56 -05:00
Brock Peabody
4d99c4cfc6 Allow for caching of submodules.
Added `git_repository_submodule_cache_all` to initialze a cache of
submodules on the repository so that operations looking up N
submodules are O(N) and not O(N^2).  Added a
`git_repository_submodule_cache_clear` function to remove the cache.

Also optimized the function that loads all submodules as it was itself
O(N^2) w.r.t the number of submodules, having to loop through the
`.gitmodules` file once per submodule.  I changed it to process the
`.gitmodules` file once, into a map.

Signed-off-by: David Turner <dturner@twosigma.com>
2017-01-20 17:33:56 -05:00
David Turner
ca05857e71 Fix formatting
Signed-off-by: David Turner <dturner@twosigma.com>
2017-01-20 17:33:56 -05:00
Edward Thomson
4e4a1460eb WinHTTP: support best auth mechanism
For username/password credentials, support NTLM or Basic (in that order
of priority).  Use the WinHTTP built-in authentication support for both,
and maintain a bitfield of the supported mechanisms from the response.
2017-01-16 11:21:26 +00:00
Edward Thomson
cb76eed5ce Merge pull request #4054 from jfultz/jfultz/fix_GIT_CHECKOUT_DISABLE_PATHSPEC_MATCH
Fix handling of GIT_CHECKOUT_DISABLE_PATHSPEC_MATCH flag.
2017-01-14 17:41:49 +00:00
Carlos Martín Nieto
2854e61956 Merge pull request #4061 from libgit2/ethomson/merge_opts
merge: set default rename threshold
2017-01-14 17:12:23 +00:00
lhchavez
f5586f5c73 Addressed review feedback 2017-01-14 16:37:00 +00:00
Etienne Samson
49be45a189 pack: report revwalk error 2017-01-13 21:48:20 +01:00
Etienne Samson
b0014063b2 patch: memory leak of patch.base.diff_opts.new|old_prefix 2017-01-13 21:48:20 +01:00
Etienne Samson
8a349bf2a1 ignore: there must be a repository
Otherwise we'll NULL-dereference in git_attr_cache__init
2017-01-13 21:48:20 +01:00
Carlos Martín Nieto
a6d833a29e Merge pull request #4049 from libgit2/ethomson/error_msgs
giterr_set: consistent error messages
2017-01-13 17:05:58 +01:00
Carlos Martín Nieto
ee89941fa2 Merge remote-tracking branch 'upstream/maint/v0.25' 2017-01-09 21:00:07 +00:00
Edward Thomson
6850b516b9 Merge branch '25_smartpktparse' into maint/v0.25 2017-01-06 17:12:16 +00:00
Patrick Steinhardt
2fdef641fd smart_pkt: treat empty packet lines as error
The Git protocol does not specify what should happen in the case
of an empty packet line (that is a packet line "0004"). We
currently indicate success, but do not return a packet in the
case where we hit an empty line. The smart protocol was not
prepared to handle such packets in all cases, though, resulting
in a `NULL` pointer dereference.

Fix the issue by returning an error instead. As such kind of
packets is not even specified by upstream, this is the right
thing to do.
2017-01-06 17:11:58 +00:00
Patrick Steinhardt
66e3774d27 smart_pkt: verify packet length exceeds PKT_LEN_SIZE
Each packet line in the Git protocol is prefixed by a four-byte
length of how much data will follow, which we parse in
`git_pkt_parse_line`. The transmitted length can either be equal
to zero in case of a flush packet or has to be at least of length
four, as it also includes the encoded length itself. Not
checking this may result in a buffer overflow as we directly pass
the length to functions which accept a `size_t` length as
parameter.

Fix the issue by verifying that non-flush packets have at least a
length of `PKT_LEN_SIZE`.
2017-01-06 17:11:44 +00:00
Etienne Samson
9a64e62f0f http: check certificate validity before clobbering the error variable 2017-01-06 17:09:39 +00:00
lhchavez
96df833b63 Close the file before unlinking
I forgot that Windows chokes while trying to delete open files.
2017-01-03 19:15:09 -08:00
Edward Thomson
19ed4d0ca3 merge: set default rename threshold
When `GIT_MERGE_FIND_RENAMES` is set, provide a default for
`rename_threshold` when it is unset.
2017-01-01 22:34:43 +00:00
lhchavez
db535d0a7d Delete temporary packfile in indexer
This change deletes the temporary packfile that the indexer creates to
avoid littering the pack/ directory with garbage.
2017-01-01 12:46:37 -08:00
Edward Thomson
42ad85ef01 Merge pull request #4043 from fudanchii/fudanchii/openbsd
Fix BIO_* functions method linking when compiled with libressl (OpenBSD).
2016-12-30 16:35:24 +00:00
John Fultz
5f959dca0d Fix handling of GIT_CHECKOUT_DISABLE_PATHSPEC_MATCH flag.
git_checkout_tree() sets up its working directory iterator to respect the
pathlist if GIT_CHECKOUT_DISABLE_PATHSPEC_MATCH is present, which is great.
What's not so great is that this iterator is then used side-by-side with
an iterator created by git_checkout_iterator(), which did not set up its
pathlist appropriately (although the iterator mirrors all other iterator
options).

This could cause git_checkout_tree() to delete working tree files which
were not specified in the pathlist when GIT_CHECKOUT_DISABLE_PATHSPEC_MATCH
was used, as the unsynchronized iterators causes git_checkout_tree() to think
that files have been deleted between the two trees.  Oops.

And added a test which fails without this fix (specifically, the final check
for "testrepo/README" to still be present fails).
2016-12-29 20:13:03 -06:00
Chris Hescock
c7a1535f32 Extend packfile in increments of page_size.
This improves performance by reducing the number of I/O operations.
2016-12-29 15:48:31 -05:00
Edward Thomson
909d549436 giterr_set: consistent error messages
Error messages should be sentence fragments, and therefore:

1. Should not begin with a capital letter,
2. Should not conclude with punctuation, and
3. Should not end a sentence and begin a new one
2016-12-29 12:26:03 +00:00
Jacques Germishuys
f928c69a07 rebase: check the result code of rebase_init_merge 2016-12-29 12:54:26 +02:00
Jacques Germishuys
6a8127d71d mempack: set the odb backend version 2016-12-25 22:13:48 +02:00
Nurahmadie
567b83de54 Fix BIO_* functions method linking when compiled with libressl.
ref:
672ac74ce7/media-video/ffmpeg/files/ffmpeg-3.2-libressl.patch
2016-12-24 17:43:08 +07:00
Carlos Martín Nieto
fafafb1f37 http: bump the pretend git version in the User-Agent
We want to keep the git UA in order for services to recognise that we're
a Git client and not a browser. But in order to stop dumb HTTP some
services have blocked UAs that claim to be pre-1.6.6 git.

Thread these needles by using the "git/2.0" prefix which is still close
enough to git's yet distinct enough that you can tell it's us.
2016-12-20 16:19:30 +00:00
Edward Thomson
8d7717c471 Merge pull request #4034 from libgit2/cmn/sysdir-no-reguess
sysdir: don't re-guess when using variable substitution
2016-12-20 15:32:49 +00:00
Edward Thomson
f91f170f0e Merge pull request #4032 from libgit2/cmn/https-cap-no-hardcode
Don't hard-code HTTPS cap & clarify the meanings of the features enum
2016-12-20 15:28:46 +00:00
Carlos Martín Nieto
3714c13a88 Merge pull request #4026 from libgit2/cmn/refdb-fs-errors
refdb: bubble up recursive rm when locking a ref
2016-12-19 17:28:41 +00:00
Carlos Martín Nieto
903955f7e5 Merge pull request #4027 from pks-t/pks/pack-deref-cache-on-error
pack: dereference cached pack entry on error
2016-12-19 17:26:09 +00:00
Carlos Martín Nieto
9f09f290bb sysdir: don't guess the paths again when $PATH is specified
We should replace it with whatever the user set, not start again.
2016-12-18 14:47:27 +00:00
Andreas Henriksson
23c9ff8632 Fix off-by-one problems in git_signature__parse
Etc/GMT-14 aka UTC+14:00 is a thing....
https://en.wikipedia.org/wiki/UTC%2B14:00

Also allow offsets on the last minute (59).

Addresses: https://bugs.debian.org/841532
Fixes: #3970
2016-12-17 17:40:49 +01:00
Carlos Martín Nieto
061a0ad1f9 settings: don't hard-code HTTPS capability
This partially reverts bdec62dce1 which activates
the transport code-paths which allow you to use a custom TLS implementation
without having to have one at build-time.

However the capabilities describe how libgit2 was built, not what it could
potentially support, bring back the ifdefs so we only say we support HTTPS if
libgit2 was itself built with a TLS implementation.
2016-12-17 14:23:35 +00:00
Carlos Martín Nieto
6ab65b80b4 refdb: bubble up recursive rm when locking a ref
Failure to bubble up this error means some locking errors do not get reported as
such on Windows.
2016-12-16 11:33:54 +00:00
Michael Tesch
87aaefe20b write_tree: use shared buffer for writing trees
The function to write trees allocates a new buffer for each tree.
This causes problems with performance when performing a lot
of actions involving writing trees, e.g. when doing many merges.
Fix the issue by instead handing in a shared buffer, which is then
re-used across the calls without having to re-allocate between
calls.
2016-12-12 10:46:05 -05:00
Patrick Steinhardt
ff5eea06a9 pack: dereference cached pack entry on error
When trying to uncompress deltas in a packfile's delta chain, we try to
add object bases to the packfile cache, subsequently decrementing its
reference count if it has been added successfully. This may lead to a
mismatched reference count in the case where we exit the loop early due
to an encountered error.

Fix the issue by decrementing the reference count in error cleanup.
2016-12-12 09:45:07 +01:00
Patrick Steinhardt
34b320535b Fix potential use of uninitialized values 2016-12-12 09:16:33 +01:00
Patrick Steinhardt
e781a0c52f graph: flag fields should be declared as unsigned 2016-12-12 09:16:33 +01:00
Patrick Steinhardt
482d17484e transports: smart: do not redeclare loop counters 2016-12-12 09:16:33 +01:00
Patrick Steinhardt
6cf575b1ad path: remove unused local variable 2016-12-12 09:16:33 +01:00
Patrick Steinhardt
013ecb4f2a revwalk: do not re-declare commit variable 2016-12-12 09:16:33 +01:00
Patrick Steinhardt
8468a44067 odb_mempack: mark zero-length array as GIT_FLEX_ARRAY 2016-12-12 09:16:33 +01:00
Edward Thomson
8339c66068 Merge pull request #4020 from novalis/rebase-detached
git_rebase_init: correctly handle detached HEAD
2016-12-07 17:44:25 +00:00
Boris Barbulovski
9af59f5dcd Properly pass wchar * type to giterr_set 2016-12-06 03:08:52 +01:00
David Turner
4db1fc7e5e git_rebase_init: correctly handle detached HEAD
git_rebase_finish relies on head_detached being set, but
rebase_init_merge was only setting it when branch->ref_name was unset.
But branch->ref_name would be set to "HEAD" in the case of detached
HEAD being either implicitly (NULL) or explicitly passed to
git_rebase_init.
2016-12-01 23:11:57 -05:00
Boris Barbulovski
86364af995 Properly pass wchar * type to giterr_set 2016-11-20 11:30:45 +01:00
Carlos Martín Nieto
ae5838f118 Merge pull request #4010 from libgit2/ethomson/clar_threads
Introduce some clar helpers for child threads
2016-11-18 21:01:51 +01:00
Edward Thomson
82f15896de threads: introduce git_thread_exit
Introduce `git_thread_exit`, which will allow threads to terminate at an
arbitrary time, returning a `void *`.  On Windows, this means that we
need to store the current `git_thread` in TLS, so that we can set its
`return` value when terminating.

We cannot simply use `ExitThread`, since Win32 returns `DWORD`s from
threads; we return `void *`.
2016-11-18 07:34:09 -05:00
Pranit Bauva
65b78ea301 use giterr_set_str() wherever possible
`giterr_set()` is used when it is required to format a string, and since
we don't really require it for this case, it is better to stick to
`giterr_set_str()`.

This also suppresses a warning(-Wformat-security) raised by the compiler.

Signed-off-by: Pranit Bauva <pranit.bauva@gmail.com>
2016-11-17 01:12:12 +05:30
Carlos Martín Nieto
0cd162be88 Merge pull request #4008 from pks-t/pks/sortedcache-fd-leak
sortedcache: plug leaked file descriptor
2016-11-15 16:28:10 +01:00
Patrick Steinhardt
613381fc14 patch_parse: fix memory leak 2016-11-15 13:33:05 +01:00
Patrick Steinhardt
24b2182c5a sortedcache: plug leaked file descriptor 2016-11-15 12:53:53 +01:00
Carlos Martín Nieto
1db3035d74 Merge pull request #3996 from pks-t/pks/curl-lastsocket-deprecation
curl_stream: use CURLINFO_ACTIVESOCKET if curl is recent enough
2016-11-15 12:18:49 +01:00
Patrick Steinhardt
5cbd52607c curl_stream: use CURLINFO_ACTIVESOCKET if curl is recent enough
The `CURLINFO_LASTSOCKET` information has been deprecated since
curl version 7.45.0 as it may result in an overflow in the
returned socket on certain systems, most importantly on 64 bit
Windows. Instead, a new call `CURLINFO_ACTIVESOCKET` has been
added which instead returns a `curl_socket_t`, which is always
sufficiently long to store a socket.

As we need to provide backwards compatibility with curl versions
smaller than 7.45.0, alias CURLINFO_ACTIVESOCKET to
CURLINFO_LASTSOCKET on platforms without CURLINFO_ACTIVESOCKET.
2016-11-15 09:12:40 +01:00
Edward Thomson
1d683c1d2e Merge pull request #4006 from libgit2/cmn/compress-buf-free
Plug a leak in the refs compressor
2016-11-14 19:21:56 +00:00
Carlos Martín Nieto
21e0fc32ab Plug a leak in the refs compressor 2016-11-14 17:55:49 +01:00
Carlos Martín Nieto
a39f18ac77 Merge pull request #3998 from pks-t/pks/repo-discovery
Repository discovery starting from files
2016-11-14 17:10:43 +01:00
Edward Thomson
df045cef68 Merge pull request #4003 from libgit2/cmn/tree-updater-ordering
Use the sorted input in the tree updater
2016-11-14 12:12:38 +00:00
Carlos Martín Nieto
8977658519 tree: look for conflicts in the new tree when updating
We look at whether we're trying to replace a blob with a tree during the
update phase, but we fail to look at whether we've just inserted a blob
where we're now trying to insert a tree.

Update the check to look at both places. The test for this was
previously succeeding due to the bu where we did not look at the sorted
output.
2016-11-14 12:44:52 +01:00
Carlos Martín Nieto
b85929c523 tree: use the sorted update list in our loop
The loop is made with the assumption that the inputs are sorted and not
using it leads to bad outputs.
2016-11-14 12:44:01 +01:00
Carlos Martín Nieto
ce5553d48b refdb: bubble up locked files on the read side
On Windows we can find locked files even when reading a reference or the
packed-refs file. Bubble up the error in this case as well to allow
callers on Windows to retry more intelligently.
2016-11-14 11:35:38 +01:00
Carlos Martín Nieto
33248b9edb refdb: remove a check-delete race when removing a loose ref
It does not help us to check whether the file exists before trying to
unlink it since it might be gone by the time unlink is called.

Instead try to remove it and handle the resulting error if it did not
exist.
2016-11-14 11:35:38 +01:00
Carlos Martín Nieto
40ffa07f4f sortedcache: check file size after opening the file
Checking the size before we open the file descriptor can lead to the
file being replaced from under us when renames aren't quite atomic, so
we can end up reading too little of the file, leading to us thinking the
file is corrupted.
2016-11-14 11:35:38 +01:00
Carlos Martín Nieto
2e09106e7a refdb: bubble up the error code when compressing the db
This allows the caller to know the errors was e.g. due to the
packed-refs file being already locked and they can try again later.
2016-11-14 11:35:37 +01:00
Carlos Martín Nieto
dd1ca6f15a refdb: refactor the lockfile cleanup
We can reduce the duplication by cleaning up at the beginning of the
loop, since it's something we want to do every time we continue.
2016-11-14 11:35:35 +01:00
Carlos Martín Nieto
7ea4710ae3 refdb: don't report failure for expected errors
There might be a few threads or processes working with references
concurrently, so fortify the code to ignore errors which come from
concurrent access which do not stop us from continuing the work.

This includes ignoring an unlinking error. Either someone else removed
it or we leave the file around. In the former case the job is done, and
in the latter case, the ref is still in a valid state.
2016-11-14 11:34:14 +01:00
Carlos Martín Nieto
f94825c10c fileops: save errno and report file existence
We need to save the errno, lest we clobber it in the giterr_set()
call. Also add code for reporting that a path component is missing,
which is a distinct failure mode.
2016-11-14 11:34:14 +01:00
Carlos Martín Nieto
2d9aec99fb refdb: make ref deletion after pack safer
In order not to undo concurrent modifications to references, we must
make sure that we only delete a loose reference if it still has the same
value as when we packed it.

This means we need to lock it and then compare the value with the one we
put in the packed file.
2016-11-14 11:34:08 +01:00
Carlos Martín Nieto
9914efec2a refdb: bubble up errors
We can get useful information like GIT_ELOCKED out of this instead of
just -1.
2016-11-14 11:25:58 +01:00
Patrick Steinhardt
0f31609611 repository: do not interpret all files as gitlinks in discovery
When trying to find a discovery, we walk up the directory
structure checking if there is a ".git" file or directory and, if
so, check its validity. But in the case that we've got a ".git"
file, we do not want to unconditionally assume that the file is
in fact a ".git" file and treat it as such, as we would error out
if it is not.

Fix the issue by only treating a file as a gitlink file if it
ends with "/.git". This allows users of the function to discover
a repository by handing in any path contained inside of a git
repository.
2016-11-14 10:53:08 +01:00
Carlos Martín Nieto
e1c14335d8 Merge pull request #4002 from pks-t/pks/giterr-format
giterr format
2016-11-14 10:48:57 +01:00
Carlos Martín Nieto
cc5966b071 Merge pull request #3983 from pks-t/pks/smart-early-eof
transports: smart: abort on early end of stream
2016-11-14 10:39:45 +01:00
Patrick Steinhardt
b81fe7c96d path: pass string instead of git_buf to giterr_set 2016-11-14 10:07:55 +01:00
Patrick Steinhardt
90a934a521 checkout: pass string instead of git_buf to giterr_set 2016-11-14 10:07:55 +01:00
Patrick Steinhardt
901434b00f common: cast precision specifiers to int 2016-11-14 10:07:55 +01:00
Patrick Steinhardt
c77a55a917 common: use PRIuZ for size_t in giterr_set calls 2016-11-14 10:05:59 +01:00
Patrick Steinhardt
8effd26f59 common: mark printf-style formatting for giterr_set 2016-11-14 09:54:08 +01:00
Patrick Steinhardt
2d20551642 Merge pull request #3992 from joshtriplett/env-namespace
git_repository_open_ext: fix handling of $GIT_NAMESPACE
2016-11-14 09:38:44 +01:00
Patrick Steinhardt
7b3f49f0c9 fileops: fix typos in git_futils_creat_locked{,with_path} 2016-11-14 09:31:07 +01:00
Josh Triplett
c9e967a1b4 git_repository_open_ext: fix handling of $GIT_NAMESPACE
The existing code would set a namespace of "" (empty string) with
GIT_NAMESPACE unset.  In a repository where refs/heads/namespaces/
exists, that can produce incorrect results.  Detect that case and avoid
setting the namespace at all.

Since that makes the last assignment to error conditional, and the
previous assignment can potentially get GIT_ENOTFOUND, set error to 0
explicitly to prevent the call from incorrectly failing with
GIT_ENOTFOUND.
2016-11-11 14:15:06 -08:00
Alex Crichton
5ca75fd52c curl_stream: check for -1 after CURLINFO_LASTSOCKET
We're recently trying to upgrade to the current master of libgit2
in Cargo but we're unfortunately hitting a segfault in one of our
tests. This particular test is just a small smoke test that https
works (e.g. it's configured in libgit2). It attempts to clone
from a URL which simply immediately drops connections after
they're accepted (e.g. terminate abnormally). We expect to see a
standard error from libgit2 but unfortunately we're seeing a
segfault.

This segfault is happening inside of the `wait_for` function of
`curl_stream.c` at the line `FD_SET(fd, &errfd)` because `fd` is
-1. This ends up doing an out-of-bounds array access that faults
the program. I tracked back to where this -1 came from to the
line here (returned by `CURLINFO_LASTSOCKET`) and added a check
to return an error.
2016-11-11 11:22:15 +01:00
Patrick Steinhardt
5fe5557e8a Merge pull request #3974 from libgit2/pks/synchronize-shutdown
global: synchronize initialization and shutdown with pthreads
2016-11-04 18:18:46 +01:00
Patrick Steinhardt
6e2fab9ede Merge pull request #3977 from jfultz/fix-forced-branch-creation-on-bare-repo 2016-11-04 18:14:00 +01:00
John Fultz
f9793884a3 branch: fix forced branch creation on HEAD of a bare repo
The code correctly detects that forced creation of a branch on a
nonbare repo should not be able to overwrite a branch which is
the HEAD reference.  But there's no reason to prevent this on
a bare repo, and in fact, git allows this.  I.e.,

   git branch -f master new_sha

works on a bare repo with HEAD set to master.  This change fixes
that problem, and updates tests so that, for this case, both the
bare and nonbare cases are checked for correct behavior.
2016-11-04 18:12:35 +01:00
Carlos Martín Nieto
7175222ce6 Merge pull request #3960 from ignatenkobrain/openssl-1.1.0
add support for OpenSSL 1.1.0 for BIO filter
2016-11-02 14:50:59 +01:00
Carlos Martín Nieto
3b832a085b openssl: include OpenSSL headers only when we're buliding against it
We need to include the initialisation and construction functions in all
backend, so we include this header when building against SecureTransport
and WinHTTP as well.
2016-11-02 13:11:31 +01:00
Carlos Martín Nieto
2f3adf9513 openssl: use ASN1_STRING_get0_data when compiling against 1.1
For older versions we can fall back on the deprecated ASN1_STRING_data.
2016-11-02 13:02:13 +01:00
Carlos Martín Nieto
f15eedb3a3 openssl: recreate the OpenSSL 1.1 BIO interface for older versions
We want to program against the interface, so recreate it when we compile
against pre-1.1 versions.
2016-11-02 13:00:30 +01:00
Patrick Steinhardt
0cf15e39f3 pack: fix race in pack_entry_find_offset
In `pack_entry_find_offset`, we try to find the offset of a
certain object in the pack file. To do so, we first assert if the
packfile has already been opened and open it if not. Opening the
packfile is guarded with a mutex, so concurrent access to this is
in fact safe.

What is not thread-safe though is our calculation of offsets
inside the packfile. Assume two threads calling
`pack_entry_find_offset` at the same time. We first calculate the
offset and index location and only then determine if the pack has
already been opened. If so, we re-calculate the offset and index
address.

Now the case for two threads: thread 1 first calculates the
addresses and is subsequently suspended. The second thread will
now call `pack_index_open` and initialize the pack file,
calculating its addresses correctly. When the first thread is
resumed now, he'll see that the pack file has already been
initialized and will happily proceed with the addresses it has
already calculated before the check. As the pack file was not
initialized before, these addresses are bogus.

Fix the issue by only calculating the addresses after having
checked if the pack file is open.
2016-11-02 12:23:12 +01:00
Patrick Steinhardt
62494bf234 transports: smart: abort receiving packets on end of stream
When trying to receive packets from the remote, we loop until
either an error distinct to `GIT_EBUFS` occurs or until we
successfully parsed the packet. This does not honor the case
where we are looping over an already closed socket which has no
more data, leaving us in an infinite loop if we got a bogus
packet size or if the remote hang up.

Fix the issue by returning `GIT_EEOF` when we cannot read data
from the socket anymore.
2016-11-02 09:42:56 +01:00
Patrick Steinhardt
61530c497d transports: smart: abort ref announcement on early end of stream
When reading a server's reference announcements via the smart
protocol, we expect the server to send multiple flushes before
the protocol is finished. If we fail to receive new data from the
socket, we will only return an end of stream error if we have not
seen any flush yet.

This logic is flawed in that we may run into an infinite loop
when receiving a server's reference announcement with a bogus
flush packet. E.g. assume the last flushing package is changed to
not be '0000' but instead any other value. In this case, we will
still await one more flush package and ignore the fact that we
are not receiving any data from the socket, causing an infinite
loop.

Fix the issue by always returning `GIT_EEOF` if the socket
indicates an end of stream.
2016-11-02 09:41:39 +01:00
Patrick Steinhardt
19001ca7ba Merge pull request #3976 from pks-t/pks/pqueue-null-deref
pqueue: resolve possible NULL pointer dereference
2016-11-02 09:23:53 +01:00
Patrick Steinhardt
038f0e1b4c global: reset global state on shutdown without threading
When threading is not enabled for libgit2, we keep global state
in a simple static variable. When libgit2 is shut down, we clean
up the global state by freeing the global state's dynamically
allocated memory. When libgit2 is built with threading, we
additionally free the thread-local storage and thus completely
remove the global state. In a non-threaded build, though, we
simply leave the global state as-is, which may result in an error
upon reinitializing libgit2.

Fix the issue by zeroing out the variable on a shutdown, thus
returning it to its initial state.
2016-11-02 08:53:52 +01:00
Patrick Steinhardt
59c6c2860a global: synchronize initialization and shutdown with pthreads
When trying to initialize and tear down global data structures
from different threads at once with `git_libgit2_init` and
`git_libgit2_shutdown`, we race around initializing data. While
we use `pthread_once` to assert that we only initilize data a
single time, we actually reset the `pthread_once_t` on the last
call to `git_libgit2_shutdown`. As resetting this variable is not
synchronized with other threads trying to access it, this is
actually racy when one thread tries to do a complete shutdown of
libgit2 while another thread tries to initialize it.

Fix the issue by creating a mutex which synchronizes `init_once`
and the library shutdown.
2016-11-01 14:30:47 +01:00
Patrick Steinhardt
dc98cb28db openssl_stream: fix typo 2016-10-31 13:50:23 +01:00
Patrick Steinhardt
95fa38802f pqueue: resolve possible NULL pointer dereference
The `git_pqueue` struct allows being fixed in its total number of
entries. In this case, we simply throw away items that are
inserted into the priority queue by examining wether the new item
to be inserted has a higher priority than the previous smallest
one.

This feature somewhat contradicts our pqueue implementation in
that it is allowed to not have a comparison function. In fact, we
also fail to check if the comparison function is actually set in
the case where we add a new item into a fully filled fixed-size
pqueue.

As we cannot determine which item is the smallest item in absence
of a comparison function, we fix the `NULL` pointer dereference
by simply dropping all new items which are about to be inserted
into a full fixed-size pqueue.
2016-10-28 16:19:24 +02:00
Arthur Schreiber
6d354747ac Perf: Don't perform merge operations for trivial merges.
When one side of a merge is treesame to the ancestor, we can take the other side and skip all the expensive merge operations. This optimization can only be performed when the generation of  REUC extension data is skipped.
2016-10-18 08:20:41 +02:00
Igor Gnatenko
feb330d50d add support for OpenSSL 1.1.0 for BIO filter
Closes: https://github.com/libgit2/libgit2/issues/3959
Signed-off-by: Igor Gnatenko <i.gnatenko.brain@gmail.com>
2016-10-12 12:41:43 +02:00
Josh Leeb-du Toit
ba3a8304ab Remove set of submodule update checkout_strategy
Remove overriding the `checkout_strategy` for `update_options` when
performing an update on a submodule. Users should be specifying the
correct checkout strategy in
`update_options.checkout_opts.checkout_strategy`.
2016-10-10 09:50:24 +11:00
Josh Leeb-du Toit
567fd782d9 Remove clone_checkout_strategy in submodule update opts
Remove `clone_checkout_strategy` in `git_submodule_update_options` as
per issue #3784.
2016-10-10 09:50:24 +11:00
Edward Thomson
610cff13a3 Merge branch 'pr/3809' 2016-10-09 16:05:48 +01:00
Sim Domingo
dc5cfdbab9 make git_diff_stats_to_buf not show 0 insertions or 0 deletions 2016-10-09 16:03:00 +01:00
Edward Thomson
aae8953496 Merge pull request #3956 from pks-t/pks/object-parsing-hardening
Object parsing hardening
2016-10-09 12:51:48 +01:00
Patrick Steinhardt
a719ef5e6d commit: always initialize commit message
When parsing a commit, we will treat all bytes left after parsing
the headers as the commit message. When no bytes are left, we
leave the commit's message uninitialized. While uncommon to have
a commit without message, this is the right behavior as Git
unfortunately allows for empty commit messages.

Given that this scenario is so uncommon, most programs acting on
the commit message will never check if the message is actually
set, which may lead to errors. To work around the error and not
lay the burden of checking for empty commit messages to the
developer, initialize the commit message with an empty string
when no commit message is given.
2016-10-09 13:26:21 +02:00
Edward Thomson
45dc219f65 Merge pull request #3921 from libgit2/cmn/walk-limit-enough
Improve revision walk preparation logic
2016-10-07 16:01:28 +01:00
Patrick Steinhardt
4974e3a596 tree: validate filename and OID length when parsing object
When parsing tree entries from raw object data, we do not verify
that the tree entry actually has a filename as well as a valid
object ID. Fix this by asserting that the filename length is
non-zero as well as asserting that there are at least
`GIT_OID_RAWSZ` bytes left when parsing the OID.
2016-10-07 09:18:55 +02:00
Carlos Martín Nieto
fedc05c89c revwalk: don't show commits that become uninteresting after being enqueued
When we read from the list which `limit_list()` gives us, we need to check that
the commit is still interesting, as it might have become uninteresting after it
was added to the list.
2016-10-06 18:13:34 +02:00
Arthur Schreiber
ab96ca5572 Make sure we use the C locale for regcomp on macOS. 2016-10-06 13:15:31 +02:00
Carlos Martín Nieto
3cc5ec94f8 rebase: don't ask for time sorting
`git-rebase--merge` does not ask for time sorting, but uses the default. We now
produce the same default time-ordered output as git, so make us of that since
it's not always the same output as our time sorting.
2016-10-06 11:04:55 +02:00
Carlos Martín Nieto
82d4c0e6b8 revwalk: update the description for the default sorting
It changed from implementation-defined to git's default sorting, as there are
systems (e.g. rebase) which depend on this order. Also specify more explicitly
how you can get git's "date-order".
2016-10-06 11:04:55 +02:00
Carlos Martín Nieto
ea1ceb7f55 revwalk: remove a useless enqueueing phase for topological and default sorting
After `limit_list()` we already have the list in time-sorted order, which is
what we want in the "default" case. Enqueueing into the "unsorted" list would
just reverse it, and the topological sort will do its own sorting if it needs
to.
2016-10-06 11:04:55 +02:00
Carlos Martín Nieto
9db367bf27 revwalk: get rid of obsolete marking code
We've now moved to code that's closer to git and produces the output
during the preparation phase, so we no longer process the commits as
part of generating the output.

This makes a chunk of code redundant, as we're simply short-circuiting
it by detecting we've processed the commits alrady.
2016-10-06 11:04:55 +02:00
Carlos Martín Nieto
e93b7e327a revwalk: style change
Change the condition for returning 0 more in line with that we write
elsewhere in the library.
2016-10-06 11:04:55 +02:00
Carlos Martín Nieto
5e2a29a78c commit_list: fix the date comparison function
This returns the integer-cast truth value comparing the dates. What we
want instead of a (-1, 0, 1) output depending on how they compare.
2016-10-06 11:04:55 +02:00
Carlos Martín Nieto
48c64362e4 revwalk: port over the topological sorting
After porting over the commit hiding and selection we were still left
with mistmaching output due to the topologial sort.

This ports the topological sorting code to make us match with our
equivalent of `--date-order` and `--topo-order` against the output
from `rev-list`.
2016-10-06 11:04:55 +02:00
Carlos Martín Nieto
938f8e32ec pqueue: support not having a comparison function
In this case, we simply behave like a vector.
2016-10-06 11:04:55 +02:00
Carlos Martín Nieto
0bd43371c2 vector, pqueue: add git_vector_reverse and git_pqueue_reverse
This is a convenience function to reverse the contents of a vector and a pqueue
in-place.

The pqueue function is useful in the case where we're treating it as a
LIFO queue.
2016-10-06 11:04:55 +02:00
Carlos Martín Nieto
6708618c10 revwalk: get closer to git
We had some home-grown logic to figure out which objects to show during
the revision walk, but it was rather inefficient, looking over the same
list multiple times to figure out when we had run out of interesting
commits. We now use the lists in a smarter way.

We also introduce the slop mechanism to determine when to stpo
looking. When we run out of interesting objects, we continue preparing
the walk for another 5 rounds in order to make it less likely that we
miss objects in situations with complex graphs.
2016-10-06 11:04:55 +02:00
Edward Thomson
9fbbb0eec5 Merge pull request #3931 from libgit2/ethomson/checkout_dont_calculate_oid_for_dirs
checkout: don't try to calculate oid for directories
2016-10-01 19:32:16 -05: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
Vicent Marti
2749ff46d8 time: Export git_time_monotonic 2016-09-13 15:52:43 +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
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
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
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
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
Edward Thomson
b859faa61c Teach git_patch_from_diff about parsed diffs
Ensure that `git_patch_from_diff` can return the patch for parsed diffs,
not just generate a patch for a generated diff.
2016-08-24 09:08:57 -05:00
Jason Haslam
7a3f1de500 filesystem_iterator: fixed double free on error 2016-08-22 09:27:47 -06:00
Edward Thomson
c1b370e931 Merge pull request #3837 from novalis/dturner/indexv4
Support index v4
2016-08-17 09:24:44 -05:00
Edward Thomson
635a922274 Merge pull request #3895 from pks-t/pks/negate-basename-in-subdirs
ignore: allow unignoring basenames in subdirectories
2016-08-17 08:54:48 -05:00
Patrick Steinhardt
b1453601f9 transports: http: reset connected flag when closing transport 2016-08-17 11:41:30 +02:00
Patrick Steinhardt
c4cba4e96a transports: http: reset connected flag when re-connecting transport
When calling `http_connect` on a subtransport whose stream is already
connected, we first close the stream in case no keep-alive is in use.
When doing so, we do not reset the transport's connection state,
though. Usually, this will do no harm in case the subsequent connect
will succeed. But when the connection fails we are left with a
substransport which is tagged as connected but which has no valid
stream attached.

Fix the issue by resetting the subtransport's connected-state when
closing its stream in `http_connect`.
2016-08-17 11:41:22 +02:00
Patrick Steinhardt
fcb2c1c895 ignore: allow unignoring basenames in subdirectories
The .gitignore file allows for patterns which unignore previous
ignore patterns. When unignoring a previous pattern, there are
basically three cases how this is matched when no globbing is
used:

1. when a previous file has been ignored, it can be unignored by
   using its exact name, e.g.

   foo/bar
   !foo/bar

2. when a file in a subdirectory has been ignored, it can be
   unignored by using its basename, e.g.

   foo/bar
   !bar

3. when all files with a basename are ignored, a specific file
   can be unignored again by specifying its path in a
   subdirectory, e.g.

   bar
   !foo/bar

The first problem in libgit2 is that we did not correctly treat
the second case. While we verified that the negative pattern
matches the tail of the positive one, we did not verify if it
only matches the basename of the positive pattern. So e.g. we
would have also negated a pattern like

    foo/fruz_bar
    !bar

Furthermore, we did not check for the third case, where a
basename is being unignored in a certain subdirectory again.

Both issues are fixed with this commit.
2016-08-12 14:47:54 +02:00
David Turner
5625d86b99 index: support index v4
Support reading and writing index v4.  Index v4 uses a very simple
compression scheme for pathnames, but is otherwise similar to index v3.

Signed-off-by: David Turner <dturner@twitter.com>
2016-08-10 14:19:30 -04:00
David Turner
aeb5ee5ab5 varint: Add varint encoding/decoding
This code is ported from git.git

Signed-off-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: David Turner <dturner@twopensource.com>
2016-08-10 14:19:06 -04:00
Patrick Steinhardt
b989514405 stransport: do not use git_stream_free on uninitialized stransport
When failing to initialize a new stransport stream, we try to
release already allocated memory by calling out to
`git_stream_free`, which in turn called out to the stream's
`free` function pointer. As we only initialize the function
pointer later on, this leads to a `NULL` pointer exception.

Furthermore, plug another memory leak when failing to create the
SSL context.
2016-08-09 08:38:54 +02:00
Carlos Martín Nieto
97e57e8770 Merge pull request #3887 from libgit2/ethomson/empty_blob
odb: only provide the empty tree
2016-08-08 15:13:59 +02:00
Edward Thomson
b47e79e2cd Merge pull request #3890 from pks-t/pks/stransport-static-linkage
stransport: make internal functions static
2016-08-08 08:42:32 -04:00
Patrick Steinhardt
067bf5dcc5 stransport: make internal functions static 2016-08-08 13:49:17 +02:00
Edward Thomson
becadafca8 odb: only provide the empty tree
Only provide the empty tree internally, which matches git's behavior.
If we provide the empty blob then any users trying to write it with
libgit2 would omit it from actually landing in the odb, which appear
to git proper as a broken repository (missing that object).
2016-08-05 19:30:56 -04:00
Carlos Martín Nieto
9884dd613e SecureTransport: handle NULL trust on success
The `SSLCopyPeerTrust` call can succeed but fail to return a trust
object if it can't load the certificate chain and thus cannot check the
validity of a certificate. This can lead to us calling `CFRelease` on a
`NULL` trust object, causing a crash.

Handle this by returning ECERTIFICATE.
2016-08-05 18:40:37 +02:00