Commit Graph

81 Commits

Author SHA1 Message Date
Russell Belfer
917f60c50b Add tests for oidmap and new cache with threading
This adds some basic tests for the oidmap just to make sure that
collisions, etc. are dealt with correctly.

This also adds some tests for the new caching that check if items
are inserted (or not inserted) properly into the cache, and that
the cache can hold up in a multithreaded environment without error.
2013-04-22 16:50:51 +02:00
Vicent Marti
5df184241a lol this worked first try wtf 2013-04-22 16:50:50 +02:00
Vicent Martí
0b061b5bfa Merge pull request #1436 from schu/opts-cache-size
opts: allow configuration of odb cache size
2013-03-26 11:05:57 -07:00
Russell Belfer
3658e81e34 Move crlf conversion into buf_text
This adds crlf/lf conversion functions into buf_text with more
efficient implementations that bypass the high level buffer
functions.  They attempt to minimize the number of reallocations
done and they directly write the buffer data as needed if they
know that there is enough memory allocated to memcpy data.

Tests are added for these new functions.  The crlf.c code is
updated to use the new functions.

Removed the include of buf_text.h from filter.h and just include
it more narrowly in the places that need it.
2013-03-25 14:20:07 -07:00
Vicent Marti
13640d1bb8 oid: Do not parse OIDs longer than 40 2013-03-25 21:39:11 +01:00
Michael Schubert
f5e28202cb opts: allow configuration of odb cache size
Currently, the odb cache has a fixed size of 128 slots as defined by
GIT_DEFAULT_CACHE_SIZE. Allow users to set the size of the cache via
git_libgit2_opts().

Fixes #1035.
2013-03-25 15:45:56 +01:00
Xavier L.
b3c174835b Clarified string value 2013-03-21 14:50:28 -03:00
Xavier L
7e527ca700 Added test case for new function 2013-03-21 12:16:31 -04:00
Russell Belfer
324602514f Fixes and cleanups
Get rid of some dead code, tighten things up a bit, and fix a bug
with core::env test.
2013-03-18 15:54:35 -07:00
Russell Belfer
41954a49c1 Switch search paths to classic delimited strings
This switches the APIs for setting and getting the global/system
search paths from using git_strarray to using a simple string with
GIT_PATH_LIST_SEPARATOR delimited paths, just as the environment
PATH variable would contain.  This makes it simpler to get and set
the value.

I also added code to expand "$PATH" when setting a new value to
embed the old value of the path.  This means that I no longer
require separate actions to PREPEND to the value.
2013-03-18 14:19:35 -07:00
Russell Belfer
5540d9477e Implement global/system file search paths
The goal of this work is to expose the search logic for "global",
"system", and "xdg" files through the git_libgit2_opts() interface.

Behind the scenes, I changed the logic for finding files to have a
notion of a git_strarray that represents a search path and to store
a separate search path for each of the three tiers of config file.
For each tier, I implemented a function to initialize it to default
values (generally based on environment variables), and then general
interfaces to get it, set it, reset it, and prepend new directories
to it.

Next, I exposed these interfaces through the git_libgit2_opts
interface, reusing the GIT_CONFIG_LEVEL_SYSTEM, etc., constants
for the user to control which search path they were modifying.
There are alternative designs for the opts interface / argument
ordering, so I'm putting this phase out for discussion.

Additionally, I ended up doing a little bit of clean up regarding
attr.h and attr_file.h, adding a new attrcache.h so the other two
files wouldn't have to be included in so many places.
2013-03-15 16:39:00 -07:00
Russell Belfer
0c46863384 Improved tree iterator internals
This updates the tree iterator internals to be more efficient.

The tree_iterator_entry objects are now kept as pointers that are
allocated from a git_pool, so that we may use git__tsort_r for
sorting (which is better than qsort, given that the tree is
likely mostly ordered already).

Those tree_iterator_entry objects now keep direct pointers to the
data they refer to instead of keeping indirect index values.  This
simplifies a lot of the data structure traversal code.

This also adds bsearch to find the start item position for range-
limited tree iterators, and is more explicit about using
git_path_cmp instead of reimplementing it.  The git_path_cmp
changed a bit to make it easier for tree_iterators to use it (but
it was barely being used previously, so not a big deal).

This adds a git_pool_free_array function that efficiently frees a
list of pool allocated pointers (which the tree_iterator keeps).
Also, added new tests for the git_pool free list functionality
that was not previously being tested (or used).
2013-03-14 13:40:15 -07:00
Russell Belfer
9bc8be3d7e Refine pluggable similarity API
This plugs in the three basic similarity strategies for handling
whitespace via internal use of the pluggable API.  In so doing, I
realized that the use of git_buf in the hashsig API was not needed
and actually just made it harder to use, so I tweaked that API as
well.

