Commit Graph

64 Commits

Author SHA1 Message Date
J Wyman
7dd2253826 centralizing all IO buffer size values 2015-05-11 10:32:08 -07:00
Carlos Martín Nieto
9cdd657887 Merge pull request #3104 from whoisj/optimal-buffer-size
Adjusting stream buffer size to 64KB
2015-05-09 13:11:46 +02:00
J Wyman
7eb7e03db8 Adjusting stream buffer size to 64KB
64K is optimal buffer size per https://technet.microsoft.com/en-us/library/cc938632.aspx
2015-05-07 08:50:12 -07:00
Leo Yang
69f0032b4c Fix some build warnings
In checkout.c and filter.c we were casting a sub struct
to a parent struct which breaks the strict aliasing rules
in C. However we can use .parent or .base to access the
parent struct to avoid the build warnings.

In remote.c the local variable error was not initialized
or updated in some cases. For unintialized error a build
warning will be generated. So always keep error variable
up-to-date.
2015-04-28 12:40:20 -04:00
Edward Thomson
669ae27422 filter: clear the temp_buf if we're using one
If we are using a temporary buffer for filtering, be sure to clear
it before using it, in case the file that we are filtering is empty.
2015-03-25 10:20:59 -04:00
Edward Thomson
6a2edc5a11 filter: accept relative paths in apply_to_file 2015-03-06 15:16:40 -05:00
Edward Thomson
9a823badbf filter: drop old TODO 2015-03-06 14:37:41 -05:00
Edward Thomson
9c9aa1bad3 filter: take temp_buf in git_filter_options 2015-02-19 11:45:46 -05:00
Edward Thomson
d05218b06f filter: add git_filter_list__load_ext
Refactor `git_filter_list__load_with_attr_reader` into
`git_filter_list__load_ext`, which takes a `git_filter_options`.
2015-02-19 11:25:26 -05:00
Edward Thomson
795eaccd66 git_filter_opt_t -> git_filter_flag_t
For consistency with the rest of the library, where an opt is an
options *structure*.
2015-02-19 11:09:54 -05:00
Edward Thomson
d4cf167515 buffer: introduce git_buf_attach_notowned
Provide a convenience function that creates a buffer that can be provided
to callers but will not be freed via `git_buf_free`, so the buffer
creator maintains the allocation lifecycle of the buffer's contents.
2015-02-19 10:05:33 -05:00
Edward Thomson
f7c0125f47 filter streams: base -> parent 2015-02-18 10:24:34 -05:00
Edward Thomson
b75f15aaf1 git_writestream: from git_filter_stream 2015-02-18 10:24:23 -05:00
Edward Thomson
646364e780 checkout: maintain temporary buffer for filters
Let the filters use the checkout data's temporary buffer, instead
of having to allocate new buffers each time.
2015-02-17 16:03:45 -05:00
Edward Thomson
e78f5c9f42 checkout: stream the blob into the filters
Use the new streaming filter API during checkout.
2015-02-17 15:57:10 -05:00
Edward Thomson
5555696f8a filters: stream internally
Migrate the `git_filter_list_apply_*` functions over to using the
new filter streams.
2015-02-17 15:57:04 -05:00
Edward Thomson
fbdc9db364 filters: introduce streaming filters
Add structures and preliminary functions to take a buffer, file or
blob and write the contents in chunks through an arbitrary number
of chained filters, finally writing into a user-provided function
accept the contents.
2015-02-17 02:19:05 -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
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
Edward Thomson
9f779aacdd attrcache: don't re-read attrs during checkout
During checkout, assume that the .gitattributes files aren't
modified during the checkout.  Instead, create an "attribute session"
during checkout.  Assume that attribute data read in the same
checkout "session" hasn't been modified since the checkout started.
(But allow subsequent checkouts to invalidate the cache.)

