Commit Graph

5935 Commits

Author SHA1 Message Date
Patrick Steinhardt
32f0798413 diff_tform: fix potential NULL pointer access
The `normalize_find_opts` function in theory allows for the
incoming diff to have no repository. When the caller does not
pass in diff find options or if the GIT_DIFF_FIND_BY_CONFIG value
is set, though, we try to derive the configuration from the
diff's repository configuration without first verifying that the
repository is actually set to a non-NULL value.

Fix this issue by explicitly checking if the repository is set
and if it is not, fall back to a default value of
GIT_DIFF_FIND_RENAMES.
2016-02-23 12:07:37 +01:00
Patrick Steinhardt
3d1abc5afc xmerge: fix memory leak on error path 2016-02-23 12:07:37 +01:00
Patrick Steinhardt
05bf67b901 openssl_stream: fix NULL pointer dereference 2016-02-23 12:07:37 +01:00
Patrick Steinhardt
2baf854e97 openssl_stream: fix memory leak when creating new stream 2016-02-23 12:07:36 +01:00
Patrick Steinhardt
2afb6fa46d rebase: plug memory leak in rebase_alloc
Convert `rebase_alloc` to use our usual error propagation
patterns, that is accept an out-parameter and return an error
code that is to be checked by the caller. This allows us to use
the GITERR_CHECK_ALLOC macro, which helps static analysis.
2016-02-23 12:07:36 +01:00
Patrick Steinhardt
d0cb11e794 remote: set error code in create_internal
Set the error code when an error occurs in any of the called
functions. This ensures we pass the error up to callers and
actually free the remote when an error occurs.
2016-02-23 12:07:36 +01:00
Patrick Steinhardt
0f1e2d2066 index: fix contradicting comparison
The overflow check in `read_reuc` tries to verify if the
`git__strtol32` parses an integer bigger than UINT_MAX. The `tmp`
variable is casted to an unsigned int for this and then checked
for being greater than UINT_MAX, which obviously can never be
true.

Fix this by instead fixing the `mode` field's size in `struct
git_index_reuc_entry` to `uint32_t`. We can now parse the int
with `git__strtol64`, which can never return a value bigger than
`UINT32_MAX`, and additionally checking if the returned value is
smaller than zero.

We do not need to handle overflows explicitly here, as
`git__strtol64` returns an error when the returned value would
overflow.
2016-02-23 12:07:14 +01:00
Patrick Steinhardt
7808c93797 index: plug memory leak in read_conflict_names 2016-02-23 11:50:23 +01:00
Patrick Steinhardt
003c5e46a8 transports: smart_pkt: fix memory leaks on error paths 2016-02-23 11:50:23 +01:00
Patrick Steinhardt
793e085536 refdb_fs: remove unnecessary check for NULL
The fail-label of `reflog_parse` explicitly checks the entry
poitner for NULL before freeing it. When we jump to the label the
variable has to be set to a non-NULL and valid pointer though: if
the allocation fails we immediately return with an error code and
if the loop was not entered we return with a success code,
withouth executing the label's code.

Remove the useless NULL-check to silence Coverity.
2016-02-23 11:50:23 +01:00
Patrick Steinhardt
be8479c987 diff_print: assert patch is non-NULL
When invoking `diff_print_info_init_frompatch` it is obvious that
the patch should be non-NULL. We explicitly check if the variable
is set and continue afterwards, happily dereferencing the
potential NULL-pointer.

Fix this by instead asserting that patch is set. This also
silences Coverity.
2016-02-23 11:50:23 +01:00
Patrick Steinhardt
bac52ab0f2 pack-objects: return early when computing write order fails
The function `compute_write_order` may return a `NULL`-pointer
when an error occurs. In such cases we jump to the `done`-label
where we try to clean up allocated memory. Unfortunately we try
to deallocate the `write_order` array, though, which may be NULL
here.

Fix this error by returning early instead of jumping to the
`done` label. There is no data to be cleaned up anyway.
2016-02-23 11:50:23 +01:00
Patrick Steinhardt
d1c9a48df6 pack-objects: check realloc in try_delta with GITERR_CHECK_ALLOC 2016-02-23 11:50:23 +01:00
Patrick Steinhardt
2129d6df93 crlf: do not ignore GIT_PASSTHROUGH error
When no payload is set for `crlf_apply` we try to compute the
crlf attributes ourselves with `crlf_check`. When the function
determines that the current file does not require any treatment
we return the GIT_PASSTHROUGH error code without actually
allocating the out-pointer, which indicates the file should not
be passed through the filter.

The `crlf_apply` function explicitly checks for the
GIT_PASSTHROUGH return code and ignores it. This means we will
try to apply the crlf-filter to the current file, leading us to
dereference the unallocated payload-pointer.

Fix this obviously incorrect behavior by not treating
GIT_PASSTHROUGH in any special way. This is the correct thing to
do anyway, as the code indicates that the file should not be
passed through the filter.
2016-02-23 11:50:23 +01:00
Patrick Steinhardt
b9f28b8d52 refspec: check buffer with GITERR_CHECK_ALLOC_BUF 2016-02-23 11:50:23 +01:00
Patrick Steinhardt
c5bd70d138 revwalk: use GITERR_CHECK_ALLOC_BUF 2016-02-23 11:50:23 +01:00
Patrick Steinhardt
6e2a37556d smart_pkt: check buffer with GITERR_CHECK_ALLOC_BUF 2016-02-23 11:50:23 +01:00
Patrick Steinhardt
42c05ed56b path: use GITERR_CHECK_ALLOC_BUF to verify passed in buffer 2016-02-23 11:50:23 +01:00
Patrick Steinhardt
859ed5ddc7 common: introduce GITERR_CHECK_ALLOC_BUF
We commonly have to check if a git_buf has been allocated
correctly or if we ran out of memory. Introduce a new macro
similar to `GITERR_CHECK_ALLOC` which checks if we ran OOM and if
so returns an error. Provide a `#nodef` for Coverity to mark the
error case as an abort path.
2016-02-23 11:50:23 +01:00
Edward Thomson
7bab2e8fbf git_libgit2_opts: validate key 2016-02-22 23:07:30 -05:00
Carlos Martín Nieto
c8fe6c0975 openssl: re-export the last-resort locking function
We need to include the header where we define the function. Otherwise it
won't be available on the DLL.
2016-02-19 16:23:14 +01:00
Ross Delinger
f1260e03d9 Remove unnecessary ifdef in pool.h 2016-02-19 09:13:40 -05:00
Carlos Martín Nieto
deecaa2ece openssl: free the context even if we don't connect 2016-02-19 13:34:52 +01:00
Carlos Martín Nieto
bf127eec4a global: remove an unused variable 2016-02-19 13:24:41 +01:00
Carlos Martín Nieto
78e16c3442 Merge pull request #3597 from ethomson/filter_registration
Filter registration
2016-02-19 13:06:51 +01:00
Patrick Steinhardt
8a62bf1180 netops: fix memory leak when an error occurs 2016-02-18 20:50:33 +01:00
Patrick Steinhardt
b0f7512f40 transports: smart_pkt: fix memory leaks 2016-02-18 20:50:33 +01:00
Patrick Steinhardt
704554cdf0 transports: smart: fix memory leak on OOM path 2016-02-18 20:50:33 +01:00
Patrick Steinhardt
038d7af085 signature: use GITERR_CHECK_ALLOC to check for OOM situation
When checking for out of memory situations we usually use the
GITERR_CHECK_ALLOC macro. Besides conforming to our current code
base it adds the benefit of silencing errors in Coverity due to
Coverity handling the macro's error path as abort.
2016-02-18 20:50:33 +01:00
Carlos Martín Nieto
c1b75f05ad Merge pull request #3604 from ethomson/nsec_xplat
Handle `USE_NSECS`
2016-02-18 15:11:31 +01:00
Carlos Martín Nieto
b85d0afd6e Merge pull request #3606 from ethomson/drop_xp
win32: drop xp support in WideCharToMultiByte
2016-02-18 15:11:02 +01:00
Carlos Martín Nieto
5663d4f691 Merge pull request #3613 from ethomson/fixups
Remove most of the silly warnings
2016-02-18 12:31:56 +01:00
Carlos Martín Nieto
594a5d12d4 Merge pull request #3619 from ethomson/win32_forbidden
win32: allow us to read indexes with forbidden paths on win32
2016-02-18 12:28:06 +01:00
Edward Thomson
318b825e76 index: allow read of index w/ illegal entries
Allow `git_index_read` to handle reading existing indexes with
illegal entries.  Allow the low-level `git_index_add` to add
properly formed `git_index_entry`s even if they contain paths
that would be illegal for the current filesystem (eg, `AUX`).
Continue to disallow `git_index_add_bypath` from adding entries
that are illegal universally illegal (eg, `.git`, `foo/../bar`).
2016-02-17 13:10:33 +00:00
Edward Thomson
4fea9cffbd iterator: assert tree_iterator has a frame
Although a `tree_iterator` that failed to be properly created
does not have a frame, all other `tree_iterator`s should.  Do not
call `pop` in the failure case, but assert that in all other
cases there is a frame.
2016-02-17 13:10:33 +00:00
Colin Xu
a218b2f625 Validate pointer before access the member.
When Git repository at network locations, sometimes git_iterator_for_tree
fails at iterator__update_ignore_case so it goes to git_iterator_free.
Null pointer will crash the process if not check.

