Commit Graph

46 Commits

Author SHA1 Message Date
Edward Thomson
f45ec1a076 index refactoring 2012-10-29 20:04:21 -05:00
Philip Kelley
ec40b7f99f Support for core.ignorecase 2012-09-17 15:42:41 -04:00
Russell Belfer
f335ecd6e1 Diff iterators
This refactors the diff output code so that an iterator object
can be used to traverse and generate the diffs, instead of just
the `foreach()` style with callbacks.  The code has been rearranged
so that the two styles can still share most functions.

This also replaces `GIT_REVWALKOVER` with `GIT_ITEROVER` and uses
that as a common error code for marking the end of iteration when
using a iterator style of object.
2012-09-05 15:17:24 -07:00
Russell Belfer
7fbca880aa Support new config locations
As of git v1.7.12, $HOME/.config/git/ is supported as a new
location for "config", "attributes", and "ignore" files.
2012-08-24 14:32:45 -07:00
Russell Belfer
f004c4a8a7 Add public API for internal ignores
This creates a public API for adding to the internal ignores
list, which already existing but was not accessible.

This adds the new default value for core.excludesfile also.
2012-08-21 17:26:39 -07:00
Vicent Marti
c07d9c95f2 oid: Explicitly include oid.h for the inlined CMP 2012-08-09 15:33:04 -07:00
Vicent Marti
51e1d80846 Merge remote-tracking branch 'arrbee/tree-walk-fixes' into development
Conflicts:
	src/notes.c
	src/transports/git.c
	src/transports/http.c
	src/transports/local.c
	tests-clar/odb/foreach.c
2012-08-06 12:41:08 +02:00
Russell Belfer
5dca201072 Update iterators for consistency across library
This updates all the `foreach()` type functions across the library
that take callbacks from the user to have a consistent behavior.
The rules are:

* A callback terminates the loop by returning any non-zero value
* Once the callback returns non-zero, it will not be called again
  (i.e. the loop stops all iteration regardless of state)
* If the callback returns non-zero, the parent fn returns GIT_EUSER
* Although the parent returns GIT_EUSER, no error will be set in
  the library and `giterr_last()` will return NULL if called.

This commit makes those changes across the library and adds tests
for most of the iteration APIs to make sure that they follow the
above rules.
2012-08-03 17:08:01 -07:00
Vicent Marti
e25dda51c4 Merge remote-tracking branch 'nulltoken/topic/amd64-compat' into development
Conflicts:
	src/netops.c
	src/netops.h
	src/oid.c
2012-08-02 01:38:30 +02:00
Vicent Marti
0c9eacf3d2 attr: Do not export variables externally
Fixes #824

Exporting variables in a dynamic library is a PITA. Let's keep
these values internally and wrap them through a helper method.

This doesn't break the external API. @arrbee, aren't you glad I turned
the `GIT_ATTR_` macros into function macros? 
2012-08-02 01:15:24 +02:00
nulltoken
b8457baae2 portability: Improve x86/amd64 compatibility 2012-07-24 16:10:12 +02:00
Vicent Martí
3f0358604e misc: Fix warnings from PVS Studio trial 2012-06-07 22:43:48 +02:00
Russell Belfer
2a99df6909 Fix bugs for status with spaces and reloaded attrs
This fixes two bugs:

* Issue #728 where git_status_file was not working for files
  that contain spaces.  This was caused by reusing the "fnmatch"
  parsing code from ignore and attribute files to interpret the
  "pathspec" that constrained the files to apply the status to.
  In that code, unescaped whitespace was considered terminal to
  the pattern, so a file with internal whitespace was excluded
  from the matched files.  The fix was to add a mode to that code
  that allows spaces and tabs inside patterns.  This mode only
  comes into play when parsing in-memory strings.

* The other issue was undetected, but it was in the recently
  added code to reload gitattributes / gitignores when they were
  changed on disk.  That code was not clearing out the old values
  from the cached file content before reparsing which meant that
  newly added patterns would be read in, but deleted patterns
  would not be removed.  The fix was to clear the vector of
  patterns in a cached file before reparsing the file.
2012-05-24 17:14:56 -07:00
Vicent Martí
904b67e69f errors: Rename error codes 2012-05-18 01:48:50 +02:00
Vicent Martí
e172cf082e errors: Rename the generic return codes 2012-05-18 01:26:26 +02:00
Vicent Martí
29e948debe global: Change parameter ordering in API
Consistency is good.
2012-05-18 01:25:57 +02:00
Russell Belfer
dc13f1f7d7 Add cache busting to attribute cache
This makes the git attributes and git ignores cache check
stat information before using the file contents from the
cache.  For cached files from the index, it checks the SHA
of the file instead.  This should reduce the need to ever
call `git_attr_cache_flush()` in most situations.

