summaryrefslogtreecommitdiff
path: root/src/refs.c
Commit message (Collapse)AuthorAgeFilesLines
...
| * refs: don't stat so muchCarlos Martín Nieto2011-07-231-53/+45
| | | | | | | | | | | | | | | | | | | | | | | | In reference_read we stat a file and then call futils which stats it again. Use git_futils_readbuffer_updated to avoid the extra stat call. This introduces another parameter which is used to tell the caller whether the file was read or not. Modify the callers to take advantage of this new feature. This change removes ~140 stat calls from the test suite. Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
* | refs: fix cast warningKirill A. Shutemov2011-07-251-2/+2
|/ | | | | | | /home/kas/git/public/libgit2/src/refs.c: In function ‘normalize_name’: /home/kas/git/public/libgit2/src/refs.c:1681:12: warning: cast discards ‘__attribute__((const))’ qualifier from pointer target type [-Wcast-qual] Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name>
* refs: fix memory leak on renameKirill A. Shutemov2011-07-191-2/+9
| | | | | | | | | | | | | | Current implementation of git_reference_rename() removes 'ref' from loose cache, but not frees it. In result 'ref' is not reachable any more and we have got memory leak. Let's re-add 'ref' with corrected name to loose cache instead of 'new_ref' and free 'new_ref' properly. 'rollback' path seems leak too. git_reference_rename() need to be rewritten for proper resource management. Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name>
* reference_rename: make sure old_name gets freedschu2011-07-121-1/+3
| | | | Signed-off-by: schu <schu-github@schulog.org>
* reference_rename: fix flaw in force-renamingschu2011-07-071-2/+6
| | | | | | | reference_rename didn't respect the force flag. Fixed. Reported-by: nulltoken <emeric.fermas@gmail.com> Signed-off-by: schu <schu-github@schulog.org>
* vector: Timsort all of the thingsVicent Marti2011-07-071-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | 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.
* refs: Cleanup reference renamingVicent Marti2011-07-061-15/+14
| | | | | | | `git_futils_rmdir_r`: rename, clean up. `git_reference_rename`: cleanup. Do not use 3x4096 buffers on the stack or things will get ugly very fast. We can reuse the same buffer.
* reference_rename: git compliant reference renamingschu2011-07-061-91/+105
| | | | | | | | | | | | | | | | So far libgit2 didn't handle the following scenarios: * Rename of reference m -> m/m * Rename of reference n/n -> n Fixed. Since we don't write reflogs, we have to delete any old reflog for the renamed reference. Otherwise git.git will possibly fail when it finds invalid logs. Reported-by: nulltoken <emeric.fermas@gmail.com> Signed-off-by: schu <schu-github@schulog.org>
* fileops: CleanupVicent Marti2011-07-051-43/+43
| | | | | | | | | | | | | | | | 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-14/+14
| | | | Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name>
* refs: Remove bogus assertionVicent Marti2011-06-301-4/+2
| | | | | | The assertion in line 360 was there to check that only loose refs were being written as loose, but there are times when we need to re-write a packed reference as loose.
* refs: Remove duplicate rename methodVicent Marti2011-06-291-142/+132
| | | | `git_reference_rename` now takes a `force` flag
* refs: Remove unused declarationsVicent Marti2011-06-281-2/+0
|
* Remove redundant methods from the APIVicent Marti2011-06-281-131/+107
| | | | | | | | | | | | | | | A bunch of redundant methods have been removed from the external API. - All the reference/tag creation methods with `_f` are gone. The force flag is now passed as an argument to the normal create methods. - All the different commit creation methods are gone; commit creation now always requires a `git_commit` pointer for parents and a `git_tree` pointer for tree, to ensure that corrupted commits cannot be generated. - All the different tag creation methods are gone; tag creation now always requires a `git_object` pointer to ensure that tags are not created to inexisting objects.
* refs: Do not overflow when normalizing refnamesVicent Marti2011-06-231-16/+23
|
* Simplify loose ref writingCarlos Martín Nieto2011-06-161-26/+8
| | | | | | | | | | There is no need to store the format outselves, as the library provides git_filebuf_printf which takes care of the formatting itself. Also get rid of an use of strcat + strcpy which is always a nice thing. Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
* 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.
* refs: Rename git_referece_listcb to _foreachVicent Marti2011-06-161-3/+3
| | | | Same name as `git_config_foreach`
* Merge pull request #245 from schu/use-normalizedVicent Martí2011-06-071-0/+2
|\ | | | | rename-reference: use normalized path
| * rename-reference: use normalized pathschu2011-06-071-0/+2
| | | | | | | | Signed-off-by: schu <schu-github@schulog.org>
* | Fix compilation warnings in MSVCnulltoken2011-06-071-3/+6
|/
* Merge pull request #232 from schu/ref-available-cbVicent Martí2011-06-061-0/+47
|\ | | | | reference_rename: respect all references v2
| * Raise GIT_EEXISTS in case of conflicting ref names instead of passingschu2011-06-051-2/+2
| | | | | | | | | | | | | | | | the error returned by the subsystem; clarify error message. Fix tiny typo. Signed-off-by: schu <schu-github@schulog.org>
| * Teach reference_rename() to really respect other referencesschu2011-06-051-0/+47
| | | | | | | | | | | | | | Add a new function reference_available() to check if a reference name actually is free and can be used. Signed-off-by: schu <schu-github@schulog.org>
* | refs: Improve error messagesVicent Marti2011-06-061-2/+7
|/
* refs: Reword errorsVicent Marti2011-05-231-16/+13
|
* refs.c: Move to new error handling mechanismJakob Pfender2011-05-231-63/+63
|
* Change error handling mechanism once againVicent Marti2011-05-091-14/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Ok, this is the real deal. Hopefully. Here's how it's going to work: - One main method, called `git__throw`, that sets the error code and error message when an error happens. This method must be called in every single place where an error code was being returned previously, setting an error message instead. Example, instead of: return GIT_EOBJCORRUPTED; Use: return git__throw(GIT_EOBJCORRUPTED, "The object is missing a finalizing line feed"); And instead of: [...] { error = GIT_EOBJCORRUPTED; goto cleanup; } Use: [...] { error = git__throw(GIT_EOBJCORRUPTED, "What an error!"); goto cleanup; } The **only** exception to this are the allocation methods, which return NULL on failure but already set the message manually. /* only place where an error code can be returned directly, because the error message has already been set by the wrapper */ if (foo == NULL) return GIT_ENOMEM; - One secondary method, called `git__rethrow`, which can be used to fine-grain an error message and build an error stack. Example, instead of: if ((error = foobar(baz)) < GIT_SUCCESS) return error; You can now do: if ((error = foobar(baz)) < GIT_SUCCESS) return git__rethrow(error, "Failed to do a major operation"); The return of the `git_lasterror` method will be a string in the shape of: "Failed to do a major operation. (Failed to do an internal operation)" E.g. "Failed to open the index. (Not enough permissions to access '/path/to/index')." NOTE: do not abuse this method. Try to write all `git__throw` messages in a descriptive manner, to avoid having to rethrow them to clarify their meaning. This method should only be used in the places where the original error message set by a subroutine is not specific enough. It is encouraged to continue using this style as much possible to enforce error propagation: if ((error = foobar(baz)) < GIT_SUCCESS) return error; /* `foobar` has set an error message, and we are just propagating it */ The error handling revamp will take place in two phases: - Phase 1: Replace all pieces of code that return direct error codes with calls to `git__throw`. This can be done semi-automatically using `ack` to locate all the error codes that must be replaced. - Phase 2: Add some `git__rethrow` calls in those cases where the original error messages are not specific enough. Phase 1 is the main goal. A minor libgit2 release will be shipped once Phase 1 is ready, and the work will start on gradually improving the error handling mechanism by refining specific error messages. OTHER NOTES: - When writing error messages, please refrain from using weasel words. They add verbosity to the message without giving any real information. (<3 Emeric) E.g. "The reference file appears to be missing a carriage return" Nope. "The reference file is missing a carriage return" Yes. - When calling `git__throw`, please try to use more generic error codes so we can eventually reduce the list of error codes to something more reasonable. Feel free to add new, more generic error codes if these are going to replace several of the old ones. E.g. return GIT_EREFCORRUPTED; Can be turned into: return git__throw(GIT_EOBJCORRUPTED, "The reference is corrupted");
* Merge pull request #151 from carlosmn/root-commit.Vicent Martí2011-05-021-1/+2
|\ | | | | Support root commits
| * refs: don't loose info on resolve errorCarlos Martín Nieto2011-04-291-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | Typical use is git_reference_resolve(&ref, ref). Currently, if there is an error, ref will point to NULL, causing the user to lose that reference. Always update resolved_ref instead of just on finding an OID ref, storing the last valid reference in it. This change helps simplify the code for allowing root commits. Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
* | Re-apply missing patchesVicent Marti2011-05-021-0/+2
| |
* | Fix -Wunused-but-set-variable warningsschu2011-04-261-4/+4
|/ | | | | As of gcc 4.6 -Wall includes -Wunused-but-set-variable. Use GIT_UNUSED or remove actually unused variables to prevent those warnings.
* refs: Allow MERGE_HEAD in normalize_name()Jakob Pfender2011-04-211-2/+3
| | | | | Do not return with EINVALIDREFNAME when trying to normalize MERGE_HEAD's name.
* refs: Fix issue when packing weak tagsVicent Marti2011-04-081-13/+24
| | | | | Weak tags (e.g. tags that point directly to a normal object instead of a tag object) were failing to be packed.
* normalize_name: allow more references under refs/Carlos Martín Nieto2011-03-291-5/+10
| | | | | | | | | | | Allow any well-formed reference name to live under refs/ removing the condition that they be under refs/{heads,tags,remotes}/ as was the design of git. An exception is made for HEAD which is allowed to contain an OID reference in detached HEAD state. Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
* refs: Don't allow references to inexistent OIDsVicent Marti2011-03-291-0/+7
|
* Enforce coding conventions in refs.cVicent Marti2011-03-291-12/+17
| | | | | Internal methods are static and without the git prefix. 'Force' methods have a `_f` prefix to match the other 'force' methods.
* rename: don't return early if the target ref existsCarlos Martín Nieto2011-03-291-2/+4
| | | | Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
* Allow forcing the creation or renaming of referencesCarlos Martín Nieto2011-03-291-167/+245
| | | | | | | | | | | | Add internal reference create and rename functions which take a force parameter, telling them to overwrite an existing reference if it exists. These functions try to update the reference if it's of the same type as the one it's going to be replaced by. Otherwise the old reference becomes invalid. Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
* New external API method: `git_reference_listcb`Vicent Marti2011-03-251-21/+45
| | | | | | | | | | | | | | List all the references in the repository, calling a custom callback for each one. The listed references may be filtered by type, or using a bitwise OR of several types. Use the magic value `GIT_REF_LISTALL` to obtain all references, including packed ones. The `callback` function will be called for each of the references in the repository, and will receive the name of the reference and the `payload` value passed to this method.
* refs loose_lookup: also free the buffer on successCarlos Martín Nieto2011-03-221-0/+1
| | | | | Free the ref_file buffer at the end of the function also on success. This fixes a small memory leak.
* Refs are now always in-sync on diskVicent Marti2011-03-161-56/+129
|
* Do not segfault when listing unpacked referencesVicent Marti2011-03-151-1/+2
|
* Remove duplicate refs in `git_reference_listall`Vicent Marti2011-03-151-11/+18
|
* Skip the optional header in packed-refs filesVicent Marti2011-03-151-16/+10
|
* Fix the retarded object interdependency systemVicent Marti2011-03-141-6/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | It's no longer retarded. All object interdependencies are stored as OIDs instead of actual objects. This should be hundreds of times faster, specially on big repositories. Heck, who knows, maye it doesn't even segfault -- wouldn't that be awesome? What has changed on the API? `git_commit_parent`, `git_commit_tree`, `git_tag_target` now return their values through a pointer-to-pointer, and have an error code. `git_commit_set_tree` and `git_tag_set_target` now return an error code and may fail. `git_repository_free__no_gc` has been deprecated because it's stupid. Since there are no longer any interdependencies between objects, we don't need internal reference counting, and GC never fails or double-free's pointers. `git_object_close` now does a very sane thing: marks an object as unused. Closed objects will be eventually free'd from the object cache based on LRU. Please use `git_object_close` from the garbage collector `destroy` method on your bindings. It's 100% safe. `git_repository_gc` is a new method that forces a garbage collector pass through the repo, to free as many LRU objects as possible. This is useful if we are running out of memory.
* Add new method `git_reference_listall`Vicent Marti2011-03-141-0/+82
| | | | | | | Lists all the references in a repository. Listing may be filtered by reference type. This should applease Lord Clem.
* Fix creation of deeply-rooted referencesVicent Marti2011-03-051-1/+1
| | | | | | | Use a new `gitfo_creat_force` that will create the full path to a file before creating it. Signed-off-by: Vicent Marti <tanoku@gmail.com>
* Fix 'possibly uninitialized variable' warningVicent Marti2011-03-041-1/+1
|
* Fix searching in git_vectorVicent Marti2011-03-031-1/+1
| | | | | | | | | | | | | | | | | | We now store only one sorting callback that does entry comparison. This is used when sorting the entries using a quicksort, and when looking for a specific entry with the new search methods. The following search methods now exist: git_vector_search(vector, entry) git_vector_search2(vector, custom_search_callback, key) git_vector_bsearch(vector, entry) git_vector_bsearch2(vector, custom_search_callback, key) The sorting state of the vector is now stored internally. Signed-off-by: Vicent Marti <tanoku@gmail.com>