Signed-off-by: Colin Xu <colin.xu@gmail.com>
2016-02-17 13:10:33 +00:00
Carlos Martín Nieto
eadd0f05f6 commit: expose the different kinds of errors
We should be checking whether the object we're looking up is a commit,
and we should let the caller know whether the not-found return code
comes from a bad object type or just a missing signature.
2016-02-16 14:06:48 +01:00
Edward Thomson
9ce0399c4d winhttp: use an unsigned iterator 2016-02-16 11:50:49 +00:00
Edward Thomson
3b2fa0fb36 submodule: explicitly cast to the teensy time value 2016-02-16 11:50:48 +00:00
Edward Thomson
b2ca8d9c29 index: explicitly cast the teeny index entry members 2016-02-16 11:50:47 +00:00
Edward Thomson
997e030154 index: don't use seek return as an error code 2016-02-16 11:50:47 +00:00
Edward Thomson
9a634cba85 index: explicitly cast new hash size to an int 2016-02-16 11:50:46 +00:00
Edward Thomson
c4d23928c3 fstat: use our custom stat 2016-02-16 11:50:45 +00:00
Edward Thomson
aadad40592 tree: zap warnings around size_t vs uint16_t 2016-02-16 11:50:44 +00:00
Edward Thomson
f28bae0c38 rebase: persist a single in-memory index
When performing an in-memory rebase, keep a single index for the
duration, so that callers have the expected index lifecycle and
do not hold on to an index that is free'd out from under them.
2016-02-15 19:27:06 +00:00
Edward Thomson
35439f5997 win32: introduce p_timeval that isn't stupid
Windows defines `timeval` with `long`, which we cannot
sanely cope with.  Instead, use a custom timeval struct.
2016-02-12 10:34:15 -08:00
Carlos Martín Nieto
5a296ad07e Merge pull request #3610 from ethomson/rebase_bare
rebase: introduce bare rebasing
2016-02-12 00:55:20 +01:00
Arthur Schreiber
3679ebaef5 Horrible fix for #3173. 2016-02-11 23:41:34 +01:00
Carlos Martín Nieto
460ae11f0a commit: don't forget the last header field
When we moved the logic to handle the first one, wrong loop logic was
kept in place which meant we still finished early. But we now notice it
because we're not reading past the last LF we find.