This commit also fixes the `git_status_should_ignore` API
to use the libgit2 standard parameter ordering.
2012-05-10 11:12:43 -07:00
Russell Belfer
cba285d32f Fix directory finding for attrs
The fix to support attrs on bare repos went a little too far
in trying to avoid using the working directory and ended up
not processing the input path quite correctly.
2012-05-07 13:32:30 -07:00
Russell Belfer
b709e95146 Fix memory leaks and use after free 2012-05-04 11:06:12 -07:00
Russell Belfer
f917481ee8 Support reading attributes from index
Depending on the operation, we need to consider gitattributes
in both the work dir and the index.  This adds a parameter to
all of the gitattributes related functions that allows user
control of attribute reading behavior (i.e. prefer workdir,
prefer index, only use index).

This fix also covers allowing us to check attributes (and
hence do diff and status) on bare repositories.

This was a somewhat larger change that I hoped because it had
to change the cache key used for gitattributes files.
2012-05-03 16:37:25 -07:00
Russell Belfer
d58336dda8 Fix leading slash behavior in attrs/ignores
We were not following the git behavior for leading slashes
in path names when matching git ignores and git attribute
file patterns.  This should fix issue #638.
2012-04-26 10:51:45 -07:00
Russell Belfer
c2b670436f Rename git_khash_str to git_strmap, etc.
This renamed `git_khash_str` to `git_strmap`, `git_hash_oid` to
`git_oidmap`, and deletes `git_hashtable` from the tree, plus
adds unit tests for `git_strmap`.
2012-04-25 15:20:28 -07:00
Russell Belfer
01fed0a8f9 Convert hashtable usage over to khash
This updates khash.h with some extra features (like error checking
on allocations, ability to use wrapped malloc, foreach calls, etc),
creates two high-level wrappers around khash: `git_khash_str` and
`git_khash_oid` for string-to-void-ptr and oid-to-void-ptr tables,
then converts all of the old usage of `git_hashtable` over to use
these new hashtables.

For `git_khash_str`, I've tried to create a set of macros that
yield an API not too unlike the old `git_hashtable` API.  Since
the oid hashtable is only used in one file, I haven't bother to
set up all those macros and just use the khash APIs directly for
now.
2012-04-25 11:18:08 -07:00
Russell Belfer
19fa2bc111 Convert attrs and diffs to use string pools
This converts the git attr related code (including ignores) and
the git diff related code (and implicitly the status code) to use
`git_pools` for storing strings.  This reduces the number of small
blocks allocated dramatically.
2012-04-25 10:42:37 -07:00
Russell Belfer
7784bcbbee Refactor git_repository_open with new options
Add a new command `git_repository_open_ext` with extended options
that control how searching for a repository will be done.  The
existing `git_repository_open` and `git_repository_discover` are
reimplemented on top of it.  We may want to change the default
behavior of `git_repository_open` but this commit does not do that.

Improve support for "gitdir" files where the work dir is separate
from the repo and support for the "separate-git-dir" config.  Also,
add support for opening repos created with `git-new-workdir` script
(although I have only confirmed that they can be opened, not that
all functions work correctly).

There are also a few minor changes that came up:

- Fix `git_path_prettify` to allow in-place prettifying.

- Fix `git_path_root` to support backslashes on Win32.  This fix
  should help many repo open/discover scenarios - it is the one
  function called when opening before prettifying the path.

- Tweak `git_config_get_string` to set the "out" pointer to NULL
  if the config value is not found.  Allows some other cleanup.

- Fix a couple places that should have been calling
  `git_repository_config__weakptr` and were not.

- Fix `cl_git_sandbox_init` clar helper to support bare repos.
2012-04-11 12:11:35 -07:00
Russell Belfer
95dfb031f7 Improve config handling for diff,submodules,attrs
This adds support for a bunch of core.* settings that affect
diff and status, plus fixes up some incorrect implementations
of those settings from before.  Also, this cleans up the
handling of config settings in the new submodules code and
in the old attrs/ignore code.
2012-03-30 14:40:50 -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
ab43ad2fd8 Convert attr and other files to new errors
This continues to add other files to the new error handling
style.  I think the only real concerns here are that there are
a couple of error return cases that I have converted to asserts,
but I think that it was the correct thing to do given the new
error style.
2012-03-14 11:07:14 -07:00
Vicent Martí
9d160ba855 diff: Fix rebase breackage 2012-03-06 01:37:56 +01:00
Russell Belfer
854eccbb2d Clean up GIT_UNUSED macros on all platforms
It turns out that commit 31e9cfc4cbcaf1b38cdd3dbe3282a8f57e5366a5
did not fix the GIT_USUSED behavior on all platforms.  This commit
walks through and really cleans things up more thoroughly, getting
rid of the unnecessary stuff.