Further, cache nonexistent git_attr_file data even when .gitattributes
files are not found to prevent re-scanning for nonexistent files.
2015-02-03 00:31:08 -05:00
Anurag Gupta (OSG)
5623e627d4 git_filter: dup the filter name 2014-10-09 14:54: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
45c53eb6cb Use unsigned type for APIs with opt flag mask 2014-05-08 10:46:04 -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
Russell Belfer
5269008cf6 Add filter options and ALLOW_UNSAFE
Diff and status do not want core.safecrlf to actually raise an
error regardless of the setting, so this extends the filter API
with an additional options flags parameter and adds a flag so that
filters can be applied with GIT_FILTER_OPT_ALLOW_UNSAFE, indicating
that unsafe filter application should be downgraded from a failure
to a warning.
2014-05-06 16:01:49 -07:00
Jiri Pospisil
424222f415 Filter: Make sure to release local on error 2014-04-25 15:49:26 +02:00
Russell Belfer
9cfce2735d Cleanups, renames, and leak fixes
This renames git_vector_free_all to the better git_vector_free_deep
and also contains a couple of memory leak fixes based on valgrind
checks.  The fixes are specifically: failure to free global dir
path variables when not compiled with threading on and failure to
free filters from the filter registry that had not be initialized
fully.
2013-12-12 12:11:38 -08:00
Russell Belfer
713793133f Fix warnings on Windows 64-bit build 2013-09-23 21:41:52 -07:00
Russell Belfer
eefc32d549 Bug fixes and cleanups
This contains a few bug fixes and some header and API cleanups.

The main API change is that filters should now use GIT_PASSTHROUGH
to indicate that they wish to skip processing a file instead of
GIT_ENOTFOUND.

The bug fixes include a possible out-of-range buffer access in
the ident filter, a filter ordering problem I introduced into the
custom filter tests on Windows, and a filter buf NUL termination
issue that was coming up on Linux.
2013-09-17 09:31:46 -07:00
Russell Belfer
37f9e40939 Some tests with ident and crlf filters
Fixed the filter order to match core Git, too.

This test demonstrates an interesting behavior of core Git (which
is totally reasonable and which libgit2 matches, although mostly
by coincidence).  If you use the ident filter and commit a file
with a garbage ident in it, like '$Id: this is just garbage$' and
then immediately do a 'git checkout-index' with the new file, Git
will not consider the file out of date and will not overwrite the
file with an updated $Id$.  Libgit2 has the same behavior.  If you
remove the file and then do a checkout-index, it will be replaced
with a filtered version that has injected the OID correctly.
2013-09-17 09:31:46 -07:00
Russell Belfer
e399c7eee8 Fix win32 warnings
I wish MSVC understood that "const char **" is not a const ptr,
but it a non-const pointer to an array of const ptrs.  Does that
seem like too much to ask.
2013-09-17 09:31:46 -07:00
Russell Belfer
b47349b8dc Port tests from PR 1683
This ports over some of the tests from
    https://github.com/libgit2/libgit2/pull/1683
by @yorah and @ethomson
2013-09-17 09:31:45 -07:00
Russell Belfer
a9f51e430f Merge git_buf and git_buffer
This makes the git_buf struct that was used internally into an
externally available structure and eliminates the git_buffer.

As part of that, some of the special cases that arose with the
externally used git_buffer were blended into the git_buf, such as
being careful about git_buf objects that may have a NULL ptr and
allowing for bufs with a valid ptr and size but zero asize as a
way of referring to externally owned data.
2013-09-17 09:31:45 -07:00
Russell Belfer
4b11f25a4f Add ident filter
This adds the ident filter (that knows how to replace $Id$) and
tweaks the filter APIs and code so that git_filter_source objects
actually have the updated OID of the object being filtered when
it is a known value.
2013-09-17 09:31:45 -07:00
Russell Belfer
40cb40fab9 Add functions to manipulate filter lists
Extend the git2/sys/filter API with functions to look up a filter
and add it manually to a filter list.  This requires some trickery
because the regular attribute lookups and checks are bypassed when
this happens, but in the right hands, it will allow a user to have
granular control over applying filters.
2013-09-17 09:31:45 -07:00
Russell Belfer
0646634e2f Update filter registry code
This updates the git filter registry to be a little cleaner and
plugs some memory leaks.
2013-09-17 09:31:45 -07:00
Russell Belfer
29e92d385e Hook up filter initialize callback
I knew I forgot something
2013-09-17 09:31:44 -07:00
Russell Belfer
2a7d224f99 Extend public filter api with filter lists
This moves the git_filter_list into the public API so that users
can create, apply, and dispose of filter lists.  This allows more
granular application of filters to user data outside of libgit2
internals.