This was not noticed before as the last field in the tested commit was
multi-line which does not trigger the early break.
2016-02-11 22:19:20 +01:00
Edward Thomson
a202e0d45b rebase: allow custom merge_options
Allow callers of rebase to specify custom merge options.  This may
allow custom conflict resolution, or failing fast when conflicts
are detected.
2016-02-11 10:49:25 -08:00
Edward Thomson
ee6673070a rebase: introduce inmemory rebasing
Introduce the ability to rebase in-memory or in a bare repository.

When `rebase_options.inmemory` is specified, the resultant `git_rebase`
session will not be persisted to disk.  Callers may still analyze
the rebase operations, resolve any conflicts against the in-memory
index and create the commits.  Neither `HEAD` nor the working
directory will be updated during this process.
2016-02-11 10:48:48 -08:00
Edward Thomson
494e61b8a3 win32: drop xp support in WideCharToMultiByte 2016-02-09 21:45:24 -08:00
Edward Thomson
9447b9e55a xplat: use st_mtimespec everywhere on mac 2016-02-09 10:40:33 -08:00
Vicent Marti
488e2b8505 Merge pull request #3599 from libgit2/gpgsign
Introduce git_commit_extract_signature
2016-02-09 16:26:58 +01:00
Carlos Martín Nieto
534cc5a3cb Merge pull request #3603 from pks-t/pks/coverity-fixes
Coverity fixes
2016-02-09 16:10:43 +01:00
Carlos Martín Nieto
a65afb757e Introduce git_commit_extract_signature
This returns the GPG signature for a commit and its contents without the
signature block, allowing for the verification of the commit's
signature.
2016-02-09 15:58:16 +01:00
Carlos Martín Nieto
ab87cb1818 Merge pull request #3602 from libgit2/cmn/header-field-2
commit: also match the first header field when searching
2016-02-09 14:53:10 +01:00
Patrick Steinhardt
24b8ed2b3a attr_file: fix resource leak 2016-02-09 11:11:38 +01:00
Patrick Steinhardt
e262545753 checkout: fix resource leak 2016-02-09 11:09:41 +01:00
Patrick Steinhardt
39c9dd24d3 pack-objects: fix memory leak in packbuilder_config 2016-02-09 10:53:30 +01:00
Patrick Steinhardt
0b2437bb68 pack-objects: fix memory leak in compute_write_order 2016-02-09 10:43:28 +01:00
Patrick Steinhardt
a53d2e3985 pack: do not free passed in poiter on error
The function `git_packfile_stream_open` tries to free the passed
in stream when an error occurs. The only call site is
`git_indexer_append`, though, which passes in the address of a
stream struct which has not been allocated on the heap.

Fix the issue by simply removing the call to free. In case of an
error we did not allocate any memory yet and otherwise it should
be the caller's responsibility to manage it's object's lifetime.
2016-02-09 09:58:56 +01:00
Carlos Martín Nieto
f55eca167c commit: also match the first header field when searching
We were searching only past the first header field, which meant we were
unable to find e.g. `tree` which is the first field.

