Commit Graph

84 Commits

Author SHA1 Message Date
Etienne Samson
49be45a189 pack: report revwalk error 2017-01-13 21:48:20 +01: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
Edward Thomson
60e15ecd55 packbuilder: size_t all the things
After 1cd65991, we were passing a pointer to an `unsigned long` to
a function that now expected a pointer to a `size_t`.  These types
differ on 64-bit Windows, which means that we trash the stack.

Use `size_t`s in the packbuilder to avoid this.
2016-07-24 15:49:19 -04:00
Edward Thomson
20302aa437 Merge pull request #3223 from ethomson/apply
Reading patch files
2016-06-25 23:33:05 -04:00
Patrick Steinhardt
faebc1c6ec threads: split up OS-dependent thread code 2016-06-20 19:32:59 +02:00
Edward Thomson
a03952f095 patch: formatting cleanups 2016-05-26 13:01:07 -05:00
Edward Thomson
b88f1713d0 zstream: offer inflating, git_zstream_inflatebuf
Introduce `git_zstream_inflatebuf` for simple uses.
2016-05-26 13:01:03 -05:00
Edward Thomson
1cd6599142 delta: refactor git_delta functions for consistency
Refactor the git_delta functions to have consistent naming and
parameters with the rest of the library.
2016-05-26 13:01:03 -05:00
Patrick Steinhardt
3fe5768b06 pack-objects: fix memory leak on overflow 2016-03-11 12:14:02 +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
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
Vicent Marti
1e5e02b4f4 pool: Simplify implementation 2015-10-28 10:13:13 +01:00
Stefan Widgren
c369b37919 Remove extra semicolon outside of a function
Without this change, compiling with gcc and pedantic generates warning:
ISO C does not allow extra ‘;’ outside of a function.
2015-07-31 16:23:11 +02:00
Carlos Martín Nieto
3c337a5d37 packbuilder: report progress during deltification
This is useful to send to the client while we're performing the work.

The reporting function has a force parameter which makes sure that we
do send out the message of 100% completed, even if this comes before the
next udpate window.
2015-05-13 15:52:13 +02:00
Carlos Martín Nieto
a61fa4c0c7 packbuilder: introduce git_packbuilder_insert_recur()
This function recursively inserts the given object and any referenced
ones. It can be thought of as a more general version of the functions to
insert a commit or tree.
2015-03-17 20:51:14 +01:00
Carlos Martín Nieto
04a36feff1 pack-objects: fill a packbuilder from a walk
Most use-cases for the object packer communicate in terms of commits
which each side has. We already have an object to specify this
relationship between commits, namely git_revwalk.

By knowing which commits we want to pack and which the other side
already has, we can perform similar optimisations to git, by marking
each tree as interesting or uninteresting only once, and not sending
those trees which we know the other side has.
2015-03-11 02:36:11 +01:00
Carlos Martín Nieto
b63b76e0b0 Reorder some khash declarations
Keep the definitions in the headers, while putting the declarations in
the C files. Putting the function definitions in headers causes
them to be duplicated if you include two headers with them.
2015-03-11 02:36:11 +01:00
Edward Thomson
0f07d54b44 pack-objects: unlock the cache on integer overflow 2015-02-13 09:35:20 -05:00
Edward Thomson
f1453c59b2 Make our overflow check look more like gcc/clang's
Make our overflow checking look more like gcc and clang's, so that
we can substitute it out with the compiler instrinsics on platforms
that support it.  This means dropping the ability to pass `NULL` as
an out parameter.

As a result, the macros also get updated to reflect this as well.
2015-02-13 09:27:33 -05:00
Edward Thomson
190b76a698 Introduce git__add_sizet_overflow and friends
Add some helper functions to check for overflow in a type-specific
manner.
2015-02-12 22:54:47 -05:00
Edward Thomson
ec3b4d35f6 Use size_t to hold size of arrays
Use `size_t` to hold the size of arrays to ease overflow checking,
lest we check for overflow of a `size_t` then promptly truncate
by packing the length into a smaller type.
2015-02-12 22:54:47 -05:00
Edward Thomson
2884cc42de overflow checking: don't make callers set oom
Have the ALLOC_OVERFLOW testing macros also simply set_oom in the
case where a computation would overflow, so that callers don't
need to.
2015-02-12 22:54:47 -05:00
Edward Thomson
3603cb0978 git__*allocarray: safer realloc and malloc
Introduce git__reallocarray that checks the product of the number
of elements and element size for overflow before allocation.  Also
introduce git__mallocarray that behaves like calloc, but without the
`c`.  (It does not zero memory, for those truly worried about every
cycle.)
2015-02-12 22:54:47 -05:00
Edward Thomson
392702ee2c allocations: test for overflow of requested size
Introduce some helper macros to test integer overflow from arithmetic
and set error message appropriately.
2015-02-12 22:54:46 -05:00
Philip Kelley
fb5917679d Win32: Fix object::cache::threadmania test on x64 2014-06-07 12:51:48 -04:00
Russell Belfer
af567e8853 Merge pull request #2334 from libgit2/rb/fix-2333
Be more careful with user-supplied buffers
2014-05-12 10:44:13 -07:00
Russell Belfer
d2c4d1c63d Merge pull request #2188 from libgit2/cmn/config-snapshot
Configuration snapshotting
2014-05-12 10:04:52 -07:00
Russell Belfer
1e4976cb01 Be more careful with user-supplied buffers
This adds in missing calls to `git_buf_sanitize` and fixes a
number of places where `git_buf` APIs could inadvertently write
NUL terminator bytes into invalid buffers.  This also changes the
behavior of `git_buf_sanitize` to NUL terminate a buffer if it can
and of `git_buf_shorten` to do nothing if it can.

