Commit Graph

43 Commits

Author SHA1 Message Date
nulltoken
3a14d3e2bc buf: introduce git_buf_splice() 2012-10-25 17:42:35 +02:00
Philip Kelley
9d9288f417 Fix buffer overrun in git_buf_put_base64 2012-10-14 12:29:05 -04:00
Russell Belfer
2d3579bea6 Add git_buf_put_base64 to buffer API 2012-10-10 14:54:31 -07:00
Russell Belfer
0c8858de8c Fix valgrind issues and leaks
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.
2012-08-24 11:00:27 -07:00
yorah
02a0d651d7 Add git_buf_unescape and git__unescape to unescape all characters in a string (in-place) 2012-07-24 14:03:07 +02:00
Russell Belfer
54e29b9380 Fix missing NUL termination of buffer 2012-07-10 23:51:32 -07:00
Russell Belfer
039fc40679 Add a couple of useful git_buf utilities
* `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.
2012-07-10 23:19:47 -07:00
Vicent Martí
3f0358604e misc: Fix warnings from PVS Studio trial 2012-06-07 22:43:48 +02:00
Russell Belfer
e3557172af No point in keeping commented out fn 2012-05-17 14:44:17 -07:00
Russell Belfer
a0d959628f Other optimization and warning fixes
This fixes a warning left by the earlier optimization and
addresses one of the other hotspots identified by GProf.
2012-05-17 13:14:17 -07:00
Russell Belfer
b59c73d39a Optimize away git_text_gather_stats in diff
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.
2012-05-17 13:06:20 -07:00
Russell Belfer
2c83391728 Document git_buf_common_prefix
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.
2012-05-15 16:33:05 -07:00
Russell Belfer
41a82592ef Ranged iterators and rewritten git_status_file
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.
2012-05-15 14:34:15 -07:00
Vicent Martí
0f49200c9a msvc: Do not use isspace
Locale-aware bullshit bitting my ass again yo
2012-05-09 04:37:02 +02:00
Vicent Martí
baaf1c4710 buffer: Add git_buf_vprintf 2012-05-03 00:03:58 -07:00
Russell Belfer
2bc8fa0227 Implement git_pool paged memory allocator
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.
2012-04-25 10:42:37 -07:00
Russell Belfer
952f94c8ab Fix bug when join_n refers to original buffer
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.
2012-03-30 14:42:23 -07:00
Russell Belfer
0d0fa7c368 Convert attr, ignore, mwindow, status to new errors
Also cleaned up some previously converted code that still had
little things to polish.
2012-03-16 15:56:01 -07:00
Russell Belfer
deafee7bd7 Continue error conversion
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.
2012-03-14 17:36:15 -07:00
Vicent Martí
cb8a79617b error-handling: Repository
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.
2012-03-07 00:11:43 +01:00
Russell Belfer
ce49c7a8a9 Add filter tests and fix some bugs
This adds some initial unit tests for file filtering and fixes
some simple bugs in filter application.
2012-03-02 15:09:40 -08:00
Vicent Martí
eb8f90e523 buffer: Null terminate on rtrim 2012-02-27 17:22:51 +01:00
Vicent Martí
44b1ff4c12 filter: Apply filters before writing a file to the ODB
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.
2012-02-27 05:30:07 +01:00
Vicent Martí
13224ea4aa buffer: Unify git_fbuffer and git_buf
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.
2012-02-27 05:30:07 +01:00
Russell Belfer
b6c93aef42 Uniform iterators for trees, index, and workdir
This create a new git_iterator type of object that provides a
uniform interface for iterating over the index, an arbitrary
tree, or the working directory of a repository.

As part of this, git ignore support was extended to support
push and pop of directory-based ignore files as the working
directory is being traversed (so the array of ignores does
not have to be recreated at each directory during traveral).

There are a number of other small utility functions in buffer,
path, vector, and fileops that are included in this patch
that made the iterator implementation cleaner.
2012-02-21 14:46:24 -08:00
schu
5e0de32818 Update Copyright header
Signed-off-by: schu <schu-github@schulog.org>
2012-02-13 17:11:09 +01:00
Russell Belfer
1dbcc9fc4e Fix several memory issues
This contains fixes for several issues discovered by MSVC and
by valgrind, including some bad data access, some memory
leakage (in where certain files were not being successfully
added to the cache), and some code simplification.
2012-01-11 23:21:46 -08:00
Russell Belfer
df743c7d3a Initial implementation of gitignore support
Adds support for .gitignore files to git_status_foreach() and
git_status_file().  This includes refactoring the gitattributes
code to share logic where possible.  The GIT_STATUS_IGNORED flag
will now be passed in for files that are ignored (provided they
are not already in the index or the head of repo).
2012-01-11 14:39:51 -08:00
Russell Belfer
b5daae68a4 Allow git_buf_joinpath to accept self-joins
It was not safe for git_buf_joinpath to be used with a pointer
into the buf itself because a reallocation could invalidate
the input parameter that pointed into the buffer.  This patch
makes it safe to self join, at least for the leading input to
the join, which is the common "append" case for self joins.

Also added unit tests to explicitly cover this case.

This should actually fix #511
2011-12-14 14:31:06 -08:00
Vicent Marti
bf6d2717ab buffer: inline git_buf_cstr 2011-12-14 03:27:53 +01:00
Russell Belfer
97769280ba Use git_buf for path storage instead of stack-based buffers
This converts virtually all of the places that allocate GIT_PATH_MAX
buffers on the stack for manipulating paths to use git_buf objects
instead.  The patch is pretty careful not to touch the public API
for libgit2, so there are a few places that still use GIT_PATH_MAX.

This extends and changes some details of the git_buf implementation
to add a couple of extra functions and to make error handling easier.

This includes serious alterations to all the path.c functions, and
several of the fileops.c ones, too.  Also, there are a number of new
functions that parallel existing ones except that use a git_buf
instead of a stack-based buffer (such as git_config_find_global_r
that exists alongsize git_config_find_global).

This also modifies the win32 version of p_realpath to allocate whatever
buffer size is needed to accommodate the realpath instead of hardcoding
a GIT_PATH_MAX limit, but that change needs to be tested still.
2011-12-07 23:08:15 -08:00
Russell Belfer
969d588d9a Optimized of git_buf_join.
This streamlines git_buf_join and removes the join-append behavior,
opting instead for a very compact join-replace of the git_buf contents.
The unit tests had to be updated to remove the join-append tests and
have a bunch more exhaustive tests added.
2011-11-30 13:10:47 -08:00
Russell Belfer
309113c984 Make initial value of git_buf ptr always be a valid empty string.
Taking a page from core git's strbuf, this introduces git_buf_initbuf
which is an empty string that is used to initialize the git_buf ptr
value even for new buffers.  Now the git_buf ptr will always point to
a valid NUL-terminated string.

This change required jumping through a few hoops for git_buf_grow
and git_buf_free to distinguish between a actual allocated buffer
and the global initial value.  Also, this moves the allocation
related functions to be next to each other near the top of buffer.c.
2011-11-29 23:45:17 -08:00
Russell Belfer
c63728cd73 Make git_buf functions always maintain a valid cstr.
At a tiny cost of 1 extra byte per allocation, this makes
git_buf_cstr into basically a noop, which simplifies error
checking when trying to convert things to use dynamic allocation.

This patch also adds a new function (git_buf_copy_cstr) for copying
the cstr data directly into an external buffer.
2011-11-29 16:39:49 -08:00
Russell Belfer
679b69c49d Resolve remaining feedback
* replace some ints with size_ts
* update NULL checks in various places
2011-11-28 13:05:25 -08:00
Russell Belfer
3aa294fd45 Add two string git_buf_join and tweak input error checking.
This commit addresses two of the comments:
* renamed existing n-input git_buf_join to git_buf_join_n
* added new git_buf_join that always takes two inputs
* moved some parameter error checking to asserts
* extended unit tests to cover new version of git_buf_join
2011-11-28 10:42:57 -08:00
Russell Belfer
8c74d22ebf Extend git_buf with new utility functions and unit tests.
Add new functions to git_buf for:
* initializing a buffer from a string
* joining one or more strings onto a buffer with separators
* swapping two buffers in place
* extracting data from a git_buf (leaving it empty)

Also, make git_buf_free leave a git_buf back in its initted state,
and slightly tweak buffer allocation sizes and thresholds.

Finally, port unit tests to clay and extend with lots of new tests
for the various git_buf functions.
2011-11-27 21:56:44 -08:00
Vicent Marti
3286c408ec global: Properly use git__ memory wrappers
Ensure that all memory related functions (malloc, calloc, strdup, free,
etc) are using their respective `git__` wrappers.
2011-10-28 19:02:36 -07:00
Vicent Martí
8114ee4c95 Merge pull request #405 from carlosmn/http-ls
Implement ls-remote over HTTP
2011-09-22 10:17:43 -07:00
Vicent Marti
bb742ede3d Cleanup legal data
1. The license header is technically not valid if it doesn't have a
copyright signature.

2. The COPYING file has been updated with the different licenses used in
the project.

3. The full GPLv2 header in each file annoys me.
2011-09-19 01:54:32 +03:00
Carlos Martín Nieto
c7c3051328 buffer: add git_buf_consume
Moves the content after 'end' to the beginning of the buffer

Signed-off-by: Carlos Martín Nieto <carlos@cmartin.tk>
2011-09-09 13:12:11 +02:00
Carlos Martín Nieto
b87600cb6b buffer: add git_buf_clear
Set the size to zero so the memory that has already been allocated
can be reused

Signed-off-by: Carlos Martín Nieto <carlos@cmartin.tk>
2011-09-09 13:12:11 +02:00
Vicent Marti
afeecf4f26 odb: Direct writes are back
DIRECT WRITES ARE BACK AND FASTER THAN EVER. The streaming writer to the
ODB was an overkill for the smaller objects like Commit and Tags; most
of the streaming logic was taking too long.

This commit makes Commits, Tags and Trees to be built-up in memory, and
then written to disk in 2 pushes (header + data), instead of streaming
everything.

This is *always* faster, even for big files (since the git_filebuf class
still does streaming writes when the memory cache overflows). This is
also a gazillion lines of code smaller, because we don't have to
precompute the final size of the object before starting the stream (this
was kind of defeating the point of streaming, anyway).

Blobs are still written with full streaming instead of loading them in
memory, since this is still the fastest way.

A new `git_buf` class has been added. It's missing some features, but
it'll get there.
2011-07-09 02:40:16 +02:00