While here, make sure to set an error message in case we cannot find the
field.
2016-02-09 07:17:26 +01:00
Edward Thomson
2ed855a9e8 filter: avoid races during filter registration
Previously we would set the global filter registry structure before
adding filters to the structure, without a lock, which is quite racy.
Now, register default filters during global registration and use an
rwlock to read and write the filter registry (as appopriate).
2016-02-08 16:31:42 -08:00
Edward Thomson
6e0fc1a631 mingw: use gcc-like memory barrier
Use the gcc-like memory barrier (__sync_synchronize) on mingw.
2016-02-08 16:30:41 -08:00
Edward Thomson
8a6d667763 global: make openssl registration like the rest 2016-02-08 16:30:39 -08:00
Edward Thomson
bad2702c43 global: refactor setup and cleanup
Move the common initialization and cleanup methods to reduce
unnecessary duplication.
2016-02-08 15:39:26 -08:00
Patrick Steinhardt
a001846b25 curl_stream: fix unused cert infos
When copying contents of the cURL certiinfo we duplicate the
data but forget to actually put it into the vector.
2016-02-08 17:05:57 +01:00
Patrick Steinhardt
fac42ff942 merge: fix memory leak 2016-02-08 16:58:08 +01:00
Carlos Martín Nieto
240b6fed00 Merge pull request #3578 from bubaflub/fix_small_memory_leak
Free allocated pointer to curl stream on error
2016-02-05 15:19:24 -08:00
Marius Ungureanu
0c09753cf5 Fix the build when defining USE_NSEC 2016-01-25 14:06:15 +02:00
Edward Thomson
5c7f2f0188 winhttp: name mangle class / iid on mingw
Standard Windows type systems define CLSID_InternetSecurityManager
and IID_IInternetSecurityManager, but MinGW lacks these definitions.
As a result, we must hardcode these definitions ourselves.  However,
we should not use a public struct with those names, lest another
library do the same thing and consumers cannot link to both.
2016-01-19 11:13:23 -06:00
Bob Kuo
8bd1c19e76 Free allocated pointer to curl stream on error 2016-01-16 19:39:24 -06:00
P.S.V.R
d4e4f27204 Remove duplicated calls to git_mwindow_close 2016-01-13 11:07:14 +08:00
P.S.V.R
b644e223aa Make packfile_unpack_compressed a private API 2016-01-13 11:02:38 +08:00
Ross Delinger
ed0571f895 Add a new build flag to disable the pool allocator and pass all git_pool_malloc calls straight to git__malloc 2016-01-12 16:08:38 -05:00
Chris Hescock
a7d9d93dad Buffer sideband packet data
The inner packet may be split across multiple sideband packets.
2016-01-12 10:08:58 -05:00
Yong Li
b3eb2cde2b Avoid subtraction overflow in git_indexer_commit 2016-01-04 10:47:00 -05:00
Sebastian Bauer
9f9df4b6e0 Copy into the correct destination. 2015-12-31 14:52:32 +01:00
Sebastian Bauer
ea5942b4cf Bail out early when no memory is available. 2015-12-31 14:52:24 +01:00
Carlos Martín Nieto
700f0aff24 Merge pull request #3562 from mgorny/ssh-read-stderr-fail
ssh_stream_read(): fix possible *bytes_read < 0 branch
2015-12-29 13:38:01 +00:00
Chris Bargren
813d73f64d Tabs 2015-12-28 11:45:12 -07:00
Chris Bargren
4df17045c1 Removing #define for SSH_PREFIX_COUNT and using ARRAY_SIZE instead
Also moving var declarations to top of blocks to support bad old compilers
2015-12-28 11:45:00 -07:00
Carlos Martín Nieto
a3776489e6 Merge pull request #3558 from libgit2/cmn/index-nolock
index: get rid of the locking
2015-12-28 15:12:37 +00:00
Carlos Martín Nieto
9d81509ab1 index: get rid of the locking
We don't support using an index object from multiple threads at the same
time, so the locking doesn't have any effect when following the
rules. If not following the rules, things are going to break down
anyway.
2015-12-28 13:55:44 +00:00
Edward Thomson
62602547db git_repository_init: include dotfiles when copying templates
Include dotfiles when copying template directory, which will handle
both a template directory itself that begins with a dotfile, and
any dotfiles inside the directory.
2015-12-26 22:41:00 -06:00
Edward Thomson
869320a85d Merge pull request #3546 from Cruel/master
Fix a couple function signatures
2015-12-26 16:55:29 -06:00
Michał Górny
02fdc2db22 ssh_stream_read(): fix possible *bytes_read < 0 branch
Fix the possibility of returning successfully from ssh_stream_read()
with *bytes_read < 0. This would occur if stdout channel read resulted
in 0, and stderr channel read failed afterwards.
2015-12-26 17:17:05 +01:00
Chris Bargren
ed21fd745c Handle git+ssh:// and ssh+git:// protocols support 2015-12-22 10:38:31 -07:00
Dmitriy Olshevskiy
91f0d186b4 typos in comments 2015-12-21 22:18:07 +03:00
Vicent Marti
ef8b7febc5 index: Also size-hint the hash table
Note that we're not checking whether the resize succeeds; in OOM cases,
we let it run with a "small" vector and hash table and see if by chance
we can grow it dynamically as we insert the new entries. Nothing to
lose really.
2015-12-16 19:36:50 +01:00
Vicent Marti
d7d46cfbfd index: Preallocate the entries vector with size hint 2015-12-16 17:04:08 +01:00
Vicent Marti
0cc20a8c48 index: Adjust namemask & mode when filling 2015-12-16 17:04:08 +01:00
Vicent Marti
879ebab314 merge: Use git_index__fill to populate the index
Instead of calling `git_index_add` in a loop, use the new
`git_index_fill` internal API to fill the index with the initial staged
entries.

The new `fill` helper assumes that all the entries will be unique and
valid, so it can append them at the end of the entries vector and only
sort it once at the end. It performs no validation checks.

This prevents the quadratic behavior caused by having to sort the
entries list once after every insertion.
2015-12-16 12:30:52 +01:00
Thomas Edvalson
95746a57c7 Fix a couple function signatures 2015-12-14 19:21:09 -05:00
Edward Thomson
7f2c1469f8 Merge pull request #3528 from chescock/Passthrough-from-credential-callback
Treat GIT_PASSTHROUGH as though git_cred_acquire_cb isn't set.
2015-12-14 13:54:02 -06:00
Edward Thomson
30c8e26074 Merge pull request #3521 from pks-t/blame-line-overflow
Line count overflow in git_blame_hunk and git_blame__entry
2015-12-14 13:53:26 -06:00
Carlos Martín Nieto
6aa06b65cf Merge pull request #3522 from pks-t/email-format-commit-message
diff: include commit message when formatting patch
2015-12-10 12:14:09 +01:00
Carlos Martín Nieto
dc49eb585f Merge pull request #3538 from pks-t/pks/index-memory-leak
index: always queue `remove_entry` for removal
2015-12-10 11:57:44 +01:00
Carlos Martín Nieto
465c3b38d5 reset: perform the checkout before moving HEAD or the index
This keeps the state of the workdir the same as one from HEAD, removing
a source of possible confusion when calculating the work that is to be
done.
2015-12-09 19:16:11 +01:00
Carlos Martín Nieto
21b1e015a3 Merge pull request #3539 from libgit2/typedef-submodule-cb
Use a typedef for the submodule_foreach callback.
2015-12-08 21:11:58 +01:00
joshaber
eda726cfb5 Use a typedef for the submodule_foreach callback.
This fits with the style for the rest of the project, but more
importantly, makes life easier for bindings authors who auto-generate
code.
2015-12-08 11:34:00 -05:00
Patrick Steinhardt
b057fdef69 index: always queue remove_entry for removal
When replacing an index with a new one, we need to iterate
through all index entries in order to determine which entries are
equal. When it is not possible to re-use old entries for the new
index, we move it into a list of entries that are to be removed
and thus free'd.

When we encounter a non-zero error code, though, we skip adding
the current index entry to the remove-queue. `INSERT_MAP_EX`,
which is the function last run before adding to the remove-queue,
may return a positive non-zero code that indicates what exactly
happened while inserting the element. In this case we skip adding
the entry to the remove-queue but still continue the current
operation, leading to a leak of the current entry.

