src/index.c


Log

Author Commit Date CI Message
Rémi Duraffort 8d6ef4bf 2013-07-15T15:59:35 index: fix potential memory leaks
Russell Belfer 41f1f9d7 2013-06-27T16:52:00 Add API to get path to index file
Russell Belfer d2ce27dd 2013-06-24T23:16:06 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.
Russell Belfer 178aa39c 2013-07-03T11:42:43 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).
Russell Belfer 22b6b82f 2013-06-20T12:16:06 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.
Russell Belfer 7863523a 2013-06-19T15:54:19 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.
Russell Belfer f30fff45 2013-06-19T15:27:25 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.
Russell Belfer 6ea999bb 2013-06-13T15:52:12 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).
Vicent Marti 6de9b2ee 2013-06-12T21:10:33 util: It's called `memzero`
Vicent Marti eb58e2d0 2013-06-12T21:05:48 Merge remote-tracking branch 'arrbee/minor-paranoia' into development
Russell Belfer 2f77d8f1 2013-06-10T14:16:56 Fix some memory leaks
Russell Belfer 3e9e6cda 2013-06-07T09:54:33 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.
Russell Belfer 03a89070 2013-05-31T21:49:40 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.
Russell Belfer f658dc43 2013-05-31T14:09:58 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.
Edward Thomson 8c2458be 2013-05-31T11:41:33 improve test for index extension truncation
Russell Belfer 43efc449 2013-05-16T11:03:55 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.
Edward Thomson 0e0108f7 2013-05-17T15:59:57 introduce git_conflict_iterator
Russell Belfer 57908bb3 2013-05-16T11:03:55 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.
Russell Belfer 96c01991 2013-05-15T09:24:51 Remove entry dup/free functions and fix comments This removes the functions to duplicate and free copies of a git_index_entry and updates the comments to explain that you should just use the public definition of the struct as needed.
Russell Belfer 797dfb28 2013-05-13T16:09:33 Add APIs to dup and free git_index_entrys This adds git_index_entry_dup to make a copy of an existing entry and git_index_entry_free to release the memory of the copy. It also updates the documentation for git_index_get_bypath and git_index_get_byindex to make it clear that the returned structure should *not* be modified.
Vicent Martí 71596200 2013-05-15T15:47:46 Merge pull request #1588 from arrbee/fixes-for-checkout-and-diff Bug fixes for checkout and diff
Russell Belfer 72b3dd4a 2013-05-15T15:23:33 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.
Russell Belfer dcb0f7c0 2013-05-15T14:54:02 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.
nulltoken 1fed6b07 2013-05-13T21:57:37 Fix trailing whitespaces
Vicent Martí 03c28d92 2013-05-06T06:45:53 Merge pull request #1526 from arrbee/cleanup-error-return-without-msg Make sure error messages are set for most error returns
Edward Thomson d8041638 2013-05-02T17:22:13 fix some leaks
Russell Belfer 81b7dec4 2013-05-02T03:06:34 Fix some compile warnings and trailing whitespace
Vicent Marti e1807113 2013-05-01T15:31:23 merge: Warning noise
Russell Belfer ae99f5e2 2013-05-01T04:57:24 Make sure error messages get set
Edward Thomson 75d1c8c6 2013-04-30T17:33:11 move NAME and REUC extensions to sys/
Edward Thomson 0462fba5 2013-04-30T14:56:41 renames!
Edward Thomson bec65a5e 2013-04-01T22:16:21 merge!
Russell Belfer b7f167da 2013-04-29T13:52:12 Make git_oid_cmp public and add git_oid__cmp
Russell Belfer eac76c23 2013-04-22T14:27:36 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).
Russell Belfer 2aee1aa4 2013-04-18T14:35:13 Fix uninitialized var warnings
Arkadiy Shapkin 10c06114 2013-03-17T04:46:46 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
Russell Belfer 169dc616 2013-03-05T16:10:05 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.
Vicent Martí b8daa9e0 2013-03-04T16:19:38 Merge pull request #1380 from phkelley/index_icase Disable ignore_case when writing the index to a tree
Edward Thomson 5bddabcc 2013-03-04T17:40:48 clear REUC on checkout
Philip Kelley cb53669e 2013-03-01T16:38:13 Rename function to __ prefix
Philip Kelley 3f0d0c85 2013-03-01T15:44:18 Disable ignore_case when writing the index to a tree
Edward Thomson eb5ffd19 2013-02-21T11:00:29 add a sorter to the reuc on index creation
Russell Belfer 390a3c81 2013-02-11T11:44:00 Merge pull request #1190 from nulltoken/topic/reset-paths reset: Allow the selective reset of pathspecs
yorah 943700ec 2013-01-18T16:37:13 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.
nulltoken 3cf58e66 2013-01-15T16:12:12 index: Fix indentations
Philip Kelley 11d9f6b3 2013-01-27T14:17:07 Vector improvements and their fallout
Scott J. Goldman 5425097f 2013-01-24T18:53:08 index: Speed up loading a tree into the index The index is empty; repeated tree entries cannot collide. cc github/gitrpc#83
Edward Thomson 25743bd7 2013-01-12T13:47:56 add an index_remove_bypath that removes conflicts, renamed add_from_workdir to match
Edward Thomson eb3c247a 2013-01-10T11:56:02 REUC needs to handle empty sides
Edward Thomson 359fc2d2 2013-01-08T17:07:25 update copyrights
Russell Belfer 7fc00435 2013-01-03T15:48:52 Add index API to remove all files in a directory This adds the git_index_remove_directory API plus tests.
Russell Belfer 6fee906c 2012-12-18T15:13:11 missing error message is confusing
Philip Kelley 27fe6efe 2013-01-04T13:48:08 Fix git_index sorting with core.ignorecase in git_index_read
Edward Thomson e759b072 2012-12-12T17:54:12 don't walk off the end of the index
Russell Belfer 9950d27a 2012-12-06T13:26:58 Clean up iterator APIs This removes the need to explicitly pass the repo into iterators where the repo is implied by the other parameters. This moves the repo to be owned by the parent struct. Also, this has some iterator related updates to the internal diff API to lay the groundwork for checkout improvements.
Russell Belfer a8122b5d 2012-11-21T15:39:03 Fix warnings on Win64 build
Russell Belfer 4604a654 2012-11-21T11:57:06 update internal index API to avoid cast
Russell Belfer 16248ee2 2012-11-21T11:03:07 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.
Ben Straub f45d51ff 2012-11-20T19:57:46 API updates for index.h
Russell Belfer e120123e 2012-11-20T14:01:46 API review / update for tree.h
Vicent Marti cfbe4be3 2012-11-17T19:54:47 More external API cleanup Conflicts: src/branch.c tests-clar/refs/branches/create.c
Russell Belfer bad68c0a 2012-11-13T14:02:59 Add iterator for git_index object The index iterator could previously only be created from a repo object, but this allows creating an iterator from a `git_index` object instead (while keeping, though renaming, the old function).
Carlos Martín Nieto 6132a54e 2012-11-13T16:13:10 Fix a few valgrind errors
Vicent Martí aa1c3b58 2012-11-13T14:13:47 Merge pull request #1016 from arrbee/fix-checkout-dir-removal Update checkout with new strategies & behavior
Vicent Martí d18713fb 2012-11-10T20:24:53 Merge pull request #1056 from nulltoken/duplicate-tree-entries Duplicate tree entries
nulltoken 95d73de1 2012-11-10T21:10:49 index: prefer INDEX_OWNER usage
nulltoken 33f95a9b 2012-11-10T21:01:05 index: refine add_from_workdir() error report
nulltoken 69c068c7 2012-11-10T20:42:45 index: make git_index_new() work with a NULL path
Russell Belfer 757b4065 2012-11-09T14:01:44 Fix warnings and valgrind issues This fixes some various warnings that showed up in Travis and a couple uses of uninitialized memory and one memory leak.
Russell Belfer ad9a921b 2012-11-08T17:05:07 Rework checkout with new strategy options This is a major reworking of checkout strategy options. The checkout code is now sensitive to the contents of the HEAD tree and the new options allow you to update the working tree so that it will match the index content only when it previously matched the contents of the HEAD. This allows you to, for example, to distinguish between removing files that are in the HEAD but not in the index, vs just removing all untracked files. Because of various corner cases that arise, etc., this required some additional capabilities in rmdir and other utility functions. This includes the beginnings of an implementation of code to read a partial tree into the index based on a pathspec, but that is not enabled because of the possibility of creating conflicting index entries.
Russell Belfer 55cbd05b 2012-11-08T16:56:34 Some diff refactorings to help code reuse There are some diff functions that are useful in a rewritten checkout and this lays some groundwork for that. This contains three main things: 1. Share the function diff uses to calculate the OID for a file in the working directory (now named `git_diff__oid_for_file` 2. Add a `git_diff__paired_foreach` function to iterator over two diff lists concurrently. Convert status to use it. 3. Move all the string/prefix/index entry comparisons into function pointers inside the `git_diff_list` object so they can be switched between case sensitive and insensitive versions. This makes them easier to reuse in various functions without replicating logic. As part of this, move a couple of index functions out of diff.c and into index.c.
nulltoken 7cc1bf0f 2012-11-08T21:08:59 index: Introduce git_index_has_conflicts()
Edward Thomson 050cf8b8 2012-11-02T01:01:21 freeing index entries would be helpful
Vicent Marti 1e808f9c 2012-11-01T20:28:28 index: Add `git_index_new`
Vicent Marti 43eeca04 2012-11-01T20:24:43 index: Fix tests
Vicent Marti 276ea401 2012-11-01T20:15:53 index: Add git_index_write_tree
Vicent Marti 8ff0f325 2012-10-31T22:26:57 index: Switch to git_futils_filestamp
Russell Belfer 744cc03e 2012-10-30T12:10:36 Add git_config_refresh() API to reload config This adds a new API that allows users to reload the config if the file has changed on disk. A new config callback function to refresh the config was added. The modified time and file size are used to test if the file needs to be reloaded (and are now stored in the disk backend object). In writing tests, just using mtime was a problem / race, so I wanted to check file size as well. To support that, I extended `git_futils_readbuffer_updated` to optionally check file size in addition to mtime, and I added a new function `git_filebuf_stats` to fetch the mtime and size for an open filebuf (so that the config could be easily refreshed after a write). Lastly, I moved some similar file checking code for attributes into filebuf. It is still only being used for attrs, but it seems potentially reusable, so I thought I'd move it over.
Edward Thomson f45ec1a0 2012-10-29T20:04:21 index refactoring
nulltoken b1be9dd0 2012-10-03T12:09:17 index: introduce git_index_owner()
Ben Straub 7d222e13 2012-10-24T13:29:14 Network progress: rename things git_indexer_stats and friends -> git_transfer_progress* Also made git_transfer_progress members more sanely named.
nulltoken 0ae81fc4 2012-10-17T15:30:22 index: remove read_tree() progress indicator git_index_read_tree() was exposing a parameter to provide the user with a progress indicator. Unfortunately, due to the recursive nature of the tree walk, the maximum number of items to process was unknown. Thus, the indicator was only counting processed entries, without providing any information how the number of remaining items.
Philip Kelley ec40b7f9 2012-09-17T15:42:41 Support for core.ignorecase
authmillenon 0e2dd29b 2012-09-04T12:07:51 Fix logical error in git_index_set_caps
Vicent Martí f98c32f3 2012-08-19T01:26:06 Merge pull request #778 from ben/clone Clone
Vicent Marti c07d9c95 2012-08-09T15:33:04 oid: Explicitly include `oid.h` for the inlined CMP
Ben Straub 4bf51156 2012-07-30T14:52:46 Enable stats on git_index_read_tree. Replace with the contents of git_index_read_tree_with_stats() and improve documentation comments.
Ben Straub f1587b97 2012-07-30T14:37:40 Checkout: use git_index_read_tree_with_stats. New variant of git_index_read_tree that fills in the 'total' field of a git_indexer_stats struct as it's walking the tree.
nulltoken b8457baa 2012-07-24T07:57:58 portability: Improve x86/amd64 compatibility
Vicent Marti 0e2fcca8 2012-06-29T02:21:12 tree: Bring back `entry_bypath` Smaller, simpler, faster.
Russell Belfer da825c92 2012-06-19T14:27:02 Make index add/append support core.filemode flag This fixes git_index_add and git_index_append to behave more like core git, preserving old filemode data in the index when adding and/or appending with core.filemode = false. This also has placeholder support for core.symlinks and core.ignorecase, but those flags are not implemented (well, symlinks has partial support for preserving mode information in the same way that git does, but it isn't tested).
Vicent Martí 904b67e6 2012-05-18T01:48:50 errors: Rename error codes
Vicent Martí e172cf08 2012-05-18T01:21:06 errors: Rename the generic return codes
Vicent Martí 9d0011fd 2012-05-16T19:23:47 tree: Naming conventions
Russell Belfer 41a82592 2012-05-15T14:17:39 Ranged iterators and rewritten git_status_file The goal of this work is to rewrite git_status_file to use the same underlying code as git_status_foreach. This is done in 3 phases: 1. Extend iterators to allow ranged iteration with start and end prefixes for the range of file names to be covered. 2. Improve diff so that when there is a pathspec and there is a common non-wildcard prefix of the pathspec, it will use ranged iterators to minimize excess iteration. 3. Rewrite git_status_file to call git_status_foreach_ext with a pathspec that covers just the one file being checked. Since ranged iterators underlie the status & diff implementation, this is actually fairly efficient. The workdir iterator does end up loading the contents of all the directories down to the single file, which should ideally be avoided, but it is pretty good.
Russell Belfer 7c7ff7d1 2012-03-19T16:10:11 Migrate index, oid, and utils to new errors This includes a few cleanups that came up while converting these files. This commit introduces a could new git error classes, including the catchall class: GITERR_INVALID which I'm using as the class for invalid and out of range values which are detected at too low a level of library to use a higher level classification. For example, an overflow error in parsing an integer or a bad letter in parsing an OID string would generate an error in this class.
Russell Belfer deafee7b 2012-03-14T17:36:15 Continue error conversion This converts blob.c, fileops.c, and all of the win32 files. Also, various minor cleanups throughout the code. Plus, in testing the win32 build, I cleaned up a bunch (although not all) of the warnings with the 64-bit build.
Russell Belfer ae9e29fd 2012-03-06T16:14:31 Migrating diff to new error handling Ended up migrating a bunch of upstream functions as well including vector, attr_file, and odb in order to get this to work right.
Vicent Martí 1a481123 2012-02-17T00:13:34 error-handling: References Yes, this is error handling solely for `refs.c`, but some of the abstractions leak all ofer the code base.
Vicent Martí 13224ea4 2012-02-27T04:28:31 buffer: Unify `git_fbuffer` and `git_buf` This makes so much sense that I can't believe it hasn't been done before. Kill the old `git_fbuffer` and read files straight into `git_buf` objects. Also: In order to fully support 4GB files in 32-bit systems, the `git_buf` implementation has been changed from using `ssize_t` for storage and storing negative values on allocation failure, to using `size_t` and changing the buffer pointer to a magical pointer on allocation failure. Hopefully this won't break anything.