src/tree.c


Log

Author Commit Date CI Message
Russell Belfer 116bbdf0 2013-04-16T12:08:21 clean up tree pointer casting
Russell Belfer 3f27127d 2013-04-16T11:51:02 Simplify object table parse functions This unifies the object parse functions into one signature that takes an odb_object.
Russell Belfer 78606263 2013-04-15T00:05:44 Add callback to git_objects_table This adds create and free callback to the git_objects_table so that more of the creation and destruction of objects can be table driven instead of using switch statements. This also makes the semantics of certain object creation functions consistent so that we can make better use of function pointers. This also fixes a theoretical error case where an object allocation fails and we end up storing NULL into the cache.
Russell Belfer badd85a6 2013-04-10T17:10:17 Use git_odb_object_data/_size whereever possible This uses the odb object accessors so we can change the internals more easily...
Vicent Marti 8842c75f 2013-04-03T22:30:07 What has science done.
Carlos Martín Nieto f90391ea 2013-04-18T14:47:54 treebuilder: don't overwrite the error message
Russell Belfer 0c468633 2013-03-14T13:40:15 Improved tree iterator internals 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).
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
Russell Belfer e2237179 2013-02-20T10:58:56 Some code cleanups in tree.c This replaces most of the explicit vector iteration with calls to git_vector_foreach, adds in some git__free and giterr_clear calls to clean up during some error paths, and a couple of other code simplifications.
Russell Belfer 93ab370b 2013-02-20T10:50:01 Store treebuilder length separately from entries vec The treebuilder entries vector flags removed items which means we can't rely on the entries vector length to accurately get the number of entries. This adds an entrycount value and maintains it while updating the treebuilder entries.
nulltoken 3ad05221 2013-02-05T16:52:56 Fix MSVC compilation warnings Fix #1308
Russell Belfer 4657fc1c 2013-01-29T13:54:08 Merge pull request #1285 from phkelley/vector Vector improvements and their fallout
John Wiegley 5fb98206 2013-01-28T15:56:04 Added git_treebuilder_entrycount Conflicts: src/tree.c
Philip Kelley 11d9f6b3 2013-01-27T14:17:07 Vector improvements and their fallout
Russell Belfer 98527b5b 2013-01-09T16:03:35 Add git_tree_entry_cmp and git_tree_entry_icmp This adds a new external API git_tree_entry_cmp and a new internal API git_tree_entry_icmp for sorting tree entries. The case insensitive one is internal only because general users should never be seeing case-insensitively sorted trees.
Edward Thomson 359fc2d2 2013-01-08T17:07:25 update copyrights
Russell Belfer 91e7d263 2012-12-10T15:29:44 Fix iterator reset and add reset ranges The `git_iterator_reset` command has not been working in all cases particularly when there is a start and end range. This fixes it and adds tests for it, and also extends it with the ability to update the start/end range strings when an iterator is reset.
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.
Carlos Martín Nieto f1c75b94 2012-12-07T15:16:41 tree: relax the filemode parser There are many different broken filemodes in the wild so we need to protect against them and give something useful up the chain. Don't fail when reading a tree from the ODB but normalize the mode as best we can. As 664 is no longer a mode that we consider to be valid and gets normalized to 644, we can stop accepting it in the treebuilder. The library won't expose it to the user, so any invalid modes are a bug.
Vicent Martí e2934db2 2012-11-29T02:05:46 Merge pull request #1090 from arrbee/ignore-invalid-by-default Ignore invalid entries by default
Russell Belfer a8122b5d 2012-11-21T15:39:03 Fix warnings on Win64 build
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
Russell Belfer cfeef7ce 2012-11-19T13:40:08 Minor optimization to tree entry validity check This checks for a leading '.' before looking for the invalid tree entry names. Even on pretty high levels of optimization, this seems to make a measurable improvement. I accidentally used && in the check initially instead of || and while debugging ended up improving the error reporting of issues with adding tree entries. I thought I'd leave those changes, too.
Scott J. Goldman 0d778b1a 2012-11-18T16:52:04 Catch invalid filenames in append_entry() This prevents the index api from calling write_tree() with a bogus tree.
Scott J. Goldman 19af78bb 2012-11-18T15:15:24 Prevent creating `..`, `.`, and `.git` with tree builder As per core git.
nulltoken f92bcaea 2012-11-08T17:39:23 index: prevent tree creation from a non merged state Fix libgit2/libgit2sharp#243
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
Edward Thomson f45ec1a0 2012-10-29T20:04:21 index refactoring
Russell Belfer 0d64bef9 2012-10-05T15:56:57 Add complex checkout test and then fix checkout This started as a complex new test for checkout going through the "typechanges" test repository, but that revealed numerous issues with checkout, including: * complete failure with submodules * failure to create blobs with exec bits * problems when replacing a tree with a blob because the tree "example/" sorts after the blob "example" so the delete was being processed after the single file blob was created This fixes most of those problems and includes a number of other minor changes that made it easier to do that, including improving the TYPECHANGE support in diff/status, etc.
nulltoken 9d7ac675 2012-08-21T11:45:16 tree entry: rename git_tree_entry_attributes() into git_tree_entry_filemode()
nulltoken a7dbac0b 2012-08-17T21:10:32 filemode: deploy enum usage
nulltoken 66439b0b 2012-08-17T11:21:49 treebuilder: enhance attributes handling on insertion
Carlos Martín Nieto a6bf1687 2012-08-13T14:07:47 tree: allow the user to skip an entry or cancel the walk Returning a negative cancels the walk, and returning a positive one causes us to skip an entry, which was previously done by a negative value. This allows us to stay consistent with the rest of the functions that take a callback and keeps the skipping functionality.
Carlos Martín Nieto 53ae1235 2012-08-13T14:00:53 tree: bring back the documented behaviour for a walk However, there should be a way to cancel the walk and another to skip the entry.
Vicent Marti 51e1d808 2012-08-06T12:41:08 Merge remote-tracking branch 'arrbee/tree-walk-fixes' into development Conflicts: src/notes.c src/transports/git.c src/transports/http.c src/transports/local.c tests-clar/odb/foreach.c
Russell Belfer b0d37669 2012-08-03T17:24:59 Add new iteration behavior to git_tree_walk Missed this one, ironically enough.
Russell Belfer 2031760c 2012-07-26T16:10:22 Fix git_tree_walk to return user error This makes sure that an error code returned by the callback function of `git_tree_walk` will stop the iteration and get propagated back to the caller verbatim. Also, this adds a minor helper function `git_tree_entry_byoid` that searches a `git_tree` for an entry with the given OID. This isn't a fast function, but it's easier than writing the loop yourself as an external user of the library.
nulltoken b8457baa 2012-07-24T07:57:58 portability: Improve x86/amd64 compatibility
Michael Schubert c6f42953 2012-07-19T17:33:48 tree: fix ordering for git_tree_walk Josh Triplett noticed libgit2 actually does preorder entries in tree_walk_post instead of postorder. Also, we continued walking even when an error occured in the callback. Fix #773; also, allow both pre- and postorder walking.
nulltoken dc1f4b32 2012-07-12T10:52:19 tree: unfound tree entry returns GIT_ENOTFOUND
nulltoken 1c3edb30 2012-07-12T09:46:45 tree: prevent git_tree_entry_free() from segfaulting when being passed a NULL tree_entry
Vicent Marti 46ea40d9 2012-06-29T17:08:36 tree: Rename `entry_copy` to `entry_dup`
Vicent Marti 0e2fcca8 2012-06-29T02:21:12 tree: Bring back `entry_bypath` Smaller, simpler, faster.
Vicent Marti b93688d0 2012-06-19T02:33:03 Merge remote-tracking branch 'yorah/fix/notes-creation' into development Conflicts: src/notes.c
nulltoken b0b3b4e3 2012-05-29T16:19:15 treebuilder: prevent git_treebuilder_free() from segfaulting when being passed a NULL treebuilder
Vicent Martí 3f035860 2012-06-07T22:43:03 misc: Fix warnings from PVS Studio trial
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
Vicent Martí cedf9ca9 2012-05-16T19:16:35 tree: Kill the `git_tree_diff` functions These are deprecated and replaced with the diffing code in git2/diff.h
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.
Vicent Martí 3fbcac89 2012-05-02T19:56:38 Remove old and unused error codes
Vicent Martí 40879fac 2012-05-02T15:59:02 Merge branch 'new-error-handling' into development Conflicts: .travis.yml include/git2/diff.h src/config_file.c src/diff.c src/diff_output.c src/mwindow.c src/path.c tests-clar/clar_helpers.c tests-clar/object/tree/frompath.c tests/t00-core.c tests/t03-objwrite.c tests/t08-tag.c tests/t10-refs.c tests/t12-repo.c tests/t18-status.c tests/test_helpers.c tests/test_main.c
Vicent Martí b8802146 2012-05-01T19:16:14 Merge remote-tracking branch 'carlosmn/remaining-errors' into new-error-handling Conflicts: src/refspec.c
nulltoken fa6420f7 2012-04-29T21:46:33 buf: deploy git_buf_len()
Carlos Martín Nieto 3aa351ea 2012-04-26T15:05:07 error handling: move the missing parts over to the new error handling
Russell Belfer 44ef8b1b 2012-04-13T13:00:10 Fix warnings on 64-bit windows builds This fixes all the warnings on win64 except those in deps, which come from the regex code.
Vicent Martí 181bbf14 2012-03-28T19:12:13 tree: Fix homing entry search
Vicent Martí cb8a7961 2012-03-07T00:02:55 error-handling: Repository This also includes droping `git_buf_lasterror` because it makes no sense in the new system. Note that in most of the places were it has been dropped, the code needs cleanup. I.e. GIT_ENOMEM is going away, so instead it should return a generic `-1` and obviously not throw anything.
Carlos Martín Nieto 82ccb87e 2012-02-23T22:56:04 tree: break out on write error If write_tree() returs an error, we used to set the error message and continued looping. Exit the loop so we return the error.
schu 5e0de328 2012-02-13T17:10:24 Update Copyright header Signed-off-by: schu <schu-github@schulog.org>
schu b3408e3e 2012-02-05T14:59:45 treebuilder: remove needless variable entry_count Signed-off-by: schu <schu-github@schulog.org>
Carlos Martín Nieto 9269ccce 2012-01-19T23:44:52 diff-index: fix leak The buffer wasn't getting freed if the last difference was a deletion.
Russell Belfer 1744fafe 2012-01-17T15:49:47 Move path related functions from fileops to path This takes all of the functions that look up simple data about paths (such as `git_futils_isdir`) and moves them over to path.h (becoming `git_path_isdir`). This leaves fileops.h just with functions that actually manipulate the filesystem or look at the file contents in some way. As part of this, the dir.h header which is really just for win32 support was moved into win32 (with some minor changes).
Clemens Buchacher 1f783edf 2011-12-29T15:03:38 do not use full path in diff-index Currently, diff_index passes the full relative path from the repository root to the callback. In case of an addition, it passes the tree entry instead of the index entry. This change fixes the path used for addition, and it passes only the basename of the path. This mimics the current behavior of git_tree_diff.
Clemens Buchacher a26a1563 2011-12-30T19:03:55 move entry_is_tree to tree.h
Vicent Marti 7af26f8f 2011-12-14T03:24:16 Fix tree-diff with the new path API
Vicent Marti 40e73d6f 2011-12-09T01:38:46 Merge remote-tracking branch 'arrbee/git-buf-for-paths' into development Conflicts: tests-clay/clay_main.c
Russell Belfer 97769280 2011-11-30T11:27:15 Use git_buf for path storage instead of stack-based buffers This converts virtually all of the places that allocate GIT_PATH_MAX buffers on the stack for manipulating paths to use git_buf objects instead. The patch is pretty careful not to touch the public API for libgit2, so there are a few places that still use GIT_PATH_MAX. This extends and changes some details of the git_buf implementation to add a couple of extra functions and to make error handling easier. This includes serious alterations to all the path.c functions, and several of the fileops.c ones, too. Also, there are a number of new functions that parallel existing ones except that use a git_buf instead of a stack-based buffer (such as git_config_find_global_r that exists alongsize git_config_find_global). This also modifies the win32 version of p_realpath to allocate whatever buffer size is needed to accommodate the realpath instead of hardcoding a GIT_PATH_MAX limit, but that change needs to be tested still.
Vicent Marti e9238687 2011-12-03T18:05:44 tree: recursive diff-index Signed-off-by: Carlos Martín Nieto <carlos@cmartin.tk> Signed-off-by: Vicent Marti <tanoku@gmail.com> # Please enter the commit message for your changes. Lines starting # with '#' will be ignored, and an empty message aborts the commit. # # Author: Carlos Martín Nieto <carlos@cmartin.tk> # # On branch development # Your branch is ahead of 'origin/development' by 11 commits. # # Changes to be committed: # (use "git reset HEAD^1 <file>..." to unstage) # # modified: include/git2/tree.h # modified: src/tree.c # modified: tests-clay/clay_main.c # modified: tests-clay/object/tree/diff.c # # Untracked files: # (use "git add <file>..." to include in what will be committed) # # 0001-remote-Cleanup-the-remotes-code.patch # 466.patch # 466.patch.1 # 488.patch # Makefile # libgit2.0.15.0.dylib # libgit2.0.dylib # libgit2.dylib # libgit2_clay # libgit2_test # tests-clay/object/tree/
Carlos Martín Nieto a1fdea28 2011-10-24T16:48:12 tree: implement tree diffing For each difference in the trees, the callback gets called with the relevant information so the user can fill in their own data structures. Signed-off-by: Carlos Martín Nieto <carlos@cmartin.tk>
Vicent Marti 45e79e37 2011-11-26T04:59:21 Rename all `_close` methods There's no difference between `_free` and `_close` semantics: keep everything with the same name to avoid confusions.
Vicent Marti 9462c471 2011-11-25T08:16:26 repository: Change ownership semantics The ownership semantics have been changed all over the library to be consistent. There are no more "borrowed" or duplicated references. Main changes: - `git_repository_open2` and `3` have been dropped. - Added setters and getters to hotswap all the repository owned objects: `git_repository_index` `git_repository_set_index` `git_repository_odb` `git_repository_set_odb` `git_repository_config` `git_repository_set_config` `git_repository_workdir` `git_repository_set_workdir` Now working directories/index files/ODBs and so on can be hot-swapped after creating a repository and between operations. - All these objects now have proper ownership semantics with refcounting: they all require freeing after they are no longer needed (the repository always keeps its internal reference). - Repository open and initialization has been updated to keep in mind the configuration files. Bare repositories are now always detected, and a default config file is created on init. - All the tests affected by these changes have been dropped from the old test suite and ported to the new one.
Vicent Marti 2ba14f23 2011-11-17T02:13:46 tree: Add payload to `git_tree_walk`
Vicent Marti 9432af36 2011-11-17T01:23:19 Rename `git_tree_frompath` to `git_tree_get_subtree` That makes more sense to me.
Vicent Marti 3286c408 2011-10-28T14:51:13 global: Properly use `git__` memory wrappers Ensure that all memory related functions (malloc, calloc, strdup, free, etc) are using their respective `git__` wrappers.
Vicent Marti da37654d 2011-10-27T22:33:31 tree: Add traversal in post-order
Vicent Marti 28c1451a 2011-10-20T02:35:19 tree: Fix name lookups once and for all Double-pass binary search. Jeez.
Vicent Marti 8cf2de07 2011-10-19T01:34:42 tree: Fix lookups by entry name
nulltoken 3fa735ca 2011-10-13T23:17:19 tree: Add git_tree_frompath() which, given a relative path to a tree entry, retrieves the tree object containing this tree entry
Vicent Marti 8e9bfa4c 2011-09-27T14:31:57 tree: Fix check for valid attributes
Vicent Marti 9ef9e8c3 2011-09-27T14:30:14 tree: Use an internal append functiont to add new entries
Carlos Martín Nieto 8255c69b 2011-09-24T17:06:52 Make use of the tree cache Taking advantage of the tree cache, git_tree_create_fromindex becomes comparable in speed to git write-tree when the cache is available. Signed-off-by: Carlos Martín Nieto <carlos@cmartin.tk>
nulltoken ad196c6a 2011-09-21T23:17:39 config: make git_config_[get|set]_long() able to properly deal with 8 bytes wide values Should fix issue #419. Signed-off-by: nulltoken <emeric.fermas@gmail.com>
Vicent Martí 71a4c1f1 2011-09-18T20:07:59 Merge pull request #384 from kiryl/warnings Add more -W flags to CFLAGS
Vicent Martí ae996e02 2011-09-18T19:59:34 Merge pull request #394 from carlosmn/tree-fromindex Use git_treebuilder to write the index as a tree
Vicent Marti bb742ede 2011-09-19T01:54:32 Cleanup legal data 1. The license header is technically not valid if it doesn't have a copyright signature. 2. The COPYING file has been updated with the different licenses used in the project. 3. The full GPLv2 header in each file annoys me.
Carlos Martín Nieto 4a619797 2011-08-31T08:10:13 tree: use git_treebuilder to write the index as a tree There is no point in reinventing the wheel when using the treebuilder is much more straightforward and makes the code more readable. There is no optimisation, and the performance is no worse than when writing the tree object ourselves.
Kirill A. Shutemov d568d585 2011-08-30T23:55:22 CMakefile: add -Wmissing-prototypes and fix warnings Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name>
Kirill A. Shutemov 0b2c4061 2011-08-30T23:06:04 CMakefile: add -Wstrict-aliasing=2 and fix warnings Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name>
Luc Bertrand 8f643ce8 2011-08-03T13:44:28 Remove duplicated sort
Kirill A. Shutemov 0cbbdc26 2011-07-15T17:56:48 tree: fix cast warnings /home/kas/git/public/libgit2/src/tree.c: In function ‘entry_search_cmp’: /home/kas/git/public/libgit2/src/tree.c:47:36: warning: cast discards ‘__attribute__((const))’ qualifier from pointer target type [-Wcast-qual] /home/kas/git/public/libgit2/src/tree.c: In function ‘git_treebuilder_remove’: /home/kas/git/public/libgit2/src/tree.c:443:31: warning: cast discards ‘__attribute__((const))’ qualifier from pointer target type [-Wcast-qual] Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name>
nulltoken f4ad64c1 2011-07-13T07:58:17 tree: fix insertion of entries with invalid filenames
Vicent Marti e6629d83 2011-07-13T03:36:03 tree: More accurate matching on entries The old matcher was returning fake matches when given stupid entry names. E.g. `git2` could be matched by `git2 /`, `git2/foobar`, git2/////` and other stupid stuff
Vicent Marti 761aa2aa 2011-07-13T02:49:47 tree: Fix wrong sort order when querying entries Fixes #127 (that was quite an outstanding issue). Rationale: The tree objects on Git are stored and read following a very specific sorting algorithm that places folders before files. That original sort was the sort we were storing on memory, but this sort was being queried with a binary search that used a simple `strcmp` for comparison, so there were many instances where the search was failing. Obviously, the most straightforward way to fix this is changing the binary search CB to use the same comparison method as the sorting CB. The problem with this is that the binary search callback compares a path and an entry, so there is no way to know if the given path is a folder or a standard file. How do we work around this? Instead of splitting the `entry_byname` method in two (one for searching directories and one for searching normal files), we just assume that the path we are searching for is of the same kind as the path it's being compared at the moment. return git_futils_cmp_path( ksearch->filename, ksearch->filename_len, entry->attr & 040000, entry->filename, entry->filename_len, entry->attr & 040000); Since there cannot be a folder and a regular file with the same name on the same tree, the most basic equality check will always fail for all comparsions, until our path is compared with the actual entry we are looking for; in this case, the matching will succeed with the file type of the entry -- whatever it was initially. I hope that makes sense. PS: While I was at it, I switched the cmp methods to use cached values for the length of each filename. That makes searches and sorts retardedly fast -- I was wondering the reason of the performance hiccups on massive trees; it's because of 2*strlen for each comparsion call.
Vicent Marti afeecf4f 2011-07-09T02:10:46 odb: Direct writes are back DIRECT WRITES ARE BACK AND FASTER THAN EVER. The streaming writer to the ODB was an overkill for the smaller objects like Commit and Tags; most of the streaming logic was taking too long. This commit makes Commits, Tags and Trees to be built-up in memory, and then written to disk in 2 pushes (header + data), instead of streaming everything. This is *always* faster, even for big files (since the git_filebuf class still does streaming writes when the memory cache overflows). This is also a gazillion lines of code smaller, because we don't have to precompute the final size of the object before starting the stream (this was kind of defeating the point of streaming, anyway). Blobs are still written with full streaming instead of loading them in memory, since this is still the fastest way. A new `git_buf` class has been added. It's missing some features, but it'll get there.