summaryrefslogtreecommitdiff
path: root/src/index.c
Commit message (Collapse)AuthorAgeFilesLines
...
* | index: extract index_entry_dup() from index_insert()Kirill A. Shutemov2011-07-251-9/+20
| | | | | | | | Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name>
* | index: fix cast warningsKirill A. Shutemov2011-07-251-6/+6
|/ | | | | | | | | | | | | | | /home/kas/git/public/libgit2/src/index.c: In function ‘git_index_clear’: /home/kas/git/public/libgit2/src/index.c:228:8: warning: cast discards ‘__attribute__((const))’ qualifier from pointer target type [-Wcast-qual] /home/kas/git/public/libgit2/src/index.c:235:8: warning: cast discards ‘__attribute__((const))’ qualifier from pointer target type [-Wcast-qual] /home/kas/git/public/libgit2/src/index.c: In function ‘index_insert’: /home/kas/git/public/libgit2/src/index.c:392:7: warning: cast discards ‘__attribute__((const))’ qualifier from pointer target type [-Wcast-qual] /home/kas/git/public/libgit2/src/index.c:399:7: warning: cast discards ‘__attribute__((const))’ qualifier from pointer target type [-Wcast-qual] /home/kas/git/public/libgit2/src/index.c: In function ‘read_unmerged’: /home/kas/git/public/libgit2/src/index.c:681:35: warning: cast discards ‘__attribute__((const))’ qualifier from pointer target type [-Wcast-qual] /home/kas/git/public/libgit2/src/index.c: In function ‘read_entry’: /home/kas/git/public/libgit2/src/index.c:716:33: warning: cast discards ‘__attribute__((const))’ qualifier from pointer target type [-Wcast-qual] Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name>
* index: fix memory leakKirill A. Shutemov2011-07-191-0/+2
| | | | | | We need really free vectors on index freeing, not only clear. Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name>
* index: Yes, we have to truncateVicent Marti2011-07-131-3/+13
|
* index: fix potential overflowKirill A. Shutemov2011-07-131-2/+6
| | | | | | | | mode field of git_index_entry_unmerged is array of unsigned ints. It's unsafe to cast pointer to an element of the array to long int *. It may cause overflow in git_strtol32(). Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name>
* index: drop useless type castingKirill A. Shutemov2011-07-131-23/+18
| | | | | | | Type casting usually points to some trick or bug. It's better not hide it between useless type castings. Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name>
* vector: mark internal functions as staticKirill A. Shutemov2011-07-131-5/+5
| | | | Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name>
* vector: avoid double assertingKirill A. Shutemov2011-07-131-3/+0
| | | | | | | index_initialize() calls assert() for arguments on its own. No need to call it twice. Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name>
* index: drop sort_index()Kirill A. Shutemov2011-07-131-11/+3
| | | | | | Remove dummy wrapper around git_vector_sort(). Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name>
* index: do not sort index before git_vector_bsearch2()Kirill A. Shutemov2011-07-131-1/+0
| | | | | | | git_vector_bsearch2() calls git_vector_sort(). No need to call it directly. Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name>
* index: do not free vectors twice in git_index_free()Kirill A. Shutemov2011-07-131-2/+0
| | | | | | | git_index_clear() frees index->entries and index->unmerged. No need to free it once again. Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name>
* index: Return `GIT_ENOTFOUND` when an entry cannot be openedVicent Marti2011-07-091-1/+1
|
* index: Fix memory leak on OOMVicent Marti2011-07-071-4/+17
|
* vector: Timsort all of the thingsVicent Marti2011-07-071-6/+6
| | | | | | | | | | | | | | | | | | | | | | | | Drop the GLibc implementation of Merge Sort and replace it with Timsort. The algorithm has been tuned to work on arrays of pointers (void **), so there's no longer a need to abstract the byte-width of each element in the array. All the comparison callbacks now take pointers-to-elements, not pointers-to-pointers, so there's now one less level of dereferencing. E.g. int index_cmp(const void *a, const void *b) { - const git_index_entry *entry_a = *(const git_index_entry **)(a); + const git_index_entry *entry_a = (const git_index_entry *)(a); The result is up to a 40% speed-up when sorting vectors. Memory usage remains lineal. A new `bsearch` implementation has been added, whose callback also supplies pointer-to-elements, to uniform the Vector API again.
* index: introduce git_index_uniq() functionKirill A. Shutemov2011-07-051-0/+5
| | | | | | | | | It removes all entries with equal path except last added. On large indexes git_index_append() + git_index_uniq() before writing is *much* faster, than git_index_add(). Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name>
* index: speedup git_index_append()/git_index_append2()Kirill A. Shutemov2011-07-051-17/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | git_index_find() in index_insert() is useless if replace is not requested (append). Do not call it in this case. It speedup git_index_append() *dramatically* on large indexes. $ cat index_test.c int main(int argc, char **argv) { git_index *index; git_repository *repo; git_odb *odb; struct git_index_entry entry; git_oid tree_oid; char tree_hex[41]; int i; git_repository_init(&repo, "/tmp/myrepo", 0); odb = git_repository_database(repo); git_repository_index(&index, repo); memset(&entry, 0, sizeof(entry)); git_odb_write(&entry.oid, odb, "", 0, GIT_OBJ_BLOB); entry.path = "test.file"; for (i = 0; i < 50000; i++) git_index_append2(index, &entry); git_tree_create_fromindex(&tree_oid, index); git_oid_fmt(tree_hex, &tree_oid); tree_hex[40] = '\0'; printf("tree: %s\n", tree_hex); git_index_free(index); git_repository_free(repo); return 0; } Before: $ time ./index_test tree: 43f73659c43b651588cc81459d9e25b08721b95d ./index_test 151.19s user 0.05s system 99% cpu 2:31.78 total After: $ time ./index_test tree: 43f73659c43b651588cc81459d9e25b08721b95d ./index_test 0.05s user 0.00s system 94% cpu 0.059 total About 2573 times speedup on this test :) Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name>
* fileops: CleanupVicent Marti2011-07-051-9/+9
| | | | | | | | | | | | | | | | Cleaned up the structure of the whole OS-abstraction layer. fileops.c now contains a set of utility methods for file management used by the library. These are abstractions on top of the original POSIX calls. There's a new file called `posix.c` that contains emulations/reimplementations of all the POSIX calls the library uses. These are prefixed with `p_`. There's a specific posix file for each platform (win32 and unix). All the path-related methods have been moved from `utils.c` to `path.c` and have their own prefix.
* cleanup: remove trailing spacesKirill A. Shutemov2011-07-011-1/+1
| | | | Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name>
* oid: Rename methodsVicent Marti2011-06-161-3/+3
| | | | | Yeah. Finally. Fuck the old names, this ain't POSIX and they don't make any sense at all.
* Prefer to use file mode defines instead of raw numbersSebastian Schuberth2011-06-101-2/+2
|
* windows: Fix Symlink issuesVicent Marti2011-06-081-4/+1
| | | | | | | | Handle Symlinks if they can be handled in Win32. This is not even compiled. Needs review. The lstat implementation is modified from core Git. The readlink implementation is modified from PHP.
* fileops: Allow differentiation between deep and shallow exists()Jakob Pfender2011-06-071-1/+1
| | | | | | | | | | When calling gitfo_exists() on a symbolic link, sometimes we need to simply check whether the link exists and sometimes we need to check whether the file pointed to by the symlink exists. Introduce a new function gitfo_shallow_exists that only checks if the link exists and revert gitfo_exists to the original functionality of checking whether the file pointed to by the link exists.
* blob: Stat path inside git_blob_create_fromfileJakob Pfender2011-06-071-1/+1
| | | | | | | | | | | | | 00582bc introduced a change that required the caller of git_blob_create_fromfile() to pass a struct stat with the stat information for the file. Several developers pointed out that this would make life hard for the bindings developers as struct stat isn't widely supported by other languages. Make git_blob_create_fromfile() stat the path itself, eliminating the need for the file to be stat'ed by the caller. This makes index_init_entry() more costly as the file will be stat'ed twice but makes life easier for everyone else.
* index: Correctly write entry modeJakob Pfender2011-06-071-1/+10
| | | | | | | | | | The entry mode flags for an entry created from a path name were not correctly written if the entry was a symlink. The st_mode of a statted symlink is 0120777, however git requires the mode to read 0120000, because it does not care about permissions of symlinks. Introduce index_create_mode() that correctly writes the mode flags in the form expected by git.
* index/fileops: Correctly process symbolic linksJakob Pfender2011-06-071-1/+1
| | | | | | | | | | | | gitfo_exists() used to error out if the given file was a symbolic link, due to access() returning an error code. This is not expected behaviour, as gitfo_exists() should only check whether the file itself exists, not its link target if it is a symbolic link. Fix this by calling gitfo_lstat() instead, which is just a wrapper for lstat(). Also fix the same error in index_init_entry().
* blob: Require stat information for git_blob_create_fromfile()Jakob Pfender2011-06-071-1/+1
| | | | | | | | | | | | | | | | | In order to be able to write symlinks with git_blob_create_fromfile(), we need to check whether the file to be written is a symbolic link or not. Since the calling function of git_blob_create_fromfile() is likely to have stated the file before calling, we make it pass the stat. The reason for this is that writing symbolic link blobs is significantly different from writing ordinary files - we do not want to open the link destination but instead want to write the link itself, regardless of whether it exists or not. Previously, index_init_entry() used to error out if the file to be added was a symlink that pointed to a nonexistent file. Fix this behaviour to add the file regardless of whether it exists. This mimics git.git's behaviour.
* Index: API uniformisation: Use unsigned int for all index number.Romain Geissler2011-06-051-3/+9
| | | | | Feature Added: Search an unmerged entry by path (git_index_get_unmerged renamed to git_index_get_unmerged_bypath) or by index (git_index_get_unmerged_byindex).
* index: Add `git_index_entry_stage` methodVicent Marti2011-06-031-0/+5
| | | | As suggested by Romain-Geissler
* Merge pull request #223 from carlosmn/valgrindVicent Martí2011-06-011-0/+9
|\ | | | | Plug a leak in the index unmerged entries vector
| * Plug a leak in the index unmerged entries vectorCarlos Martín Nieto2011-05-311-0/+9
| | | | | | | | Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
* | index: Cleanup tree parsingVicent Marti2011-06-011-23/+25
| |
* | index: correctly parse invalidated TREE extensionsCarlos Martín Nieto2011-06-011-1/+10
| | | | | | | | | | | | | | | | | | | | A TREE extension with an entry count of -1 means that it was invalidated and we should ignore it. Do so instead of returning an error. This fixes issue #202 Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
* | Allow read_tree_internal to return an error codeCarlos Martín Nieto2011-06-011-28/+53
| | | | | | | | | | | | | | | | | | | | | | | | There are two reasons why read_tree_internal might return a NULL tree. The first one is a corrupt index, but the second one is an invalidated TREE extension. Up to now, its only way to communicate with its caller was through the return value being NULL or not. Allow read_tree_internal to report its exit status independently from the tree pointer. Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
* | index: Change the memory management for repo indexesVicent Marti2011-06-011-3/+9
|/ | | | | The `git_repository_index` call now returns a brand new index that must be manually free'd.
* index: Fix unused error messagesVicent Marti2011-05-231-2/+2
|
* index.c: Move to new error handling mechanismJakob Pfender2011-05-231-21/+20
|
* index: Fix issues in the unmerged entries APIVicent Marti2011-05-191-42/+26
|
* index.c: Fix typoJakob Pfender2011-05-171-1/+1
| | | | git__rethrow was missing an underscore.
* Move index.c to new error handling mechanismJakob Pfender2011-05-171-13/+15
|
* Merge branch 'development' into unmergedJakob Pfender2011-05-171-51/+105
|\
| * Fix misspelling of git_index_append2 (was git_index_apppend2).Jason R. McNeil2011-05-031-1/+1
| |
| * Re-apply missing patchesVicent Marti2011-05-021-2/+23
| |
| * index: Refactor add/replace methodsVicent Marti2011-04-241-46/+77
| | | | | | | | | | | | | | | | | | | | | | Removed the optional `replace` argument, we now have 4 add methods: `git_index_add`: add or update from path `git_index_add2`: add or update from struct `git_index_append`: add without replacing from path `git_index_append2`: add without replacing from struct Yes, this breaks the bindings.
| * index: Allow user to toggle whether to replace an index entryJakob Pfender2011-04-211-5/+7
| | | | | | | | | | When in the middle of a merge, the index needs to contain several files with the same name. git_index_insert() used to prevent this by not adding a new entry if an entry with the same name already existed.
* | index.c: Remove duplicate function declarationJakob Pfender2011-04-281-1/+0
| | | | | | | | read_unmerged_internal() was present twice.
* | index: Add API for unmerged entriesJakob Pfender2011-04-211-0/+114
|/ | | | | | | | | | | | | | | | | | | | | | New external functions: - git_index_unmerged_entrycount: Counts the unmerged entries in the index - git_index_get_unmerged: Gets an unmerged entry from the index by name New internal functions: - read_unmerged: Wrapper for read_unmerged_internal - read_unmerged_internal: Reads unmerged entries from the index if the index has the INDEX_EXT_UNMERGED_SIG set - unmerged_srch: Search function for unmerged vector - unmerged_cmp: Compare function for unmerged vector New data structures: - git_index now contains a git_vector unmerged that stores unmerged entries - git_index_entry_unmerged: Representation of an unmerged file entry. It represents all three versions of the file at the same time, with one name, three modes and three OIDs
* Properly check `strtol` for errorsVicent Marti2011-04-091-2/+13
| | | | | We are now using a custom `strtol` implementation to make sure we're not missing any overflow errors.
* index.c: Fix tiny typosschu2011-03-281-2/+2
|
* index.c: Read index after initializationJakob Pfender2011-03-251-1/+1
| | | | | | | | | | | | | | | | | | | | The current behaviour of git_index_open{bare,inrepo}() is unexpected. When an index is opened, an in-memory index object is created that is linked to the index discovered by git_repository_open(). However, this index object is empty, as the on-disk index is not read. To fully open the on-disk index file, git_index_read() has to be called. This leads to confusing behaviour. Consider the following code: git_index *idx; git_index_open_inrepo(&idx, repo); git_index_write(idx); You would expect this to have no effect, as the index is never ostensibly manipulated. However, what actually happens is that the index entries are removed from the on-disk index because the empty in-memory index object created by open_inrepo() is written back to the disk. This patch reads the index after opening it.
* Switch from time_t to git_time_tnulltoken2011-03-231-6/+6
| | | | git_time_t is defined as a signed 64 integer. This allows a true predictable multiplatform behavior.