Commit Graph

199 Commits

Author SHA1 Message Date
Russell Belfer
1ca3e49f88 Clean up newly introduced warnings
The attempt to "clean up warnings" seems to have introduced some
new warnings on compliant compilers.  This fixes those in a way
that I suspect will also be okay for the non-compliant compilers.

Also this fixes what appears to be an extra semicolon in the
repo initialization template dir handling (and as part of that
fix, handles the case where an error occurs correctly).
2013-09-23 21:41:43 -07:00
Linquize
66566516ce Fix warning 2013-09-19 23:14:06 +08:00
Russell Belfer
f240acce86 Add more file mode permissions macros
This adds some more macros for some standard operations on file
modes, particularly related to permissions, and then updates a
number of places around the code base to use the new macros.
2013-09-05 11:20:12 -07:00
Carlos Martín Nieto
3d27687475 index: report when it's locked
Report the index being locked with its own error code in order to be
able to differentiate, as a locked index is typically the result of a
crashed process or concurrent access, both of which often require user
intervention to fix.
2013-08-19 10:30:44 +02:00
Edward Thomson
57f31f058c Fixes to safely reading the index
Avoid wrapping around extension size when reading, avoid walking off
the end of the buffer when reading names.
2013-08-08 12:32:23 -05:00
Russell Belfer
a16e41729d Fix rename detection to use actual blob size
The size data in the index may not reflect the actual size of the
blob data from the ODB when content filtering comes into play.
This commit fixes rename detection to use the actual blob size when
calculating data signatures instead of the value from the index.

Because of a misunderstanding on my part, I first converted the
git_index_add_bypath API to use the post-filtered blob data size
in creating the index entry.  I backed that change out, but I
kept the overall refactoring of that routine and the new internal
git_blob__create_from_paths API because it eliminates an extra
stat() call from the code that adds a file to the index.

The existing tests actually cover this code path, at least when
running on Windows, so at this point I'm not adding new tests to
cover the changes.
2013-07-25 12:27:39 -07:00
Rémi Duraffort
8d6ef4bf78 index: fix potential memory leaks 2013-07-15 16:29:09 +02:00
Russell Belfer
41f1f9d732 Add API to get path to index file 2013-07-10 12:14:13 -07:00
Russell Belfer
d2ce27dd49 Add public API for pathspec matching
This adds a new public API for compiling pathspecs and matching
them against the working directory, the index, or a tree from the
repository.  This also reworks the pathspec internals to allow the
sharing of code between the existing internal usage of pathspec
matching and the new external API.

