summaryrefslogtreecommitdiff
path: root/src/refs.c
Commit message (Collapse)AuthorAgeFilesLines
...
* Write packed-refs with 0644 permissionsCarlos Martín Nieto2011-11-071-1/+3
| | | | Signed-off-by: Carlos Martín Nieto <carlos@cmartin.tk>
* Reword packed-refs error messages so they're easier to track downCarlos Martín Nieto2011-11-071-4/+4
| | | | Signed-off-by: Carlos Martín Nieto <carlos@cmartin.tk>
* refs: Partial rewrite for read-only refsVicent Marti2011-11-061-839/+615
| | | | | | | | | | | | | | | | | | | | | | | | | This new version of the references code is significantly faster and hopefully easier to read. External API stays the same. A new method `git_reference_reload()` has been added to force updating a memory reference from disk. In-memory references are no longer updated automagically -- this was killing us. If a reference is deleted externally and the user doesn't reload the memory object, nothing critical happens: any functions using that reference should fail gracefully (e.g. deletion, renaming, and so on). All generated references from the API are read only and must be free'd by the user. There is no reference counting and no traces of generated references are kept in the library. There is no longer an internal representation for references. There is only one reference struct `git_reference`, and symbolic/oid targets are stored inside an union. Packfile references are stored using an optimized struct with flex array for reference names. This should significantly reduce the memory cost of loading the packfile from disk.
* git_reference_rename: cleanup reference renamingschu2011-11-061-37/+35
| | | | | | | | | git_reference_rename() didn't properly cleanup old references given by the user to not break some ugly old tests. Since references don't point to libgit's internal cache anymore we can cleanup git_reference_rename() to be somewhat less messy. Signed-off-by: schu <schu-github@schulog.org>
* refs: split internal and external referencesschu2011-11-061-124/+300
| | | | | | | | | | | | | | | | | Currently libgit2 shares pointers to its internal reference cache with the user. This leads to several problems like invalidation of reference pointers when reordering the cache or manipulation of the cache from user side. Give each user its own git_reference instead of leaking the internal representation (struct reference). Add the following new API functions: * git_reference_free * git_reference_is_packed Signed-off-by: schu <schu-github@schulog.org>
* Merge pull request #456 from brodie/perm-fixesVicent Martí2011-10-281-2/+3
|\ | | | | Create objects, indexes, and directories with the right file permissions
| * *: correct and codify various file permissionsBrodie Rao2011-10-141-2/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The following files now have 0444 permissions: - loose objects - pack indexes - pack files - packs downloaded by fetch - packs downloaded by the HTTP transport And the following files now have 0666 permissions: - config files - repository indexes - reflogs - refs This brings libgit2 more in line with Git. Note that git_filebuf_commit() and git_filebuf_commit_at() have both gained a new mode parameter. The latter change fixes an important issue where filebufs created with GIT_FILEBUF_TEMPORARY received 0600 permissions (due to mkstemp(3) usage). Now we chmod() the file before renaming it into place. Tests have been added to confirm that new commit, tag, and tree objects are created with the right permissions. I don't have access to Windows, so for now I've guarded the tests with "#ifndef GIT_WIN32".
* | global: Properly use `git__` memory wrappersVicent Marti2011-10-281-8/+8
|/ | | | | Ensure that all memory related functions (malloc, calloc, strdup, free, etc) are using their respective `git__` wrappers.
* fetch: store FETCH_HEADCarlos Martín Nieto2011-10-081-1/+2
| | | | | | We should always save the remote's HEAD as FETCH_HEAD locally. Signed-off-by: Carlos Martín Nieto <carlos@cmartin.tk>
* refs.c: fix reference_renameschu2011-09-301-1/+1
| | | | | | | | 6c8b458 removed an "unused" variable needed for git_hashtable_insert2(), causing a segfault in reference_rename(). Instead, use git_hashtable_insert(). Signed-off-by: schu <schu-github@schulog.org>
* mingw: Fix compilation warningsVicent Marti2011-09-291-14/+20
|
* refs: fix git_reference_rename()schu2011-09-201-4/+7
| | | | | | | | reference_rename() recently failed when renaming an existing reference refs/heads/foo/bar -> refs/heads/foo because of a change in the underlying functions / error codes. Fixes #412. Signed-off-by: schu <schu-github@schulog.org>
* Merge pull request #384 from kiryl/warningsVicent Martí2011-09-181-1/+1
|\ | | | | Add more -W flags to CFLAGS
| * CMakefile: add -Wmissing-prototypes and fix warningsKirill A. Shutemov2011-08-301-1/+1
| | | | | | | | Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name>
* | Tabify everythingVicent Marti2011-09-191-9/+9
| | | | | | | | | | | | There were quite a few places were spaces were being used instead of tabs. Try to catch them all. This should hopefully not break anything. Except for `git blame`. Oh well.
* | Cleanup legal dataVicent Marti2011-09-191-21/+3
|/ | | | | | | | | | 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.
* refs.c: remove two lines of dead codeschu2011-08-171-2/+0
| | | | Signed-off-by: schu <schu-github@schulog.org>
* Fix the reference character check for UnicodeCarlos Martín Nieto2011-08-161-2/+2
| | | | | | | We need to do an unsigned comparison, as otherwise UTF-8 characters might look like they have the sign bit set and the check will fail. Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
* util: Add git__strcmp_cb() wrappernulltoken2011-08-091-5/+3
| | | | We don't want direct pointers to the CRT on Windows, we may get stdcall conflicts.
* Fix compilation in WindowsVicent Marti2011-08-081-2/+0
|
* Merge pull request #335 from carlosmn/read-updatedVicent Martí2011-07-281-53/+45
|\ | | | | Don't stat so much when reading references
| * 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