summaryrefslogtreecommitdiff
path: root/src/buffer.c
Commit message (Collapse)AuthorAgeFilesLines
* buffer: introduce git_buf_attach_notownedEdward Thomson2015-02-191-0/+14
| | | | | | 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.
* Make our overflow check look more like gcc/clang'sEdward Thomson2015-02-131-67/+76
| | | | | | | | | 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.
* overflow checking: don't make callers set oomEdward Thomson2015-02-121-1/+0
| | | | | | 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.
* git_buf_grow_by: increase buf asize incrementallyEdward Thomson2015-02-121-3/+14
| | | | | Introduce `git_buf_grow_by` to incrementally increase the size of a `git_buf`, performing an overflow calculation on the growth.
* allocations: test for overflow of requested sizeEdward Thomson2015-02-121-5/+57
| | | | | Introduce some helper macros to test integer overflow from arithmetic and set error message appropriately.
* Fix crash in free() when git_buf_grow() fails.Jeff Hostetler2015-01-091-1/+2
|
* buffer: Do not `put` anything if len is 0Vicent Marti2014-11-211-4/+7
|
* Introduce git_buf_decode_base64Edward Thomson2014-08-151-10/+56
| | | | Decode base64-encoded text into a git_buf
* Just put it all in buffer.joshaber2014-07-161-0/+11
|
* Be more careful with user-supplied buffersrb/fix-2333Russell Belfer2014-05-081-15/+22
| | | | | | | | | | | 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.
* patch: emit binary patches (optionally)Edward Thomson2014-04-221-0/+36
|
* Introduce git_buf_putcnJacques Germishuys2014-04-101-0/+9
| | | | Allows for inserting the same character n amount of times
* Add efficient git_buf join3 APIRussell Belfer2014-04-011-0/+53
| | | | | | | There are a few places where we need to join three strings to assemble a path. This adds a simple join3 function to avoid the comparatively expensive join_n (which calls strlen on each string twice).
* Remove now-duplicated stdarg.h includeEdward Thomson2014-02-241-1/+0
|
* fix corner cases and an undefined behaviorPatrick Reynolds2014-01-201-3/+6
|
* Handle git_buf's from users more liberallyEdward Thomson2014-01-081-0/+8
|
* Clean up unnecessary git_buf_printf callsRussell Belfer2013-09-231-0/+2
| | | | | | This replaces some git_buf_printf calls with simple calls to git_buf_put instead. Also, it fixes a missing va_end inside the git_buf_vprintf implementation.
* Merge pull request #1840 from linquize/warningVicent Martí2013-09-211-1/+1
|\ | | | | Fix warning
| * Fix warningLinquize2013-09-191-1/+1
| |
* | Merge git_buf and git_bufferRussell Belfer2013-09-171-74/+19
| | | | | | | | | | | | | | | | | | | | | | 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.
* | Add functions to manipulate filter listsRussell Belfer2013-09-171-1/+2
| | | | | | | | | | | | | | | | 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.
* | Extend public filter api with filter listsRussell Belfer2013-09-171-3/+20
| | | | | | | | | | | | | | | | | | | | | | 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.
* | Start of filter API + git_blob_filtered_contentRussell Belfer2013-09-171-0/+54
|/ | | | | | | | | | This begins the process of exposing git_filter objects to the public API. This includes: * new public type and API for `git_buffer` through which an allocated buffer can be passed to the user * new API `git_blob_filtered_content` * make the git_filter type and GIT_FILTER_TO_... constants public
* Add helpful buffer shorten functionRussell Belfer2013-07-011-0/+9
|
* update copyrightsEdward Thomson2013-01-081-1/+1
|
* Consolidate text buffer functionsRussell Belfer2012-11-281-108/+6
| | | | | | | | | | | | | 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).
* buf: introduce git_buf_splice()nulltoken2012-10-251-0/+28
|
* Fix buffer overrun in git_buf_put_base64Philip Kelley2012-10-141-1/+1
|
* Add git_buf_put_base64 to buffer APIRussell Belfer2012-10-101-0/+40
|
* Fix valgrind issues and leaksRussell Belfer2012-08-241-14/+23
| | | | | | This fixes up a number of problems flagged by valgrind and also cleans up the internal `git_submodule` allocation handling overall with a simpler model.
* Add git_buf_unescape and git__unescape to unescape all characters in a ↵yorah2012-07-241-0/+4
| | | | string (in-place)
* Fix missing NUL termination of bufferRussell Belfer2012-07-101-0/+2
|
* Add a couple of useful git_buf utilitiesRussell Belfer2012-07-101-0/+34
| | | | | | | * `git_buf_rfind` (with tests and tests for `git_buf_rfind_next`) * `git_buf_puts_escaped` and `git_buf_puts_escaped_regex` (with tests) to copy strings into a buffer while injecting an escape sequence (e.g. '\') in front of particular characters.
* misc: Fix warnings from PVS Studio trialVicent Martí2012-06-071-1/+2
|
* No point in keeping commented out fnRussell Belfer2012-05-171-9/+0
|
* Other optimization and warning fixesRussell Belfer2012-05-171-11/+16
| | | | | This fixes a warning left by the earlier optimization and addresses one of the other hotspots identified by GProf.
* Optimize away git_text_gather_stats in diffRussell Belfer2012-05-171-0/+18
| | | | | | | | GProf shows `git_text_gather_stats` as the most expensive call in large diffs. The function calculates a lot of information that is not actually used and does not do so in a optimal order. This introduces a tuned `git_buf_is_binary` function that executes the same algorithm in a fraction of the time.
* Document git_buf_common_prefixRussell Belfer2012-05-151-0/+3
| | | | | This function fills in a git_buf with the common prefix of an array of strings, but let's make that a little more clear.
* Ranged iterators and rewritten git_status_fileRussell Belfer2012-05-151-0/+27
| | | | | | | | | | | | | | | | | | | | | The goal of this work is to rewrite git_status_file to use the same underlying code as git_status_foreach. This is done in 3 phases: 1. Extend iterators to allow ranged iteration with start and end prefixes for the range of file names to be covered. 2. Improve diff so that when there is a pathspec and there is a common non-wildcard prefix of the pathspec, it will use ranged iterators to minimize excess iteration. 3. Rewrite git_status_file to call git_status_foreach_ext with a pathspec that covers just the one file being checked. Since ranged iterators underlie the status & diff implementation, this is actually fairly efficient. The workdir iterator does end up loading the contents of all the directories down to the single file, which should ideally be avoided, but it is pretty good.
* msvc: Do not use `isspace` Vicent Martí2012-05-091-1/+1
| | | | Locale-aware bullshit bitting my ass again yo
* buffer: Add `git_buf_vprintf`Vicent Martí2012-05-031-6/+22
|
* Implement git_pool paged memory allocatorRussell Belfer2012-04-251-1/+1
| | | | | | | | | | | | | | | | | | This adds a `git_pool` object that can do simple paged memory allocation with free for the entire pool at once. Using this, you can replace many small allocations with large blocks that can then cheaply be doled out in small pieces. This is best used when you plan to free the small blocks all at once - for example, if they represent the parsed state from a file or data stream that are either all kept or all discarded. There are two real patterns of usage for `git_pools`: either for "string" allocation, where the item size is a single byte and you end up just packing the allocations in together, or for "fixed size" allocation where you are allocating a large object (e.g. a `git_oid`) and you generally just allocation single objects that can be tightly packed. Of course, you can use it for other things, but those two cases are the easiest.
* Fix bug when join_n refers to original bufferRussell Belfer2012-03-301-6/+18
| | | | | | There was a bug in git_buf_join_n when the contents of the original buffer were joined into itself and the realloc moved the pointer to the original buffer.
* Convert attr, ignore, mwindow, status to new errorsRussell Belfer2012-03-161-22/+18
| | | | | Also cleaned up some previously converted code that still had little things to polish.
* Continue error conversionRussell Belfer2012-03-141-2/+2
| | | | | | | This converts blob.c, fileops.c, and all of the win32 files. Also, various minor cleanups throughout the code. Plus, in testing the win32 build, I cleaned up a bunch (although not all) of the warnings with the 64-bit build.
* error-handling: RepositoryVicent Martí2012-03-071-7/+2
| | | | | | | | This also includes droping `git_buf_lasterror` because it makes no sense in the new system. Note that in most of the places were it has been dropped, the code needs cleanup. I.e. GIT_ENOMEM is going away, so instead it should return a generic `-1` and obviously not throw anything.
* Add filter tests and fix some bugsRussell Belfer2012-03-021-0/+7
| | | | | This adds some initial unit tests for file filtering and fixes some simple bugs in filter application.
* buffer: Null terminate on rtrimVicent Martí2012-02-271-0/+2
|
* filter: Apply filters before writing a file to the ODBVicent Martí2012-02-271-1/+1
| | | | | | | | | | | | | | | | | | | | Initial implementation. The relevant code is in `blob.c`: the blob write function has been split into smaller functions. - Directly write a file to the ODB in streaming mode - Directly write a symlink to the ODB in direct mode - Apply a filter, and write a file to the ODB in direct mode When trying to write a file, we first call `git_filter__load_for_file`, which populates a filters array with the required filters based on the filename. If no filters are resolved to the filename, we can write to the ODB in streaming mode straight from disk. Otherwise, we load the whole file in memory and use double-buffering to apply the filter chain. We finish by writing the file as a whole to the ODB.
* buffer: Unify `git_fbuffer` and `git_buf`Vicent Martí2012-02-271-15/+30
| | | | | | | | | | | | | | This makes so much sense that I can't believe it hasn't been done before. Kill the old `git_fbuffer` and read files straight into `git_buf` objects. Also: In order to fully support 4GB files in 32-bit systems, the `git_buf` implementation has been changed from using `ssize_t` for storage and storing negative values on allocation failure, to using `size_t` and changing the buffer pointer to a magical pointer on allocation failure. Hopefully this won't break anything.