Adds tests of filtering code with zeroed (i.e. unsanitized) buffer
which was previously triggering a segfault.
2014-05-08 10:17:14 -07:00
Carlos Martín Nieto
ac99d86ba5 repository: introduce a convenience config snapshot method
Accessing the repository's config and immediately taking a snapshot of
it is a common operation, so let's provide a convenience function for
it.
2014-05-07 11:34:32 +02:00
Carlos Martín Nieto
38d338b2b8 pack-objects: always write out the status in write_one()
Make sure we set the output parameter to a value.
2014-04-26 18:15:39 +02:00
Jacques Germishuys
48e60ae75e Don't redefine the same callback types, their signatures may change 2014-04-21 11:28:49 +02:00
Carlos Martín Nieto
29c4cb0965 Use config snapshotting
This way we can assume we have a consistent view of the config situation
when we're looking up remote, branch, pack-objects, etc.
2014-04-18 16:03:01 +02:00
Carlos Martín Nieto
a14aa1e789 pack-objects: free memory safely
A few fixes have accumulated in this area which have made the freeing of
data a bit muddy. Make sure to free the data only when needed and once.

When we are going to write a delta to the packfile, we need to free the
data, otherwise leave it. The current version of the code mixes up the
checks for po->data and po->delta_data.
2014-03-04 20:11:50 +01:00
Russell Belfer
d9b04d78a3 Reorganize zstream API and fix wrap problems
There were some confusing issues mixing up the number of bytes
written to the zstream output buffer with the number of bytes
consumed from the zstream input.  This reorganizes the zstream
API and makes it easier to deflate an arbitrarily large input
while still using a fixed size output.
2014-01-30 09:59:59 -08:00
Russell Belfer
e9d5e5f3d4 Some fixes for Windows x64 warnings 2014-01-30 09:59:59 -08:00
XTao
1cb5a81194 Fix write_object. 2014-01-26 22:26:53 +08:00
Edward Thomson
52a8a13072 Packbuilder contains its own zstream 2014-01-14 09:45:14 -08:00
Edward Thomson
0ade2f7a59 Packbuilder stream deflate instead of one-shot 2014-01-14 09:45:13 -08:00
Edward Thomson
c6f26b48e4 Refactor zlib for easier deflate streaming 2014-01-14 09:45:12 -08:00
Russell Belfer
7e3ed41959 Fix up some valgrind leaks and warnings 2013-12-11 16:56:17 -08:00
Russell Belfer
26c1cb91be One more rename/cleanup for callback err functions 2013-12-11 10:57:50 -08:00
Russell Belfer
c7b3e1b320 Some callback error check style cleanups
I find this easier to read...
2013-12-11 10:57:50 -08:00
Russell Belfer
25e0b1576d Remove converting user error to GIT_EUSER
This changes the behavior of callbacks so that the callback error
code is not converted into GIT_EUSER and instead we propagate the
return value through to the caller.  Instead of using the
giterr_capture and giterr_restore functions, we now rely on all
functions to pass back the return value from a callback.

To avoid having a return value with no error message, the user
can call the public giterr_set_str or some such function to set
an error message.  There is a new helper 'giterr_set_callback'
that functions can invoke after making a callback which ensures
that some error message was set in case the callback did not set
one.

In places where the sign of the callback return value is
meaningful (e.g. positive to skip, negative to abort), only the
negative values are returned back to the caller, obviously, since
the other values allow for continuing the loop.

The hardest parts of this were in the checkout code where positive
return values were overloaded as meaningful values for checkout.
I fixed this by adding an output parameter to many of the internal
checkout functions and removing the overload.  This added some
code, but it is probably a better implementation.

There is some funkiness in the network code where user provided
callbacks could be returning a positive or a negative value and
we want to rely on that to cancel the loop.  There are still a
couple places where an user error might get turned into GIT_EUSER
there, I think, though none exercised by the tests.
2013-12-11 10:57:49 -08:00
Russell Belfer
dab89f9b68 Further EUSER and error propagation fixes
This continues auditing all the places where GIT_EUSER is being
returned and making sure to clear any existing error using the
new giterr_user_cancel helper.  As a result, places that relied
on intercepting GIT_EUSER but having the old error preserved also
needed to be cleaned up to correctly stash and then retrieve the
actual error.

Additionally, as I encountered places where error codes were not
being propagated correctly, I tried to fix them up.  A number of
those fixes are included in the this commit as well.
2013-12-11 10:57:49 -08:00
Linquize
fb190bbbd0 Fix warnings 2013-11-12 19:46:25 +08:00
Edward Thomson
1e60e5f42d Allow callers to set mode on packfile creation 2013-11-07 12:04:32 -05:00
Edward Thomson
cc2447da32 Add git_packbuilder_hash to query pack filename 2013-11-07 09:43:24 -05:00
Russell Belfer
948f00b4e7 Merge pull request #1933 from libgit2/vmg/gcc-warnings
Warnings for Windows x64 (MSVC) and GCC on Linux
2013-11-01 09:38:03 -07:00