Fix this by checking for a negative return value instead of a
non-zero one when we want to add the current index entry to the
remove-queue.
2015-12-08 16:29:08 +01:00
Carlos Martín Nieto
fc43646965 tree: mark a tree as already sorted
The trees are sorted on-disk, so we don't have to go over them
again. This cuts almost a fifth of time spent parsing trees.
2015-12-06 23:17:19 +01:00
Edward Thomson
5d1f31c6e6 Merge pull request #3530 from libgit2/cmn/parse-mode
tree: use a specialised mode parse function
2015-12-03 17:42:52 -05:00
Edward Thomson
626f9e243e index: canonicalize inserted paths safely
When adding to the index, we look to see if a portion of the given
path matches a portion of a path in the index.  If so, we will use
the existing path information.  For example, when adding `foo/bar.c`,
if there is an index entry to `FOO/other` and the filesystem is case
insensitive, then we will put `bar.c` into the existing tree instead
of creating a new one with a different case.

Use `strncmp` to do that instead of `memcmp`.  When we `bsearch`
into the index, we locate the position where the new entry would
go.  The index entry at that position does not necessarily have
a relation to the entry we're adding, so we cannot make assumptions
and use `memcmp`.  Instead, compare them as strings.

When canonicalizing paths, we look for the first index entry that
matches a given substring.
2015-12-03 16:27:15 -05:00
Carlos Martín Nieto
0174f21b0a tree: use a specialised mode parse function
Instead of going out to strtol, which is made to parse generic numbers,
copy a parse function from git which is specialised for file modes.
2015-12-02 18:59:58 +01:00
Chris Hescock
efd9ab568b Treat GIT_PASSTHROUGH as though git_cred_acquire_cb isn't set. 2015-12-01 10:54:20 -05:00
Patrick Steinhardt
9487585ddc tree: mark cloned tree entries as un-pooled
When duplicating a `struct git_tree_entry` with
`git_tree_entry_dup` the resulting structure is not allocated
inside a memory pool. As we do a 1:1 copy of the original struct,
though, we also copy the `pooled` field, which is set to `true`
for pooled entries. This results in a huge memory leak as we
never free tree entries that were duplicated from a pooled
tree entry.

Fix this by marking the newly duplicated entry as un-pooled.
2015-12-01 14:25:15 +01:00
Patrick Steinhardt
254e0a33ee diff: include commit message when formatting patch
When formatting a patch as email we do not include the commit's
message in the formatted patch output. Implement this and add a
test that verifies behavior.
2015-12-01 10:12:53 +01:00
Patrick Steinhardt
7f8fe1d45e commit: introduce git_commit_body
It is already possible to get a commit's summary with the
`git_commit_summary` function. It is not possible to get the
remaining part of the commit message, that is the commit
message's body.

Fix this by introducing a new function `git_commit_body`.
2015-12-01 10:07:00 +01:00
Patrick Steinhardt
944dbd1259 blame: use size_t for line counts in git_blame__entry
The `git_blame__entry` struct keeps track of line counts with
`int` fields. Since `int` is only guaranteed to be at least 16
bits we may overflow on certain platforms when line counts exceed
2^15.

Fix this by instead storing line counts in `size_t`.
2015-12-01 09:02:47 +01:00
Patrick Steinhardt
cb1cb24ca9 blame: use size_t for line counts in git_blame_hunk
It is not unreasonable to have versioned files with a line count
exceeding 2^16. Upon blaming such files we fail to correctly keep
track of the lines as `git_blame_hunk` stores them in `uint16_t`
fields.

Fix this by converting the line fields of `git_blame_hunk` to
`size_t`. Add test to verify behavior.
2015-12-01 09:02:47 +01:00
Edward Thomson
337b2b08f4 Merge pull request #3508 from libgit2/cmn/tree-parse-speed
Improvements to tree parsing speed
2015-11-30 20:53:54 -05:00
Patrick Steinhardt
bbd2fa4e70 object: remove unused constant OBJECT_BASE_SIZE 2015-11-30 18:05:27 +01:00
Carlos Martín Nieto
95ae3520c5 tree: ensure the entry filename fits in 16 bits
Return an error in case the length is too big. Also take this
opportunity to have a single allocating function for the size and
overflow logic.
2015-11-30 17:32:18 +01:00
Carlos Martín Nieto
a27f31d8f5 Merge pull request #3513 from ethomson/merge_recursive
Recursive Merge
2015-11-30 04:49:31 +01:00
Carlos Martín Nieto
ee42bb0e3d tree: make path len uint16_t and avoid holes
This reduces the size of the struct from 32 to 26 bytes, and leaves a
single padding byte at the end of the struct (which comes from the
zero-length array).
2015-11-28 19:21:52 +01:00
Carlos Martín Nieto
2580077fc2 tree: calculate the filename length once
We already know the size due to the `memchr()` so use that information
instead of calling `strlen()` on it.
2015-11-28 19:21:52 +01:00
Carlos Martín Nieto
ed970748b6 tree: pool the entry memory allocations
These are rather small allocations, so we end up spending a non-trivial
amount of time asking the OS for memory. Since these entries are tied to
the lifetime of their tree, we can give the tree a pool so we speed up
the allocations.
2015-11-28 19:21:51 +01:00
Carlos Martín Nieto
7132150ddf tree: avoid advancing over the filename multiple times
We've already looked at the filename with `memchr()` and then used
`strlen()` to allocate the entry. We already know how much we have to
advance to get to the object id, so add the filename length instead of
looking at each byte again.
2015-11-28 19:21:51 +01:00
Edward Thomson
5b9c63c3f6 recursive merge: add a recursion limit 2015-11-25 16:25:47 -05:00
Edward Thomson
78859c6344 merge: handle conflicts in recursive base building
When building a recursive merge base, allow conflicts to occur.
Use the file (with conflict markers) as the common ancestor.

The user has already seen and dealt with this conflict by virtue
of having a criss-cross merge.  If they resolved this conflict
identically in both branches, then there will be no conflict in the
result.  This is the best case scenario.

