summaryrefslogtreecommitdiff
path: root/src/index.c
Commit message (Collapse)AuthorAgeFilesLines
* Merge pull request #3353 from ethomson/wrongcase_addCarlos Martín Nieto2015-09-081-22/+114
|\ | | | | index: canonicalize directory case when adding
| * git_index_add: allow case changing renamesEdward Thomson2015-09-081-15/+26
| | | | | | | | | | | | | | | | | | | | | | On case insensitive platforms, allow `git_index_add` to provide a new path for an existing index entry. Previously, we would maintain the case in an index entry without the ability to change it (except by removing an entry and re-adding it.) Higher-level functions (like `git_index_add_bypath` and `git_index_add_frombuffers`) continue to keep the old path for easier usage.
| * index: canonicalize directory case when addingEdward Thomson2015-09-081-7/+88
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | On case insensitive systems, when given a user-provided path in the higher-level index addition functions (eg `git_index_add_bypath` / `git_index_add_frombuffer`), examine the index to try to match the given path to an existing directory. Various mechanisms can cause the on-disk representation of a folder to not match the representation in HEAD or the index - for example, a case changing rename of some file `a/file.txt` to `A/file.txt` will update the paths in the index, but not rename the folder on disk. If a user subsequently adds `a/other.txt`, then this should be stored in the index as `A/other.txt`.
* | Merge pull request #3381 from leoyanggit/index_directory_iteratorEdward Thomson2015-09-081-0/+24
|\ \ | |/ |/| New feature: add the ablility to iterate through a directory in index
| * New API: git_index_find_prefixLeo Yang2015-09-041-0/+24
| | | | | | | | Find the first index entry matching a prefix.
* | Merge pull request #3366 from libgit2/cmn/index-hashmapEdward Thomson2015-09-061-17/+99
|\ \ | |/ |/| Use a hashmap for path-based lookups in the index
| * index: put the icase insert choice in macroscmn/index-hashmapCarlos Martín Nieto2015-09-041-25/+30
| | | | | | | | | | This should let us see more clearly what we're doing and avoid the ugly 'if' we need every time we want to interact with the map.
| * index: keep a hash table as well as a vector of entriesCarlos Martín Nieto2015-08-141-17/+94
| | | | | | | | | | The hash table allows quick lookup of specific paths, while we use the vector for enumeration.
* | racy-git: TODO to use improved diffingEdward Thomson2015-08-281-0/+1
| |
* | iterator: use an options struct instead of argsEdward Thomson2015-08-281-4/+5
|/
* errors: tighten up git_error_state OOMs a bit moreEdward Thomson2015-08-031-3/+3
| | | | | When an error state is an OOM, make sure that we treat is specially and do not try to free it.
* index: stage an unregistered submodule as wellcmn/add-unreg-submoduleCarlos Martín Nieto2015-08-011-5/+58
| | | | | | We previously added logic to `_add_bypath()` to update a submodule. Go further and stage the submodule even if it's not registered to behave like git.
* index: allow add_bypath to update submodulescmn/index-add-submoduleCarlos Martín Nieto2015-07-121-2/+22
| | | | | Similarly to how git itself does it, allow the index update operation to stage a change in a submodule's HEAD.
* 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.