Commit Graph

27 Commits

Author SHA1 Message Date
Edward Thomson
ff80b5e80b Merge pull request #2847 from jacquesg/coverity
More coverity fixes
2015-01-26 11:24:47 -06:00
Jacques Germishuys
636af2198e Return early if allocating a git_pathspec_match_list failed 2015-01-25 14:38:10 +02:00
Boris Egorov
dc5fe00c65 pathspec: do not try to dereference NULL
pathspec_match_free() should not dereference a NULL passed to it.

I found this issue when I tried to run example log program with
nonexistent branch:

./example/log help

Such call leads to segmentation fault.
2015-01-25 01:40:44 +06:00
Carlos Martín Nieto
62a617dc68 iterator: submodules are determined by an index or tree
We cannot know from looking at .gitmodules whether a directory is a
submodule or not. We need the index or tree we are comparing against to
tell us. Otherwise we have to assume the entry in .gitmodules is stale
or otherwise invalid.

Thus we pass the index of the repository into the workdir iterator, even
if we do not want to compare against it. This follows what git does,
which even for `git diff <tree>`, it will consider staged submodules as
such.
2014-11-07 08:33:27 +01:00
Russell Belfer
ac16bd0a94 Minor fixes
Only apply LEADING_DIR pattern munging to patterns in ignore and
attribute files, not to pathspecs used to select files to operate
on.  Also, allow internal macro definitions to be evaluated before
loading all external ones (important so that external ones can
make use of internal `binary` definition).
2014-04-18 15:45:59 -07:00
Russell Belfer
52bb0476a8 Clean up index snapshot function naming
Clear up some of the various "find" functions and the snapshot
API naming to be things I like more.
2014-04-17 14:43:46 -07:00
Russell Belfer
3158e2febe Fix some Windows warnings
This fixes a number of warnings with the Windows 64-bit build
including a test failure in test_repo_message__message where an
invalid pointer to a git_buf was being used.
2014-02-07 15:43:37 -08:00
Vicent Marti
53bec813a8 index: Compare with given len 2014-01-29 13:15:51 -08:00
Arthur Schreiber
63170bcae9 Fix a memory leak in git_pathspec__vinit. 2014-01-13 22:17:07 +01:00
Russell Belfer
9cfce2735d Cleanups, renames, and leak fixes
This renames git_vector_free_all to the better git_vector_free_deep
and also contains a couple of memory leak fixes based on valgrind
checks.  The fixes are specifically: failure to free global dir
path variables when not compiled with threading on and failure to
free filters from the filter registry that had not be initialized
fully.
2013-12-12 12:11:38 -08:00
Russell Belfer
fcd324c625 Add git_vector_free_all
There are a lot of places that we call git__free on each item in
a vector and then call git_vector_free on the vector itself.  This
just wraps that up into one convenient helper function.
2013-12-11 10:57:49 -08:00
Russell Belfer
3ff1d12373 Rename diff objects and split patch.h
This makes no functional change to diff but renames a couple of
the objects and splits the new git_patch (formerly git_diff_patch)
into a new header file.
2013-10-11 14:51:54 -07:00
Russell Belfer
b7b77def93 Match against file with leading ! was too broad 2013-08-09 11:20:49 -07:00
Russell Belfer
4ba64794ae Revert PR #1462 and provide alternative fix
This rolls back the changes to fnmatch parsing from commit
2e40a60e84 except for the tests
that were added.  Instead this adds couple of new flags that can
be passed in when attempting to parse an fnmatch pattern.  Also,
this changes the pathspec match logic to special case matching a
filename with a '!' prefix against a negative pattern.

This fixes the build.
2013-08-09 10:52:35 -07:00
Russell Belfer
33d532dcfa Merge pull request #1462 from yorah/fix/libgit2sharp-issue-379
status: fix handling of filenames with special prefixes
2013-08-09 09:32:06 -07:00
Russell Belfer
2b672d5b64 Add git_pathspec_match_diff API
This adds an additional pathspec API that will match a pathspec
against a diff object.  This is convenient if you want to handle
renames (so you need the whole diff and can't use the pathspec
constraint built into the diff API) but still want to tell if the
diff had any files that matched the pathspec.

When the pathspec is matched against a diff, instead of keeping
a list of filenames that matched, instead the API keeps the list
of git_diff_deltas that matched and they can be retrieved via a
new API git_pathspec_match_list_diff_entry.

There are a couple of other minor API extensions here that were
mostly for the sake of convenience and to reduce dependencies
on knowing the internal data structure between files inside the
library.
2013-07-10 20:50:33 +02:00
Russell Belfer
a8b5f116bc Fix example/log.c pathspec handling of merges
This fixes the way the example log program decides if a merge
commit should be shown when a pathspec is given.  Also makes it
easier to use the pathspec API to just check "does a tree match
anything in the pathspec" without allocating a match list.
2013-07-10 20:50:32 +02: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
e91f9a8f28 Add higher level pathspec API
Right now, setting up a pathspec to be parsed and processed
requires several data structures and a couple of API calls.  This
adds a new high level data structure that contains all the items
that you'll need and high-level APIs that do all of the setup and
all of the teardown.  This will make it easier to use pathspecs
in various places with less repeated code.
2013-06-19 15:20:59 -07:00
nulltoken
1fed6b07f0 Fix trailing whitespaces 2013-05-15 22:41:30 +02:00
yorah
2e40a60e84 status: fix handling of filenames with special prefixes
Fix libgit2/libgit2sharp#379
2013-04-15 16:39:56 +02:00
yorah
0d32f39eb8 Notify '*' pathspec correctly when diffing
I also moved all tests related to notifying in their own file.
2013-04-11 09:59:26 +02: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
Edward Thomson
359fc2d241 update copyrights 2013-01-08 17:31:27 -06: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
a277345e05 Create internal strcmp variants for function ptrs
Using the builtin strcmp and strcasecmp as function pointers is
problematic on win32.  This adds internal implementations and
divorces us from the platform linkage.
2012-11-14 22:37:13 -08:00
Russell Belfer
2e3d4b96c0 Move pathspec code in separate files
Diff uses a `git_strarray` of path specs to represent a subset
of all files to be processed.  It is useful to be able to reuse
this filtering in other places outside diff, so I've moved it
into a standalone set of utilities.
2012-11-09 13:52:07 -08:00