If they did not resolve the conflict identically in the two branches,
then we will generate a new conflict.  If the user is simply using
standard conflict output then the results will be fairly sensible.
But if the user is using a mergetool or using diff3 output, then the
common ancestor will be a conflict file (itself with diff3 output,
haha!).  This is quite terrible, but it matches git's behavior.
2015-11-25 15:38:39 -05:00
Edward Thomson
76ade3a0b8 merge: use annotated commits for recursion
Use annotated commits to act as our virtual bases, instead of regular
commits, to avoid polluting the odb with virtual base commits and
trees.  Instead, build an annotated commit with an index and pointers
to the commits that it was merged from.
2015-11-25 15:38:16 -05:00
Edward Thomson
7730fe8e9c merge: merge annotated commits instead of regular commits 2015-11-25 15:38:03 -05:00
Edward Thomson
3f2bb387a4 merge: octopus merge common ancestors when >2
When there are more than two common ancestors, continue merging the
virtual base with the additional common ancestors, effectively
octopus merging a new virtual base.
2015-11-25 15:37:57 -05:00
Edward Thomson
1b82f7b6a2 merge: compute octopus merge bases 2015-11-25 15:37:45 -05:00
Edward Thomson
75dee59c94 merge: build virtual base of multiple merge bases
When the commits to merge have multiple common ancestors, build a
"virtual" base tree by merging the common ancestors.
2015-11-25 15:37:17 -05:00
Edward Thomson
fa78782f67 merge: rename git_merge_tree_flags_t -> git_merge_flags_t 2015-11-25 15:37:05 -05:00
Edward Thomson
25e84f959a checkout: only consider nsecs when built that way
When examining the working directory and determining whether it's
up-to-date, only consider the nanoseconds in the index entry when
built with `GIT_USE_NSEC`.  This prevents us from believing that
the working directory is always dirty when the index was originally
written with a git client that uinderstands nsecs (like git 2.x).
2015-11-23 15:49:54 -05:00
Edward Thomson
66e4e6da59 Merge pull request #3515 from jacquesg/unsigned-signed
Fix <0 unsigned comparison (stat.st_size should be an off_t)
2015-11-21 11:26:18 -05:00
Jacques Germishuys
e78e8fae5c Make stat.st_size a __int64 not a uint64_t 2015-11-21 14:41:15 +02:00
Edward Thomson
7a612b53cf Merge pull request #3514 from jacquesg/stat-fixes
Stat fixes
2015-11-20 17:52:00 -05:00
Jacques Germishuys
eb11fac629 Detect stat's structure 2015-11-20 21:05:38 +02:00
Carlos Martín Nieto
2ea40fdaac repository: distinguish sequencer cherry-pick and revert
These are not quite like their plain counterparts and require special handling.
2015-11-20 13:19:23 -05:00
Carlos Martín Nieto
69d1494873 Merge pull request #3511 from ethomson/racy_fixes_2
Racy fixes for writing new indexes
2015-11-17 13:21:18 -05:00
Edward Thomson
3eac1037d6 settings: allow users to set PROGRAMDATA
Allow users to set the `git_libgit2_opts` search path for the
`GIT_CONFIG_LEVEL_PROGRAMDATA`.  Convert `GIT_CONFIG_LEVEL_PROGRAMDATA`
to `GIT_SYSDIR_PROGRAMDATA` for setting the configuration.
2015-11-16 23:31:19 -05:00
Edward Thomson
5f32c50683 racy: make git_index_read_index handle raciness
Ensure that `git_index_read_index` clears the uptodate bit on
files that it modifies.

Further, do not propagate the cache from an on-disk index into
another on-disk index.  Although this should not be done, as
`git_index_read_index` is used to bring an in-memory index into
another index (that may or may not be on-disk), ensure that we do
not accidentally bring in these bits when misused.
2015-11-16 22:59:02 -05:00
Edward Thomson
27bc41cf17 index: clear uptodate bit on save
The uptodate bit should have a lifecycle of a single read->write
on the index.  Once the index is written, the files within it should
be scanned for racy timestamps against the new index timestamp.
2015-11-16 22:59:01 -05:00
Edward Thomson
d1101263f7 index: don't detect raciness in uptodate entries
Keep track of entries that we believe are up-to-date, because we
added the index entries since the index was loaded.  This prevents
us from unnecessarily examining files that we wrote during the
cleanup of racy entries (when we smudge racily clean files that have
a timestamp newer than or equal to the index's timestamp when we
read it).  Without keeping track of this, we would examine every
file that we just checked out for raciness, since all their timestamps
would be newer than the index's timestamp.
2015-11-16 22:58:58 -05:00
Edward Thomson
cb0ff012d3 racy-git: do a single index->workdir diff
When examining paths that are racily clean, do a single index->workdir
diff over the entirety of the racily clean files, instead of a diff
per file.
2015-11-16 22:58:57 -05:00
Vicent Marti
7ff7ca623e pool: Never return unaligned buffers 2015-11-13 04:57:19 +01:00
Carlos Martín Nieto
75a0ccf52f Merge pull request #3170 from CmdrMoozy/nsec_fix
git_index_entry__init_from_stat: set nsec fields in entry stats
2015-11-12 19:53:09 +01:00
Carlos Martín Nieto
2c26c8679f Merge pull request #3499 from ethomson/ref_dir_errmsgs
Improve error messages when dirs prevent ref/reflog creation
2015-11-12 19:22:31 +01:00
Carlos Martín Nieto
ecdc04287a Merge pull request #3448 from libgit2/cmn/custom-agent
Support setting custom user-agent
2015-11-12 19:20:36 +01:00
Carlos Martín Nieto
1411cb9eb5 winhttp: use a custom user-agent if the user has set it
We also keep the "git/1.0" prefix in order to maintain compatibility
with hosters.
2015-11-12 17:18:42 +01:00
Carlos Martín Nieto
94bac76c3f http: use a custom user-agent if the user has set it
We still prefix it with "git/1.0" since that's required in many
situations, but we replace the area which mentions libgit2.
2015-11-12 17:18:42 +01:00
Carlos Martín Nieto
de870533e0 settings: add a setter for a custom user-agent 2015-11-12 17:18:42 +01:00
Edward Thomson
0a700ee368 reflog: error when a directory is at reflog path
When a non-empty directory exists and prevents the creation of a
reflog, provide a more informative error message.
2015-11-12 09:39:29 -05:00
Edward Thomson
b46c7ee5e2 refs: complain when a directory exists at ref
When a (non-empty) directory exists at the reference target
location, complain with a more actionable error message.
2015-11-12 09:35:51 -05:00
Carlos Martín Nieto
ad8509ef9f index: overwrite the path when inserting conflicts
When we insert a conflict in a case-insensitive index, accept the
new entry's path as the correct case instead of leaving the path we
already had.

