summaryrefslogtreecommitdiff
path: root/src/iterator.c
Commit message (Collapse)AuthorAgeFilesLines
* Merge pull request #3165 from ethomson/downcaseCarlos Martín Nieto2015-06-081-4/+4
|\ | | | | Downcase
| * git__tolower: a tolower() that isn't dumbEdward Thomson2015-05-291-4/+4
| | | | | | | | | | | | | | | | Some brain damaged tolower() implementations appear to want to take the locale into account, and this may require taking some insanely aggressive lock on the locale and slowing down what should be the most trivial of trivial calls for people who just want to downcase ASCII.
* | introduce `git_index_entry_is_conflict`Edward Thomson2015-05-281-1/+1
| | | | | | | | | | | | | | | | | | It's not always obvious the mapping between stage level and conflict-ness. More importantly, this can lead otherwise sane people to write constructs like `if (!git_index_entry_stage(entry))`, which (while technically correct) is unreadable. Provide a nice method to help avoid such messy thinking.
* | index iterator: optionally include conflictsEdward Thomson2015-05-281-7/+11
|/
* git_path_diriter: use FindFirstFile in win32Edward Thomson2015-05-011-1/+1
| | | | | | | Using FindFirstFile and FindNextFile in win32 allows us to use the directory information that is returned, instead of us having to get the file attributes all over again, which is a distinct cost savings on win32.
* git_path_diriter: next shouldn't take path ptrEdward Thomson2015-05-011-1/+1
| | | | | | | | The _next method shouldn't take a path pointer (and a path_len pointer) as 100% of current users use the full path and ignore the filename. Plus let's add some docs and a unit test.
* git_path_dirload_with_stat: moved to fs_iteratorEdward Thomson2015-05-011-7/+116
|
* git_win32_path_dirload_with_stat: removedEdward Thomson2015-05-011-16/+1
|
* Improvements to status performance on Windows.J Wyman2015-04-281-1/+17
| | | | Changed win32/path_w32.c to utilize NTFS' FindFirst..FindNext data instead of doing an lstat per file. Avoiding unnecessary directory opens and file scans reduces IO, improving overall performance. Effect is magnified due to NTFS being a kernel mode file system (as opposed to user mode).
* Improvements to ignore performance on Windows.J Wyman2015-04-281-5/+16
| | | | Minimizing the number directory and file opens, minimizes the amount of IO thus reducing the overall cost of performing ignore operations.
* Make our overflow check look more like gcc/clang'sEdward Thomson2015-02-131-5/+2
| | | | | | | | | Make our overflow checking look more like gcc and clang's, so that we can substitute it out with the compiler instrinsics on platforms that support it. This means dropping the ability to pass `NULL` as an out parameter. As a result, the macros also get updated to reflect this as well.
* allocations: test for overflow of requested sizeEdward Thomson2015-02-121-3/+8
| | | | | Introduce some helper macros to test integer overflow from arithmetic and set error message appropriately.
* Plug leaksCarlos Martín Nieto2014-11-231-0/+1
| | | | Valgrind is now clean except for libssl and libgcrypt.
* iterator: submodules are determined by an index or treecmn/submodule-and-dirCarlos Martín Nieto2014-11-071-1/+70
| | | | | | | | | | | | 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.
* Improve checks for ignore containmentrb/how-broken-can-ignores-beRussell Belfer2014-05-061-18/+48
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The diff code was using an "ignored_prefix" directory to track if a parent directory was ignored that contained untracked files alongside tracked files. Unfortunately, when negative ignore rules were used for directories inside ignored parents, the wrong rules were applied to untracked files inside the negatively ignored child directories. This commit moves the logic for ignore containment into the workdir iterator (which is a better place for it), so the ignored-ness of a directory is contained in the frame stack during traversal. This allows a child directory to override with a negative ignore and yet still restore the ignored state of the parent when we traverse out of the child. Along with this, there are some problems with "directory only" ignore rules on container directories. Given "a/*" and "!a/b/c/" (where the second rule is a directory rule but the first rule is just a generic prefix rule), then the directory only constraint was having "a/b/c/d/file" match the first rule and not the second. This was fixed by having ignore directory-only rules test a rule against the prefix of a file with LEADINGDIR enabled. Lastly, spot checks for ignores using `git_ignore_path_is_ignored` were tested from the top directory down to the bottom to deal with the containment problem, but this is wrong. We have to test bottom to top so that negative subdirectory rules will be checked before parent ignore rules. This does change the behavior of some existing tests, but it seems only to bring us more in line with core Git, so I think those changes are acceptable.
* Remove trace / add git_diff_perfdata struct + apiRussell Belfer2014-05-021-4/+1
|
* Add payloads, bitmaps to trace APIRussell Belfer2014-05-021-2/+2
| | | | | | | | | This is a proposed adjustment to the trace APIs. This makes the trace levels into a bitmask so that they can be selectively enabled and adds a callback-level payload, plus a message-level payload. This makes it easier for me to a GIT_TRACE_PERF callbacks that are simply bypassed if the PERF level is not set.
* Add GIT_STATUS_OPT_UPDATE_INDEX and use trace APIRussell Belfer2014-05-021-2/+3
| | | | | | This adds an option to refresh the stat cache while generating status. It also rips out the GIT_PERF stuff I had an makes use of the trace API to keep statistics about what happens during diff.
* Skip diff oid calc when size definitely changedRussell Belfer2014-05-021-1/+1
| | | | | | | | | | | | | When we think the stat cache in the index seems valid and the size or mode of a file has definitely changed, then don't bother trying to recalculate the OID of the workdir bits to confirm that it is modified - just accept that it is modified. This can result in files that show as modified with no actual diff, but the behavior actually appears to match Git on the command line. This also includes a minor optimization to not perform a submodule lookup on the ".git" directory itself.
* Add build option for diff internal statisticsRussell Belfer2014-05-021-3/+7
|
* Handle explicitly ignored dir slightly differentlyrb/stash-skip-submodulesRussell Belfer2014-04-241-8/+9
| | | | | | | When considering status of untracked directories, if we find an explicitly ignored item, even if it is a directory, treat the parent as an IGNORED item. It was accidentally being treated as an EMPTY item because we were not looking into the ignored subdir.
* Treat ignored, empty, and untracked dirs differentRussell Belfer2014-04-231-6/+11
| | | | | | In the iterator, distinguish between ignores and empty directories so that diff and status can ignore empty directories, but checkout and stash can treat them as untracked items.
* Make checkout match diff for untracked/ignored dirRussell Belfer2014-04-221-0/+68
| | | | | | | | | | | | | | | | | | When diff finds an untracked directory, it emulates Git behavior by looking inside the directory to see if there are any untracked items inside it. If there are only ignored items inside the dir, then diff considers it ignored, even if there is no direct ignore rule for it. Checkout was not copying this behavior - when it found an untracked directory, it just treated it as untracked. Unfortunately, when combined with GIT_CHECKOUT_REMOVE_UNTRACKED, this made is seem that checkout (and stash, which uses checkout) was removing ignored items when you had only asked it to remove untracked ones. This commit moves the logic for advancing past an untracked dir while scanning for non-ignored items into an iterator helper fn, and uses that for both diff and checkout.
* Clean up index snapshot function namingRussell Belfer2014-04-171-4/+3
| | | | | Clear up some of the various "find" functions and the snapshot API naming to be things I like more.
* Decouple index iterator sort from indexRussell Belfer2014-04-171-5/+9
| | | | | | | | This makes the index iterator honor the GIT_ITERATOR_IGNORE_CASE and GIT_ITERATOR_DONT_IGNORE_CASE flags without modifying the index data itself. To take advantage of this, I had to export a number of the internal index entry comparison functions. I also wrote some new tests to exercise the capability.
* Add index snapshot and use it for iteratorRussell Belfer2014-04-171-13/+22
|
* Some index internals refactoringRussell Belfer2014-04-171-2/+4
| | | | | | | | Again, laying groundwork for some index iterator changes, this contains a bunch of code refactorings for index internals that should make it easier down the line to add locking around index modifications. Also this removes the redundant prefix_position function and fixes some potential memory leaks.
* CleanupsRussell Belfer2014-03-311-1/+1
|
* Fix submodule sorting in workdir iteratorRussell Belfer2014-03-311-16/+25
| | | | | | | | | With the changes to how git_path_dirload_with_stat handles things that look like submodules, submodules could end up sorted in the wrong order with the workdir iterator. This moves the submodule check earlier in the iterator processing of a new directory so that the submodule name updates will happen immediately and the sort order will be correct.
* Update behavior for untracked sub-reposRussell Belfer2014-03-251-2/+2
| | | | | | | | | | | When a directory containing a .git directory (or even just a plain gitlink) was found, libgit2 was going out of its way to treat it specially. This seemed like it was necessary because the diff code was not originally emulating Git's behavior for untracked directories correctly (i.e. scanning for ignored vs untracked items inside). Now that libgit2 diff mimics Git's untracked directory behavior, the special handling for contained Git repos is actually incorrect and this commit rips it out.
* index: rename an entry's id to 'id'Carlos Martín Nieto2014-01-251-1/+1
| | | | This was not converted when we converted the rest, so do it now.
* Cleanups, renames, and leak fixesRussell Belfer2013-12-121-1/+1
| | | | | | | | | 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.
* Add git_vector_free_allRussell Belfer2013-12-111-6/+1
| | | | | | 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.
* Improve GIT_EUSER handlingRussell Belfer2013-12-111-9/+3
| | | | | | | | | | | This adds giterr_user_cancel to return GIT_EUSER and clear any error message that is sitting around. As a result of using that in places, we need to be more thorough with capturing errors that happen inside a callback when used internally. To help with that, this also adds giterr_capture and giterr_restore so that when we internally use a foreach-type function that clears errors and converts them to GIT_EUSER, it is easier to restore not just the return value, but the actual error message text.
* error: Simplify giterr_detachVicent Marti2013-11-051-5/+6
|
* Preserve file error in iteratorRussell Belfer2013-11-041-0/+12
| | | | | | | | When the filesystem iterator encounters an error with a file, it returns the error but because of the cleanup code, it was in some cases erasing the error message. This uses the giterr_detach API to make sure that the actual error message is restored after the cleanup code has been run.
* More filemode cleanups for FAT on MacOSRussell Belfer2013-10-081-1/+1
| | | | | | | | | | | | | | | | | | | | | | This cleans up some additional issues. The main change is that on a filesystem that doesn't support mode bits, libgit2 will now create new blobs with GIT_FILEMODE_BLOB always instead of being at the mercy to the filesystem driver to report executable or not. This means that if "core.filemode" lies and claims that filemode is not supported, then we will ignore the executable bit from the filesystem. Previously we would have allowed it. This adds an option to the new git_repository_reset_filesystem to recurse through submodules if desired. There may be other types of APIs that would like a "recurse submodules" option, but this one is particularly useful. This also has a number of cleanups, etc., for related things including trying to give better error messages when problems come up from the filesystem. For example, the FAT filesystem driver on MacOS appears to return errno EINVAL if you attempt to write a filename with invalid UTF-8 in it. We try to capture that with a better error message now.
* Initial iconv hookup for precomposed unicodeRussell Belfer2013-10-031-12/+12
| | | | | | | | | | | | | | | | | | | | This hooks up git_path_direach and git_path_dirload so that they will take a flag indicating if directory entry names should be tested and converted from decomposed unicode to precomposed form. This code will only come into play on the Apple platform and even then, only when certain types of filesystems are used. This involved adding a flag to these functions which involved changing a lot of places in the code. This was an opportunity to do a bit of code cleanup here and there, for example, getting rid of the git_futils_cleanupdir_r function in favor of a simple flag to git_futils_rmdir_r to not remove the top level entry. That ended up adding depth tracking during rmdir_r which led to a safety check for infinite directory recursion. Yay. This hasn't actually been tested on the Mac filesystems where the issue occurs. I still need to get test environment for that.
* Put hooks in place for precompose in dirload fnRussell Belfer2013-10-031-1/+13
| | | | | | This doesn't actual do string precompose but it puts the hooks in place into the iterators and the git_path_dirload function so that the actual precompose work is ready to go.
* Improve building ignore file listsRussell Belfer2013-08-091-1/+1
| | | | | | | | | | | | | | | | | The routines to push and pop ignore files while traversing a directory had some issues. In particular, setting up the initial list would sometimes push an ignore file before it ought to be applied if the starting path was a directory containing an ignore file. Also, the pop function was not always matching the right part of the path and would fail to pop ignores from the list in some cases. This adds some tests that exercise a particular problematic case and then fixes the problems that I could find related to this. At some point, I'd like to isolate this ignore rule management code and rewrite it, but that's a larger project and right now, I'll opt to just try to fix the broken behaviors.
* Add target directory to checkoutRussell Belfer2013-06-211-4/+8
| | | | | | | | | | | | | | | | This adds the ability for checkout to write to a target directory instead of having to use the working directory of the repository. This makes it easier to do exports of repository data and the like. This is similar to, but not quite the same as, the --prefix option to `git checkout-index` (this will always be treated as a directory name, not just as a simple text prefix). As part of this, the workdir iterator was extended to take the path to the working directory as a parameter and fallback on the git_repository_workdir result only if it's not specified. Fixes #1332
* Reorganize diff and add basic diff driverRussell Belfer2013-06-101-0/+1
| | | | | | | | | | | | | | | | | | This is a significant reorganization of the diff code to break it into a set of more clearly distinct files and to document the new organization. Hopefully this will make the diff code easier to understand and to extend. This adds a new `git_diff_driver` object that looks of diff driver information from the attributes and the config so that things like function content in diff headers can be provided. The full driver spec is not implemented in the commit - this is focused on the reorganization of the code and putting the driver hooks in place. This also removes a few #includes from src/repository.h that were overbroad, but as a result required extra #includes in a variety of places since including src/repository.h no longer results in pulling in the whole world.
* Make iterators use GIT_ITEROVER & smart advanceRussell Belfer2013-05-311-69/+145
| | | | | | | | | | | | | | | 1. internal iterators now return GIT_ITEROVER when you go past the last item in the iteration. 2. git_iterator_advance will "advance" to the first item in the iteration if it is called immediately after creating the iterator, which allows a simpler idiom for basic iteration. 3. if git_iterator_advance encounters an error reading data (e.g. a missing tree or an unreadable file), it returns the error but also attempts to advance past the invalid data to prevent an infinite loop. Updated all tests and internal usage of iterators to account for these new behaviors.
* Fix workdir iterator leakRussell Belfer2013-04-181-7/+5
| | | | | When attempting to create a workdir iterator for a bare repo, don't leak the iterator structure.
* More filesystem iterator cleanupRussell Belfer2013-04-181-41/+42
| | | | | Renamed the callback functions and made some minor rearrangements to clean up the flow of some code.
* Make workdir iterator use filesystem iteratorRussell Belfer2013-04-181-391/+154
| | | | | | | | This adds some hooks into the filesystem iterator so that the workdir iterator can just become a wrapper around it. Then we remove most of the workdir iterator code and just have it augment the filesystem iterator with skipping .git entries, updating the ignore stack, and checking for submodules.
* Add filesystem iterator variantRussell Belfer2013-04-181-0/+301
| | | | | | This adds a new variant iterator that is a raw filesystem iterator for scanning directories from a root. There is still more work to do to blend this with the working directory iterator.
* object: Export git_object_dupVicent Marti2013-04-101-1/+1
|
* Three submodule status bug fixesRussell Belfer2013-03-181-1/+3
| | | | | | | | | | | | | | | | 1. Fix sort order problem with submodules where "mod" was sorting after "mod-plus" because they were being sorted as "mod/" and "mod-plus/". This involved pushing the "contains a .git entry" test significantly lower in the stack. 2. Reinstate behavior that a directory which contains a .git entry will be treated as a submodule during iteration even if it is not yet added to the .gitmodules. 3. Now that any directory containing .git is reported as submodule, we have to be more careful checking for GIT_EEXISTS when we do a submodule lookup, because that is the error code that is returned by git_submodule_lookup when you try to look up a directory containing .git that has no record in gitmodules or the index.
* Improved tree iterator internalsRussell Belfer2013-03-141-197/+155
| | | | | | | | | | | | | | | | | | | | | | | | 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).