This also converts all the internal usage of filters to the public
APIs along with a few small tweaks to make it easier to use the
public git_buffer stuff alongside the internal git_buf.
2013-09-17 09:31:44 -07:00
Russell Belfer
974774c7b0 Add attributes to filters and fix registry
The filter registry as implemented was too primitive to actually
work once multiple filters were coming into play.  This expands
the implementation of the registry to handle multiple prioritized
filters correctly.

Additionally, this adds an "attributes" field to a filter that
makes it really really easy to implement filters that are based
on one or more attribute values.  The lookup and even simple value
checking can all happen automatically without custom filter code.

Lastly, with the registry improvements, this fills out the filter
lifecycle callbacks, with initialize and shutdown callbacks that
will be called before the filter is first used and after it is
last invoked.  This allows for system-wide initialization and
cleanup by the filter.
2013-09-17 09:31:44 -07:00
Russell Belfer
570ba25cb0 Make git_filter_source opaque 2013-09-17 09:30:06 -07:00
Russell Belfer
85d5481206 Create public filter object and use it
This creates include/sys/filter.h with a basic definition of a
git_filter and then converts the internal code to use it.  There
are related internal objects (git_filter_list) that we will want
to publish at some point, but this is a first step.
2013-09-17 09:30:06 -07:00
Arkadiy Shapkin
10c06114cb Several warnings detected by static code analyzer fixed
Implicit type conversion argument of function to size_t type
Suspicious sequence of types castings: size_t -> int -> size_t
Consider reviewing the expression of the 'A = B == C' kind. The expression is calculated as following: 'A = (B == C)'
Unsigned type is never < 0
2013-03-18 03:30:26 +04:00
Edward Thomson
359fc2d241 update copyrights 2013-01-08 17:31:27 -06:00
Russell Belfer
7bf87ab698 Consolidate text buffer functions
There are many scattered functions that look into the contents of
buffers to do various text manipulations (such as escaping or
unescaping data, calculating text stats, guessing if content is
binary, etc).  This groups all those functions together into a
new file and converts the code to use that.

This has two enhancements to existing functionality.  The old
text stats function is significantly rewritten and the BOM
detection code was extended (although largely we can't deal with
anything other than a UTF8 BOM).
2012-11-28 09:58:48 -08:00
Jameson Miller
c902f5a0ff Update of text stats calculation
Do not interpret 0x85 as Next Line (NEL)
char when gathering statistics for a text file.
2012-11-01 12:26:56 -04:00
nulltoken
5e4cb4f4da checkout : reduce memory usage when not filtering 2012-09-17 10:48:36 +02:00
nulltoken
3aa443a951 checkout: introduce git_checkout_tree() 2012-09-17 10:48:26 +02:00
Ben Straub
7cae2bcdf9 filter: fix memory leak 2012-07-21 20:11:37 -07:00
Ben Straub
9587895f57 Migrate code to git_filter_blob_contents.
Also removes the unnecessary check for filter 
length, since git_filters_apply does the right 
thing when there are none, and it's more efficient
than this.
2012-07-16 12:06:23 -07:00
Ben Straub
f2d42eea34 Checkout: add structure for CRLF. 2012-07-09 20:21:22 -07:00