Note that the similarity metric is still not hooked up in the
find_similarity code - this is just setting out the function that
will be used.
2013-02-20 15:09:41 -08:00
Russell Belfer
aa6432604e More tests of file signatures with whitespace opts
Seems to be working pretty well...
2013-02-20 15:09:41 -08:00
Russell Belfer
5e5848eb15 Change similarity metric to sampled hashes
This moves the similarity metric code out of buf_text and into a
new file.  Also, this implements a different approach to similarity
measurement based on a Rabin-Karp rolling hash where we only keep
the top 100 and bottom 100 hashes.  In theory, that should be
sufficient samples to given a fairly accurate measurement while
limiting the amount of data we keep for file signatures no matter
how large the file is.
2013-02-20 15:09:40 -08:00
Russell Belfer
9c454b007b Initial implementation of similarity scoring algo
This adds a new `git_buf_text_hashsig` type and functions to
generate these hash signatures and compare them to give a
similarity score.  This can be plugged into diff similarity
scoring.
2013-02-20 15:09:40 -08:00
Russell Belfer
56543a609a Clear up warnings from cppcheck
The cppcheck static analyzer generates warnings for a bunch of
places in the libgit2 code base.  All the ones fixed in this
commit are actually false positives, but I've reorganized the
code to hopefully make it easier for static analysis tools to
correctly understand the structure.  I wouldn't do this if I
felt like it was making the code harder to read or worse for
humans, but in this case, these fixes don't seem too bad and will
hopefully make it easier for better analysis tools to get at any
real issues.
2013-02-15 16:02:45 -08:00
Philip Kelley
8c29dca6c3 Fix some incorrect MSVC #ifdef's. Fixes #1305 2013-02-11 09:25:57 -05:00
Russell Belfer
17c92beaca Test buf join with NULL behavior explicitly 2013-01-29 12:13:24 -08:00
Vicent Marti
0d52cb4aea opts: Some basic tests 2013-01-24 00:09:55 +01:00
Russell Belfer
f63d0ee9fc Move all non-ascii test data to raw hex
This takes all of the characters in core::env and makes them use
hex sequences instead of keeping tricky character data inline in
the test.
2013-01-17 15:47:10 -08:00
Russell Belfer
0d65acade8 Match binary file check of core git in diff
Core git just looks for NUL bytes in files when deciding about
is-binary inside diff (although it uses a better algorithm in
checkout, when deciding if CRLF conversion should be done).
Libgit2 was using the better algorithm in both places, but that
is causing some confusion.  For now, this makes diff just look
for NUL bytes to decide if a file is binary by content in diff.
2013-01-11 11:24:26 -08:00
Russell Belfer
b8a1ea7cf9 Fix core::env cleanup code
Mark fake home directories that failed to be created, so we won't
try to remove them and have cleanup just use p_rmdir.
2013-01-03 11:04:03 -08:00
Ben Straub
600d8dbf6d Move test cleanup into cleanup functions 2013-01-03 09:10:38 -08:00
Ben Straub
6fef1ab344 Tests should clean up after themselves 2013-01-03 07:47:51 -08:00
nulltoken
50a762a563 path: Teach UNC paths to git_path_dirname_r()
Fix libgit2/libgit2sharp#256
2012-12-26 23:07:25 +01:00
nulltoken
34b6f05f39 path: enhance git_path_dirname_r() test coverage 2012-12-26 11:59:07 +01: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
Russell Belfer
16248ee2d1 Fix up some missing consts in tree & index
This fixes some missed places where we can apply const-ness to
various public APIs.

There are still some index and tree APIs that cannot take const
pointers because we sort our `git_vectors` lazily and so we can't
reliably bsearch the index and tree content without applying a
`git_vector_sort()` first.

This also fixes some missed places where size_t can be used and
where const can be applied to a couple internal functions.
2012-11-27 13:18:29 -08:00
Sascha Cunz
9094d30b93 Reset all static variables to NULL in clar's __cleanup
Without this change, any failed assertion in the second (or a later) test
inside a test suite has a chance of double deleting memory, resulting in
a heap corruption. See #1096 for details.

This leaves alone the test cases where we "just" use cl_git_sandbox_init()
and cl_git_sandbox_cleanup(). These methods already take good care to not
double delete a repository.

Fixes #1096
2012-11-23 11:41:56 +01:00
Eduardo Bart
e566b609df Update clar tests p_lstat_posixly and p_lstat 2012-11-20 00:57:56 -02:00
nulltoken
0e95e70a55 env: ensure git_futils_find_xxx() returns ENOTFOUND 2012-11-17 05:41:22 -08:00
Russell Belfer
cccacac555 Add POSIX compat lstat() variant for win32
The existing p_lstat implementation on win32 is not quite POSIX
compliant when setting errno to ENOTDIR.  This adds an option to
make is be compliant so that code (such as checkout) that cares
to have separate behavior for ENOTDIR can use it portably.