While this is working and the new API is ready for discussion, I
think there is still an incorrect behavior in which patterns are
always matched against the full path of an entry without taking
the subdirectories into account (so "s*" will match "subdir/file"
even though it wouldn't with core Git).  Further enhancements are
coming, but this was a good place to take a functional snapshot.
2013-07-10 20:50:31 +02:00
Russell Belfer
178aa39cc2 Be more thread aware with some index updates
The index isn't really thread safe for the most part, but we can
easily be more careful and avoid double frees and the like, which
are serious problems (as opposed to a lookup which might return
the incorrect value but if the index in being updated, that is
much harder to avoid).
2013-07-03 11:42:43 -07:00
Russell Belfer
22b6b82f2c Add status flags to force output sort order
Files in status will, be default, be sorted according to the case
insensitivity of the filesystem that we're running on.  However,
in some cases, this is not desirable.  Even on case insensitive
file systems, 'git status' at the command line will generally use
a case sensitive sort (like 'ls').  Some GUIs prefer to display a
list of file case insensitively even on case-sensitive platforms.

This adds two new flags: GIT_STATUS_OPT_SORT_CASE_SENSITIVELY
and GIT_STATUS_OPT_SORT_CASE_INSENSITIVELY that will override the
default sort order of the status output and give the user control.
This includes tests for exercising these new options and makes
the examples/status.c program emulate core Git and always use a
case sensitive sort.
2013-06-20 12:16:06 -07:00
Russell Belfer
7863523a1b Add tests and fix use of freed memory
This adds some tests for updating the index and having it remove
items to make sure that the iteration over the index still works
even as earlier items are removed.

In testing with valgrind, this found a path that would use the
path string from the index entry after it had been freed.  The
bug fix is simply to copy the path of the index entry before
doing any actual index manipulation.
2013-06-19 15:54:19 -07:00
Russell Belfer
f30fff45a7 Add index pathspec-based operations
This adds three new public APIs for manipulating the index:

1. `git_index_add_all` is similar to `git add -A` and will add
   files in the working directory that match a pathspec to the
   index while honoring ignores, etc.
2. `git_index_remove_all` removes files from the index that match
   a pathspec.
3. `git_index_update_all` updates entries in the index based on
   the current contents of the working directory, either added
   the new information or removing the entry from the index.
2013-06-19 15:27:25 -07:00
Russell Belfer
6ea999bb88 Make index_insert keep existing case
In a case insensitive index, if you attempt to add a file from
disk with a different case pattern, the old case pattern in the
index should be preserved.

This fixes that (and a couple of minor warnings).
2013-06-17 10:03:49 -07:00
Vicent Marti
6de9b2ee14 util: It's called memzero 2013-06-12 21:10:33 +02:00
Vicent Marti
eb58e2d0be Merge remote-tracking branch 'arrbee/minor-paranoia' into development 2013-06-12 21:05:48 +02:00
Russell Belfer
2f77d8f15d Fix some memory leaks 2013-06-10 14:16:56 -07:00
Russell Belfer
3e9e6cdaff Add safe memset and use it
This adds a `git__memset` routine that will not be optimized away
and updates the places where I memset() right before a free() call
to use it.
2013-06-07 09:54:33 -07:00
Russell Belfer
03a8907078 Make git_index_read_tree preserve stat cache
Instead of just blowing away the stat cache data when loading a
new tree into the index, this checks if each loaded item has a
corresponding existing item with the same OID and if so, copies
the stat data from the old item to the new one so it will not be
blown away.
2013-05-31 21:49:40 -07:00
Russell Belfer
f658dc433c Zero memory for major objects before freeing
By zeroing out the memory when we free larger objects (i.e. those
that serve as collections of other data, such as repos, odb, refdb),
I'm hoping that it will be easier for libgit2 bindings to find
errors in their object management code.
2013-05-31 14:09:58 -07:00
Edward Thomson
8c2458bea6 improve test for index extension truncation 2013-05-31 11:41:33 -05:00
Russell Belfer
43efc4493d Ensure reuc vector is always valid
In theory, if there was a problem reading the REUC data, the
read_reuc() routine could have left uninitialized and invalid
data in the git_index vector.  This moves the line that inserts a
new entry into the vector down to the bottom of the routine so we
know all the content is already valid.  Also, per @linquize, this
uses calloc to ensure no uninitialized data.
2013-05-24 07:11:22 -05:00
Edward Thomson
0e0108f73f introduce git_conflict_iterator 2013-05-17 16:10:48 -05:00
Russell Belfer
57908bb3a3 Ensure reuc vector is always valid
In theory, if there was a problem reading the REUC data, the
read_reuc() routine could have left uninitialized and invalid
data in the git_index vector.  This moves the line that inserts a
new entry into the vector down to the bottom of the routine so we
know all the content is already valid.  Also, per @linquize, this
uses calloc to ensure no uninitialized data.
2013-05-16 11:03:55 -07:00
Vicent Martí
7159620044 Merge pull request #1588 from arrbee/fixes-for-checkout-and-diff
Bug fixes for checkout and diff
2013-05-15 15:47:46 -07:00
Russell Belfer
72b3dd4a5c Use GIT_IDXENTRY_STAGE macro
Since I added the GIT_IDXENTRY_STAGE macro to extract the stage
from a git_index_entry, we probably don't need an internal inline
function to do the same thing.
2013-05-15 15:23:33 -07:00
Russell Belfer
dcb0f7c061 Fix checkout of submodules with no .gitmodules
It is possible for there to be a submodule in a repository with
no .gitmodules file (for example, if the user forgot to commit
the .gitmodules file).  In this case, core Git will just create
an empty directory as a placeholder for the submodule but
otherwise ignore it.  We were generating an error and stopping
the checkout.  This makes our behavior match that of core git.
2013-05-15 14:54:02 -07:00
nulltoken
1fed6b07f0 Fix trailing whitespaces 2013-05-15 22:41:30 +02:00
Vicent Martí
03c28d92d0 Merge pull request #1526 from arrbee/cleanup-error-return-without-msg
Make sure error messages are set for most error returns
2013-05-06 06:45:53 -07:00
Edward Thomson
d80416384f fix some leaks 2013-05-02 20:43:45 -05:00
Russell Belfer
81b7dec4ee Fix some compile warnings and trailing whitespace 2013-05-02 03:06:34 -07:00
Vicent Marti
e1807113c4 merge: Warning noise 2013-05-01 15:31:23 +02:00
Russell Belfer
ae99f5e2ab Make sure error messages get set 2013-05-01 04:57:24 -07:00
Edward Thomson
75d1c8c664 move NAME and REUC extensions to sys/ 2013-04-30 17:33:11 -05:00
Edward Thomson
0462fba538 renames! 2013-04-30 16:01:11 -05:00
Edward Thomson
bec65a5e99 merge! 2013-04-30 15:31:31 -05:00
Russell Belfer
b7f167da29 Make git_oid_cmp public and add git_oid__cmp 2013-04-29 13:52:12 -07:00
Russell Belfer
eac76c230c Use config cache where possible
This converts many of the config lookups that are done around the
library to use the repository config cache.  This was everything I
could find that wasn't part of diff (which requires a larger fix).
2013-04-23 12:57:30 -07:00
Russell Belfer
2aee1aa416 Fix uninitialized var warnings 2013-04-18 14:59:25 -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
Russell Belfer
169dc61607 Make iterator APIs consistent with standards
The iterator APIs are not currently consistent with the parameter
ordering of the rest of the codebase.  This rearranges the order
of parameters, simplifies the naming of a number of functions, and
makes somewhat better use of macros internally to clean up the
iterator code.

This also expands the test coverage of iterator functionality,
making sure that case sensitive range-limited iteration works
correctly.
2013-03-06 16:52:01 -08:00
Vicent Martí
b8daa9e0fc Merge pull request #1380 from phkelley/index_icase
Disable ignore_case when writing the index to a tree
2013-03-04 16:19:38 -08:00
Edward Thomson
5bddabcca5 clear REUC on checkout 2013-03-04 18:10:57 -06:00
Philip Kelley
cb53669e14 Rename function to __ prefix 2013-03-01 16:38:13 -05:00
Philip Kelley
3f0d0c85d0 Disable ignore_case when writing the index to a tree 2013-03-01 15:46:21 -05:00
Edward Thomson
eb5ffd1944 add a sorter to the reuc on index creation 2013-02-21 11:00:29 -06:00
Russell Belfer
390a3c8141 Merge pull request #1190 from nulltoken/topic/reset-paths
reset: Allow the selective reset of pathspecs
2013-02-11 11:44:00 -08:00
yorah
943700ecbb Return the matched pathspec pattern in git_pathspec_match_path
Instead of returning directly the pattern as the return value, I used an
out parameter, because the function also tests if the passed pathspecs
vector is empty. If yes, it considers that the path "matches", but in
that case there is no matched pattern per se.
2013-02-07 20:44:34 +01:00
nulltoken
3cf58e6697 index: Fix indentations 2013-02-05 15:47:17 +01:00
Philip Kelley
11d9f6b304 Vector improvements and their fallout 2013-01-27 14:17:07 -05:00