To remove the use of some GIT_UNUSED, I ended up adding a couple
of new iterators for hashtables that allow you to iterator just
over keys or just over values.

In making this change, I found a bug in the clar tests (where we
were doing *count++ but meant to do (*count)++ to increment the
value).  I fixed that but then found the test failing because it
was not really using an empty repo.  So, I took some of the code
that I wrote for iterator testing and moved it to clar_helpers.c,
then made use of that to make it easier to open fixtures on a
per test basis even within a single test file.
2012-03-02 15:51:55 -08: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
Russell Belfer
e8c96ed2a7 Add unit tests for recent bug fixes
Add unit tests to confirm ignore directory pattern matches and
to confirm that ignore and attribute files are loaded properly
into the attribute file cache.
2012-02-01 12:30:35 -08:00
Russell Belfer
62a1f713de Fix memory leak in attr file cache
Actually look for the file by the same cache key that we
store it under.  Rocket science!
2012-02-01 11:54:42 -08:00
Russell Belfer
adc9bdb3b1 Fix attr path is_dir check
When building an attr path object, the code that checks if the
file is a directory was evaluating the file as a relative path
to the current working directory, instead of using the repo root.
This lead to inconsistent behavior.
2012-01-31 13:59:32 -08:00
Russell Belfer
63ab73bec0 Merge branch 'fix-subdir-attr-paths' into development
This resolves issue #535 and issue #533.
2012-01-20 11:13:17 -08:00
Russell Belfer
1744fafec0 Move path related functions from fileops to path
This takes all of the functions that look up simple data about
paths (such as `git_futils_isdir`) and moves them over to path.h
(becoming `git_path_isdir`).  This leaves fileops.h just with
functions that actually manipulate the filesystem or look at
the file contents in some way.

As part of this, the dir.h header which is really just for win32
support was moved into win32 (with some minor changes).
2012-01-17 15:49:47 -08:00
Russell Belfer
83bfbdf593 Remove poor git__removechar function
Going back over this, the git__removechar function was not
needed (only invoked once) and is actually mislabeled.  As
implemented, it really only made sense for removing backslash
characters, since two of the "removed" characters in a row
would include the second one -- i.e. it really implements
stripping backslash-escaped strings where a backslash allows
internal whitespace in a word.
2012-01-16 18:00:18 -08:00
Russell Belfer
a51cd8e6f6 Fix handling of relative paths for attrs
Per issue #533, the handling of relative paths in attribute
and ignore files was not right.  Fixed this by pre-joining
the relative path of the attribute/ignore file onto the match
string when a full path match is required.

Unfortunately, fixing this required a bit more code than I
would have liked because I had to juggle things around so that
the fnmatch parser would have sufficient information to prepend
the relative path when it was needed.
2012-01-16 16:58:27 -08:00
Russell Belfer
cfbc880d8a Patch cleanup for merge
After reviewing the gitignore support with Vicent, we came up
with a list of minor cleanups to prepare for merge, including:

* checking git_repository_config error returns
* renaming git_ignore_is_ignored and moving to status.h
* fixing next_line skipping to include \r skips
* commenting on where ignores are and are not included
2012-01-16 15:16:44 -08: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
0cfcff5daa Convert git_path_walk_up to regular function
This gets rid of the crazy macro version of git_path_walk_up
and makes it into a normal function that takes a callback
parameter.  This turned out not to be too messy.
2012-01-11 20:41:55 -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
nulltoken
acb159e191 Fix MSVC compilation warnings 2012-01-04 18:17:55 +01:00
Russell Belfer
c6d2a2c094 Fixed up memory leaks 2011-12-29 21:32:37 -08:00
Russell Belfer
73b51450a3 Add support for macros and cache flush API.
Add support for git attribute macro definitions.  Also, add
support for cache flush API to clear the attribute file content
cache when needed.

Additionally, improved the handling of global and system files,
making common utility functions in fileops and converting config
and attr to both use the common functions.

Adds a bunch more tests and fixed some memory leaks.  Note that
adding macros required me to use refcounted attribute assignment
definitions, which complicated, but probably improved memory usage.
2011-12-29 00:01:10 -08:00
Russell Belfer
ee1f0b1aed Add APIs for git attributes
This adds APIs for querying git attributes.  In addition to
the new API in include/git2/attr.h, most of the action is in
src/attr_file.[hc] which contains utilities for dealing with
a single attributes file, and src/attr.[hc] which contains
the implementation of the APIs that merge all applicable
attributes files.
2011-12-20 16:32:58 -08:00