This also contains a couple of other minor cleanups in the
posix_w32.c implementations to avoid unnecessary work.
2012-11-14 22:41:51 -08:00
Russell Belfer
331e7de900 Extensions to rmdir and mkdir utilities
* Rework GIT_DIRREMOVAL values to GIT_RMDIR flags, allowing
  combinations of flags
* Add GIT_RMDIR_EMPTY_PARENTS flag to remove parent dirs that
  are left empty after removal
* Add GIT_MKDIR_VERIFY_DIR to give an error if item is a file,
  not a dir (previously an EEXISTS error was ignored, even for
  files) and enable this flag for git_futils_mkpath2file call
* Improve accuracy of error messages from git_futils_mkdir
2012-11-09 13:52:06 -08:00
Edward Thomson
f45ec1a076 index refactoring 2012-10-29 20:04:21 -05:00
Russell Belfer
0d422ec9c2 Fix env variable tests with new Win32 path rules
The new Win32 global path search was not working with the
environment variable tests.  But when I fixed the test, the new
codes use of getenv() was causing more failures (presumably because
of caching on Windows ???).  This fixes the global file lookup to
always go directly to the Win32 API in a predictable way.
2012-10-19 15:40:43 -07:00
Russell Belfer
4c47a8bcfe Merge pull request #968 from arrbee/diff-support-typechange
Support TYPECHANGE records in status and adjust checkout accordingly
2012-10-17 14:14:51 -07:00
Vicent Marti
18217e7e8a test: Don't be so picky with failed lookups
Not found means not found, and the other way around.
2012-10-16 19:37:21 +02:00
Russell Belfer
2d3579bea6 Add git_buf_put_base64 to buffer API 2012-10-10 14:54:31 -07:00
Russell Belfer
0d64bef941 Add complex checkout test and then fix checkout
This started as a complex new test for checkout going through the
"typechanges" test repository, but that revealed numerous issues
with checkout, including:

* complete failure with submodules
* failure to create blobs with exec bits
* problems when replacing a tree with a blob because the tree
  "example/" sorts after the blob "example" so the delete was
  being processed after the single file blob was created

This fixes most of those problems and includes a number of other
minor changes that made it easier to do that, including improving
the TYPECHANGE support in diff/status, etc.
2012-10-09 11:59:34 -07:00
Russell Belfer
1a62810053 Make giterr_set_str public
There has been discussion for a while about making some set of
the `giterr_set` type functions part of the public API for code
that is implementing new backends to libgit2.  This makes the
`giterr_set_str()` and `giterr_set_oom()` functions public.
2012-09-21 15:04:39 -07:00
Russell Belfer
2eb4edf5f2 Fix errors on Win32 with new repo init 2012-08-24 10:48:48 -07:00
Russell Belfer
e9ca852e4d Fix warnings and merge issues on Win64 2012-08-23 09:20:17 -07:00
Russell Belfer
85bd174626 Some cleanup suggested during review
This cleans up a number of items suggested during code review
with @vmg, including:

* renaming "outside repo" config API to `git_config_open_default`
* killing the `git_config_open_global` API
* removing the `git_` prefix from the static functions in fileops
* removing some unnecessary functionality from the "cp" command
2012-08-22 16:16:42 -07:00
Russell Belfer
b769e936d0 Don't reference stack vars in cleanup callback
If you use the clar cleanup callback function, you can't pass a
reference pointer to a stack allocated variable because when the
cleanup function runs, the stack won't exist anymore.
2012-08-22 16:07:19 -07:00
Russell Belfer
ca1b6e5409 Add template dir and set gid to repo init
This extends git_repository_init_ext further with support for
initializing the repository from an external template directory
and with support for the "create shared" type flags that make a
set GID repository directory.

This also adds tests for much of the new functionality to the
existing `repo/init.c` test suite.

Also, this adds a bunch of new utility functions including a
very general purpose `git_futils_mkdir` (with the ability to
make paths and to chmod the paths post-creation) and a file
tree copying function `git_futils_cp_r`.  Also, this includes
some new path functions that were useful to keep the code
simple.
2012-08-22 16:07:19 -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
465092ce3f Fix memory leak in test 2012-07-12 11:56:50 -07:00
Russell Belfer
b0fe112922 Add path utilities to resolve relative paths
This makes it easy to take a buffer containing a path with relative
references (i.e. .. or . path segments) and resolve all of those
into a clean path.  This can be applied to URLs as well as file
paths which can be useful.

As part of this, I made the drive-letter detection apply on all
platforms, not just windows.  If you give a path that looks like
"c:/..." on any platform, it seems like we might as well detect
that as a rooted path.  I suppose if you create a directory named
"x:" on another platform and want to use that as the beginning
of a relative path under the root directory of your repo, this
could cause a problem, but then it seems like you're asking for
trouble.
2012-07-10 23:19:47 -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