This puts `git_index_conflict_add()` on the same level as
`git_index_add()` in this respect.
2015-11-12 12:11:45 +01:00
Carlos Martín Nieto
16604d7469 index: correctly report which conflict stage has a wrong filemode
When we're at offset 'i', we're dealing with the 'i+1' stage, since
conflicts start at 1.
2015-11-12 12:11:45 +01:00
Carlos Martín Nieto
1c34b717e0 Merge pull request #3498 from ethomson/windows_symlinks
Diff: Honor `core.symlinks=false` and fake symlinks
2015-11-08 05:10:18 +01:00
Carlos Martín Nieto
619488948b Merge pull request #3500 from ethomson/submodules_with_path
Handle submodules with paths in `git_submodule_update`
2015-11-08 04:54:55 +01:00
Edward Thomson
f4b0267122 submodule: reload HEAD/index after reading config
Reload the HEAD and index data for a submodule after reading the
configuration.  The configuration may specify a `path`, so we must
update HEAD and index data with that path in mind.
2015-11-04 16:53:41 -05:00
Edward Thomson
5aa28a8f2d Merge pull request #3465 from libgit2/cmn/tls-register
stream: allow registering a user-provided TLS constructor
2015-11-04 14:16:24 -05:00
Stjepan Rajko
f5f96a23ee Fix git_commit_summary to convert newlines to spaces even after
whitespace.  Collapse spaces around newlines for the summary.
2015-11-03 17:50:55 -05:00
Edward Thomson
ec50b23acc filebuf: detect directories in our way
When creating a filebuf, detect a directory that exists in our
target file location.  This prevents a failure later, when we try
to move the lock file to the destination.
2015-11-03 17:16:51 -05:00
Edward Thomson
6b0fc6abc1 diff: on win32, treat fake "symlinks" specially
On platforms that lack `core.symlinks`, we should not go looking for
symbolic links and `p_readlink` their target.  Instead, we should
examine the file's contents.
2015-11-03 12:06:49 -05:00
Carlos Martín Nieto
7fafde6325 stream: allow registering a user-provided TLS constructor
This allows the application to use their own TLS stream, regardless of
the capabilities of libgit2 itself.
2015-11-03 08:10:29 -08:00
Carlos Martín Nieto
d39f643a0a stream: accept NULL in the free function 2015-11-03 08:10:14 -08:00
Jason Haslam
3138ad9366 Add diff progress callback. 2015-11-02 16:33:58 -05:00
Edward Thomson
db1edf91e9 Merge pull request #3491 from libgit2/cmn/config-checksum
Use checksums to detect config file changes
2015-11-02 15:09:19 -05:00
Vicent Marti
1d0bed9de1 merge-base: Style 2015-11-02 13:47:04 +01:00
Vicent Marti
4cacf5b594 merge-base: Do not read parents from the root 2015-11-02 13:47:04 +01:00
Vicent Marti
136a71f4ee merge-base: Remove redundant merge bases 2015-11-02 13:47:04 +01:00
Carlos Martín Nieto
3547b122b5 filebuf: use an internal buffer
This reduces the chances of a crash in the thread tests. This shouldn't
affect general usage too much, since the main usage of these functions
are to read into an empty buffer.
2015-10-30 21:36:51 +01:00
Carlos Martín Nieto
eb5977991a filebuf: use a checksum to detect file changes
Instead of relying on the size and timestamp, which can hide changes
performed in the same second, hash the file content's when we care about
detecting changes.
2015-10-30 19:49:35 +01:00
Carlos Martín Nieto
d571a54e60 Merge pull request #3493 from ethomson/read_index
index: read_index must update hashes
2015-10-30 19:36:16 +01:00
Carlos Martín Nieto
e0be1d605f git: put NULL check at the top 2015-10-30 18:23:17 +01:00
Edward Thomson
0bf77e3283 index: read_index must update hashes 2015-10-30 13:07:51 -04:00
Carlos Martín Nieto
45d295e08c git: accept NULL as argument to its stream free 2015-10-30 17:51:50 +01:00
Carlos Martín Nieto
fd74bd0842 Merge pull request #3486 from srajko/reflog-segfault-fix
Fix segfault when reading reflog with extra newlines
2015-10-29 20:37:48 +01:00
Stjepan Rajko
335c9e2f45 Prevent segfault when parsing a reflog with oid parse error
Using calloc instead of malloc because the parse error will lead to an immediate free of committer (and its properties, which can segfault on free if undefined - test_refs_reflog_reflog__reading_a_reflog_with_invalid_format_returns_error segfaulted before the fix).

