summaryrefslogtreecommitdiff
path: root/src/index.c
Commit message (Collapse)AuthorAgeFilesLines
* index: check racily clean entries more thoroughlyCarlos Martín Nieto2015-06-221-2/+41
| | | | | | When an entry has a racy timestamp, we need to check whether the file itself has changed since we put its entry in the index. Only then do we smudge the size field to force a check the next time around.
* index: make relative comparison use the checksum as wellcmn/index-checksumCarlos Martín Nieto2015-06-201-4/+2
| | | | | | This is used by the submodule in order to figure out if the index has changed since it last read it. Using a timestamp is racy, so let's make it use the checksum, just like we now do for reloading the index itself.
* index: use the checksum to check whether it's been modifiedCarlos Martín Nieto2015-06-191-5/+42
| | | | | | | | | | | | | We currently use a timetamp to check whether an index file has been modified since we last read it, but this is racy. If two updates happen in the same second and we read after the first one, we won't detect the second one. Instead read the SHA-1 checksum of the file, which are its last 20 bytes which gives us a sure-fire way to detect whether the file has changed since we last read it. As we're now keeping track of it, expose an accessor to this data.
* index: zero the size of racily-clean entriesCarlos Martín Nieto2015-06-161-0/+18
| | | | | | | | | | | | | | | | If a file entry has the same timestamp as the index itself, it is considered racily-clean, as it may have been modified after the index was written, but during the same second. We take extra steps to check the contents, but this is just one part of avoiding races. For files which do have changes but have not been updated in the index, updating the on-disk index means updating its timestamp, which means we would no longer recognise these entries as racy and we would trust the timestamp to tell us whether they have changed. In order to work around this, git zeroes out the file-size field in entries with the same timestamp as the index in order to force the next diff to check the contents. Do so in libgit2 as well.
* diff: introduce binary diff callbacksEdward Thomson2015-06-121-1/+1
| | | | | | | Introduce a new binary diff callback to provide the actual binary delta contents to callers. Create this data from the diff contents (instead of directly from the ODB) to support binary diffs including the workdir, not just things coming out of the ODB.
* index_add_all: remove conflicts when no wd fileEdward Thomson2015-05-281-1/+2
| | | | | | | If there exists a conflict in the index, but no file in the working directory, this implies that the user wants to accept the resolution by removing the file. Thus, remove the conflict entry from the index, instead of trying to add a (nonexistent) file.
* introduce `git_index_entry_is_conflict`Edward Thomson2015-05-281-1/+6
| | | | | | | | | 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: validate mode of new conflictsEdward Thomson2015-05-281-0/+9
|
* index: remove error message in non-error removeEdward Thomson2015-05-281-0/+3
| | | | | If `git_index_remove_bypath` does no work, and returns an OK error code, it should not set an error message.
* conflicts: when adding conflicts, remove stagedEdward Thomson2015-05-281-1/+16
| | | | | | When adding a conflict for some path, remove the staged entry. Otherwise, an illegal index (with both stage 0 and high-stage entries) would result.
* git_index_add_all: don't recurse ignored dirsEdward Thomson2015-05-201-2/+1
| | | | | No need to get reports about individual ignored files, having a single ignored directory delta is enough.
* index_add_all: include untracked files in new subdirsEdward Thomson2015-05-201-1/+4
|
* index: include TYPECHANGE in the diffCarlos Martín Nieto2015-05-141-1/+2
| | | | Without this option, we would not be able to catch exec bit changes.
* index: make add_all to act on a diffCarlos Martín Nieto2015-05-141-80/+28
| | | | | | | Instead of going through each entry we have and re-adding, which may not even be correct for certain crlf options and has bad performance, use the function which performs a diff against the worktree and try to add and remove files from that list.
* index: refactor diff-based update_all to match other appliesCarlos Martín Nieto2015-05-141-80/+87
| | | | | Refactor so we look like the code we're replacing, which should also allow us to more easily inplement add-all.
* index: use a diff to perform update_allCarlos Martín Nieto2015-05-141-2/+79
| | | | | | | | | We currently iterate over all the entries and re-add them to the index. While this provides correctness, it is wasteful as we try to re-insert files which have not changed. Instead, take a diff between the index and the worktree and only re-add those which we already know have changed.
* index: introduce git_index_read_indexEdward Thomson2015-05-111-0/+98
|
* Fix index-adding functions to know when to trust filemodes.John Fultz2015-04-211-7/+11
| | | | | | | | | | | | | | | | | | | | | | | | | The idea...sometimes, a filemode is user-specified via an explicit git_index_entry. In this case, believe the user, always. Sometimes, it is instead built up by statting the file system. In those cases, go with the existing logic we have to determine whether the file system supports all filemodes and symlinks, and make the best guess. On file systems which have full filemode and symlink support, this commit should make no difference. On others (most notably Windows), this will fix problems things like: * git_index_add and git_index_add_frombuffer() should be believed. * As a consequence, git_checkout_tree should make the filemodes in the index match the ones in the tree. * And diffs with GIT_DIFF_UPDATE_INDEX don't write the wrong filemodes. * And merges, and probably other downstream stuff now fixed, too. This makes my previous changes to checkout.c unnecessary, so they are now reverted. Also, added a test for index_entry permissions from git_index_add and git_index_add_frombuffer, both of which failed before these changes.
* Entry argument passed to git_index_add_frombuffer() should be constPierre-Olivier Latour2015-04-031-1/+1
|
* Add API to add a memory buffer to an indexDamien PROFETA2015-02-251-8/+52
| | | | | | git_index_add_frombuffer enables now to store a memory buffer in the odb and to store an entry in the index directly if the index is attached to a repository.
* Merge pull request #2831 from ethomson/merge_lockCarlos Martín Nieto2015-02-151-29/+93
|\ | | | | merge: lock index during the merge (not just checkout)
| * indexwriter: an indexwriter for repo operationsEdward Thomson2015-02-141-0/+32
| | | | | | | | | | Provide git_indexwriter_init_for_operation for the common locking pattern in merge, rebase, revert and cherry-pick.
| * git_indexwriter: lock then write the indexEdward Thomson2015-02-141-29/+61
| | | | | | | | | | | | Introduce `git_indexwriter`, to allow us to lock the index while performing additional operations, then complete the write (or abort, unlocking the index).
* | Make our overflow check look more like gcc/clang'sEdward Thomson2015-02-131-8/+9
| | | | | | | | | | | | | | | | | | 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.
* | overflow checking: don't make callers set oomEdward Thomson2015-02-121-3/+1
| | | | | | | | | | | | Have the ALLOC_OVERFLOW testing macros also simply set_oom in the case where a computation would overflow, so that callers don't need to.
* | allocations: test for overflow of requested sizeEdward Thomson2015-02-121-4/+14
|/ | | | | Introduce some helper macros to test integer overflow from arithmetic and set error message appropriately.
* Ensure git_index_entry is not NULL before trying to free itJacques Germishuys2015-01-251-0/+3
|
* index: reuc and name entrycounts should be size_tEdward Thomson2014-12-221-4/+4
| | | | | | For the REUC and NAME entries, we use size_t internally, and we take size_t for the get_byindex() functions, but the entrycount() functions strangely cast to an unsigned int instead.
* checkout: disallow bad paths on win32Edward Thomson2014-12-161-88/+31
| | | | | | | | | | | | | | | Disallow: 1. paths with trailing dot 2. paths with trailing space 3. paths with trailing colon 4. paths that are 8.3 short names of .git folders ("GIT~1") 5. paths that are reserved path names (COM1, LPT1, etc). 6. paths with reserved DOS characters (colons, asterisks, etc) These paths would (without \\?\ syntax) be elided to other paths - for example, ".git." would be written as ".git". As a result, writing these paths literally (using \\?\ syntax) makes them hard to operate with from the shell, Windows Explorer or other tools. Disallow these.
* index: Check for valid paths before creating an index entryVicent Marti2014-12-161-15/+95
|
* iterator: submodules are determined by an index or treecmn/submodule-and-dirCarlos Martín Nieto2014-11-071-1/+1
| | | | | | | | | | | | 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.
* index: write out the tree cache extensionCarlos Martín Nieto2014-10-101-6/+28
| | | | | | | | | | Keeping the cache around after read-tree is only one part of the optimisation opportunities. In order to share the cache between program instances, we need to write the TREE extension to the index. Do so, taking the opportunity to rename 'entries' to 'entry_count' to match the name given in the format description. The included test is rather trivial, but works as a sanity check.
* index: fill the tree cache when reading from a treeCarlos Martín Nieto2014-10-101-0/+8
| | | | | | When reading from a tree, we know what every tree is going to look like, so we can fill in the tree cache completely, making use of the index for modification of trees a lot quicker.
* tree-cache: move to use a pool allocatorCarlos Martín Nieto2014-10-101-2/+8
| | | | | | This simplifies freeing the entries quite a bit; though there aren't that many failure paths right now, introducing filling the cache from a tree will introduce more. This makes sure not to leak memory on errors.
* The raw index buffer content is not guaranteed to be alignedJacques Germishuys2014-09-261-24/+29
| | | | * Ensure alignment by copying the content into a structure on the stack
* index: check for valid filemodes on addcmn/index-add-modesCarlos Martín Nieto2014-05-221-0/+14
|
* Lay groundwork for updating stat cache in diffRussell Belfer2014-05-021-4/+2
| | | | | | | | | | | This reorganized the diff OID calculation to make it easier to correctly update the stat cache during a diff once the flags to do so are enabled. This includes marking the path of a git_index_entry as const so we can make a "fake" git_index_entry with a "const char *" path and not get warnings. I was a little surprised at how unobtrusive this change was, but I think it's probably a good thing.
* Fix some coverity-found issuesRussell Belfer2014-04-211-2/+3
|
* Fix race checking for existing index itemsRussell Belfer2014-04-171-20/+32
| | | | | | | In the threading tests, I was still seeing a race condition where the same item could end up being inserted multiple times into the index. Preserving the sorted-ness of the index outside of the `index_insert` call fixes the issue.
* Attribute file cache refactorRussell Belfer2014-04-171-5/+12
| | | | | | | This is a big refactoring of the attribute file cache to be a bit simpler which in turn makes it easier to enforce a lock around any updates to the cache so that it can be used in a threaded env. Tons of changes to the attributes and ignores code.
* Fix leak in git_index_conflict_cleanupRussell Belfer2014-04-171-22/+10
| | | | | | | | | | | | | I introduced a leak into conflict cleanup by removing items from inside the git_vector_remove_matching call. This simplifies the code to just use one common way for the two conflict cleanup APIs. When an index has an active snapshot, removing an item can cause an error (inserting into the deferred deletion vector), so I made the git_index_conflict_cleanup API return an error code. I felt like this wasn't so bad since it is just like the other APIs. I fixed up a couple of comments while I was changing the header.
* Clean up index snapshot function namingRussell Belfer2014-04-171-39/+47
| | | | | Clear up some of the various "find" functions and the snapshot API naming to be things I like more.
* Index locking and entry allocation changesRussell Belfer2014-04-171-164/+205
| | | | | | | | | | | | | | | | | This makes the lock management on the index a little bit broader, having a number of routines hold the lock across looking up the item to be modified and actually making the modification. Still not true thread safety, but more pure index modifications are now safe which allows the simple cases (such as starting up a diff while index modifications are underway) safe enough to get the snapshot without hitting allocation problems. As part of this, I simplified the allocation of index entries to use a flex array and just put the path at the end of the index entry. This makes every entry self-contained and makes it a little easier to feel sure that pointers to strings aren't being accidentally copied and freed while other references are still being held.
* Decouple index iterator sort from indexRussell Belfer2014-04-171-46/+27
| | | | | | | | 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 mutex around index entries changesRussell Belfer2014-04-171-61/+164
| | | | | This surrounds any function that mutates the entries vector with a mutex so it can be safely snapshotted.
* Add index snapshot and use it for iteratorRussell Belfer2014-04-171-9/+33
|
* Some index internals refactoringRussell Belfer2014-04-171-165/+193
| | | | | | | | 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.
* Some vector utility tweaksRussell Belfer2014-04-171-2/+5
| | | | | This is just laying some groundwork for internal index changes that I'm working on.
* Merge pull request #2215 from libgit2/rb/submodule-cache-fixesVicent Marti2014-04-041-0/+12
|\ | | | | Improve submodule cache management
| * More tests and fix submodule index refreshRussell Belfer2014-04-011-1/+3
| | | | | | | | | | | | | | | | | | | | There was a little bug where the submodule cache thought that the index date was out of date even when it wasn't that was resulting in some extra scans of index data even when not needed. Mostly this commit adds a bunch of new tests including adding and removing submodules in the index and in the HEAD and seeing if we can automatically pick them up when refreshing.