#3458
2015-10-29 11:15:37 -07:00
Edward Thomson
1b4449b40d pool: fix documentation 2015-10-28 10:53:03 -04:00
Vicent Marti
d845abe639 merge: Do not mallocz unecessary entries 2015-10-28 14:49:28 +01:00
Vicent Marti
340b15b71c pool: update comment 2015-10-28 14:31:09 +01:00
Vicent Marti
d3416dfe29 pool: Dot not assume mallocs are zeroed out 2015-10-28 10:50:25 +01:00
Vicent Marti
410efda80b pool: Take into account malloc overhead & pool page size 2015-10-28 10:28:43 +01:00
Vicent Marti
4f971852d5 repository: plug memory leak
cc @carlosmn
2015-10-28 10:15:24 +01:00
Vicent Marti
1e5e02b4f4 pool: Simplify implementation 2015-10-28 10:13:13 +01:00
Vicent Marti
7a02e93e02 merge: Plug memory leak 2015-10-27 22:44:26 +01:00
Vicent Marti
a1f5d691a2 merge: Implement GIT_MERGE_TREE_SKIP_REUC 2015-10-27 22:44:26 +01:00
Vicent Marti
d307a0134b reuc: Be smarter when inserting new REUC entries
Inserting new REUC entries can quickly become pathological given that
each insert unsorts the REUC vector, and both subsequent lookups *and*
insertions will require sorting it again before being successful.

To avoid this, we're switching to `git_vector_insert_sorted`: this keeps
the REUC vector constantly sorted and lets us use the `on_dup` callback
to skip an extra binary search on each insertion.
2015-10-27 22:44:13 +01:00
Carlos Martín Nieto
e324005e8b Merge pull request #3481 from ethomson/xdiff_include
xdiff: reference util.h in parent directory
2015-10-23 15:13:38 +02:00
Edward Thomson
8683d31f08 merge: add GIT_MERGE_TREE_FAIL_ON_CONFLICT
Provide a new merge option, GIT_MERGE_TREE_FAIL_ON_CONFLICT, which
will stop on the first conflict and fail the merge operation with
GIT_EMERGECONFLICT.
2015-10-22 14:55:17 -04:00
Carlos Martín Nieto
dc2cf3eb1a Merge pull request #3480 from ethomson/nsecs
Nanoseconds in the index: ignore for diffing
2015-10-22 18:35:43 +02:00
Edward Thomson
c7b336b084 xdiff: reference util.h in parent directory
Although CMake will correctly configure include directories for us,
some people may use their own build system, and we should reference
`util.h` based on where it actually lives.
2015-10-22 10:29:51 -04:00
Edward Thomson
7499eae98a diff: ignore nsecs when diffing
Although our index contains the literal time present in the index,
we do not read nanoseconds from disk, and thus we should not use
them in any comparisons, lest we always think our working directory
is dirty.

Guard this behind a `GIT_USE_NSECS` for future improvement.
2015-10-22 09:35:47 -04:00
Edward Thomson
44b1e3e390 Merge pull request #3475 from libgit2/cmn/programdata-config
config: add a ProgramData level
2015-10-21 13:43:22 -07:00
Carlos Martín Nieto
8c7c5fa585 config: add a ProgramData level
This is where portable git stores the global configuration which we can
use to adhere to it even though git isn't quite installed on the system.
2015-10-21 15:11:18 +02:00
Vicent Marti
128e94bbbb index: Remove unneeded consts 2015-10-21 12:04:53 +02:00
Vicent Marti
307c4a2b6d signature: Strip crud just like Git does 2015-10-21 11:58:44 +02:00
Edward Thomson
4280fabb9f Merge pull request #3466 from libgit2/cmn/quick-parse-64
revwalk: make commit list use 64 bits for time
2015-10-15 07:10:48 -07:00
Carlos Martín Nieto
8321596a49 Merge pull request #3444 from ethomson/add_preserves_conflict_mode
Preserve modes from a conflict in `git_index_insert`
2015-10-15 12:22:10 +02:00
Vicent Marti
a0a1b19ab0 odb: Prioritize alternate backends
For most real use cases, repositories with alternates use them as main
object storage. Checking the alternate for objects before the main
repository should result in measurable speedups.

Because of this, we're changing the sorting algorithm to prioritize
alternates *in cases where two backends have the same priority*. This
means that the pack backend for the alternate will be checked before the
pack backend for the main repository *but* both of them will be checked
before any loose backends.
2015-10-14 20:53:01 +02:00
Vicent Marti
43820f204e odb: Be smarter when refreshing backends
In the current implementation of ODB backends, each backend is tasked
with refreshing itself after a failed lookup. This is standard Git
behavior: we want to e.g. reload the packfiles on disk in case they have
changed and that's the reason we can't find the object we're looking
for.

This behavior, however, becomes pathological in repositories where
multiple alternates have been loaded. Given that each alternate counts
as a separate backend, a miss in the main repository (which can
potentially be very frequent in cases where object storage comes from
the alternate) will result in refreshing all its packfiles before we
move on to the alternate backend where the object will most likely be
found.

To fix this, the code in `odb.c` has been refactored as to perform the
refresh of all the backends externally, once we've verified that the
object is nowhere to be found.

If the refresh is successful, we then perform the lookup sequentially
through all the backends, skipping the ones that we know for sure
weren't refreshed (because they have no refresh API).

The on-disk pack backend has been adjusted accordingly: it no longer
performs refreshes internally.
2015-10-14 19:24:07 +02:00
Carlos Martín Nieto
5ffdea6f65 revwalk: make commit list use 64 bits for time
We moved the "main" parsing to use 64 bits for the timestamp, but the
quick parsing for the revwalk did not. This means that for large
timestamps we fail to parse the time and thus the walk.

Move this parser to use 64 bits as well.
2015-10-14 16:54:13 +02:00
Edward Thomson
ae195a71ae blame: guard xdiff calls for large files 2015-10-05 22:59:53 +02:00
Edward Thomson
6c014bcc54 diff: don't feed large files to xdiff 2015-10-05 22:59:50 +02:00