summaryrefslogtreecommitdiff
path: root/src/refs.c
Commit message (Collapse)AuthorAgeFilesLines
...
* Rename git_khash_str to git_strmap, etc.Russell Belfer2012-04-251-23/+23
| | | | | | This renamed `git_khash_str` to `git_strmap`, `git_hash_oid` to `git_oidmap`, and deletes `git_hashtable` from the tree, plus adds unit tests for `git_strmap`.
* Convert hashtable usage over to khashRussell Belfer2012-04-251-27/+45
| | | | | | | | | | | | | | | This updates khash.h with some extra features (like error checking on allocations, ability to use wrapped malloc, foreach calls, etc), creates two high-level wrappers around khash: `git_khash_str` and `git_khash_oid` for string-to-void-ptr and oid-to-void-ptr tables, then converts all of the old usage of `git_hashtable` over to use these new hashtables. For `git_khash_str`, I've tried to create a set of macros that yield an API not too unlike the old `git_hashtable` API. Since the oid hashtable is only used in one file, I haven't bother to set up all those macros and just use the khash APIs directly for now.
* Implement git_pool paged memory allocatorRussell Belfer2012-04-251-1/+1
| | | | | | | | | | | | | | | | | | This adds a `git_pool` object that can do simple paged memory allocation with free for the entire pool at once. Using this, you can replace many small allocations with large blocks that can then cheaply be doled out in small pieces. This is best used when you plan to free the small blocks all at once - for example, if they represent the parsed state from a file or data stream that are either all kept or all discarded. There are two real patterns of usage for `git_pools`: either for "string" allocation, where the item size is a single byte and you end up just packing the allocations in together, or for "fixed size" allocation where you are allocating a large object (e.g. a `git_oid`) and you generally just allocation single objects that can be tightly packed. Of course, you can use it for other things, but those two cases are the easiest.
* Rename to git_reference_name_to_oidRussell Belfer2012-04-231-1/+1
|
* Fix warnings on 64-bit windows buildsRussell Belfer2012-04-171-7/+7
| | | | | This fixes all the warnings on win64 except those in deps, which come from the regex code.
* Add git_reference_lookup_oid and lookup_resolvedRussell Belfer2012-04-171-51/+88
| | | | | | | | | | | | | | Adds a new public reference function `git_reference_lookup_oid` that directly resolved a reference name to an OID without returning the intermediate `git_reference` object (hence, no free needed). Internally, this adds a `git_reference_lookup_resolved` function that combines looking up and resolving a reference. This allows us to be more efficient with memory reallocation. The existing `git_reference_lookup` and `git_reference_resolve` are reimplmented on top of the new utility and a few places in the code are changed to use one of the two new functions.
* branch: add git_branch_move()nulltoken2012-04-101-0/+9
|
* Convert attr, ignore, mwindow, status to new errorsRussell Belfer2012-03-161-4/+4
| | | | | Also cleaned up some previously converted code that still had little things to polish.
* Migrate ODB files to new error handlingRussell Belfer2012-03-121-2/+2
| | | | | | | | | | | | | | This migrates odb.c, odb_loose.c, odb_pack.c and pack.c to the new style of error handling. Also got the unix and win32 versions of map.c. There are some minor changes to other files but no others were completely converted. This also contains an update to filebuf so that a zeroed out filebuf will not think that the fd (== 0) is actually open (and inadvertently call close() on fd 0 if cleaned up). Lastly, this was built and tested on win32 and contains a bunch of fixes for the win32 build which was pretty broken.
* Migrating diff to new error handlingRussell Belfer2012-03-061-2/+1
| | | | | | Ended up migrating a bunch of upstream functions as well including vector, attr_file, and odb in order to get this to work right.
* error-handling: ReferencesVicent Martí2012-03-061-434/+374
| | | | | Yes, this is error handling solely for `refs.c`, but some of the abstractions leak all ofer the code base.
* refs: Error handling rework. WIPVicent Martí2012-03-031-272/+239
|
* Clean up GIT_UNUSED macros on all platformsRussell Belfer2012-03-021-16/+13
| | | | | | | | | | | | | | | | | | | It turns out that commit 31e9cfc4cbcaf1b38cdd3dbe3282a8f57e5366a5 did not fix the GIT_USUSED behavior on all platforms. This commit walks through and really cleans things up more thoroughly, getting rid of the unnecessary stuff. To remove the use of some GIT_UNUSED, I ended up adding a couple of new iterators for hashtables that allow you to iterator just over keys or just over values. In making this change, I found a bug in the clar tests (where we were doing *count++ but meant to do (*count)++ to increment the value). I fixed that but then found the test failing because it was not really using an empty repo. So, I took some of the code that I wrote for iterator testing and moved it to clar_helpers.c, then made use of that to make it easier to open fixtures on a per test basis even within a single test file.
* buffer: Unify `git_fbuffer` and `git_buf`Vicent Martí2012-02-271-24/+24
| | | | | | | | | | | | | | This makes so much sense that I can't believe it hasn't been done before. Kill the old `git_fbuffer` and read files straight into `git_buf` objects. Also: In order to fully support 4GB files in 32-bit systems, the `git_buf` implementation has been changed from using `ssize_t` for storage and storing negative values on allocation failure, to using `size_t` and changing the buffer pointer to a magical pointer on allocation failure. Hopefully this won't break anything.
* Update Copyright headerschu2012-02-131-1/+1
| | | | Signed-off-by: schu <schu-github@schulog.org>
* refs: don't leak the packref when deleting/renamingCarlos Martín Nieto2012-01-191-2/+4
| | | | | When we remove the ref from the hashtable, we need to free the packref.
* Move path related functions from fileops to pathRussell Belfer2012-01-171-11/+11
| | | | | | | | | | | 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).
* Merge remote-tracking branch 'arrbee/git-attributes' into developmentVicent Martí2012-01-021-14/+1
|\ | | | | | | | | Conflicts: tests-clay/clay_main.c
| * Add APIs for git attributesRussell Belfer2011-12-201-14/+1
| | | | | | | | | | | | | | | | | | This adds APIs for querying git attributes. In addition to the new API in include/git2/attr.h, most of the action is in src/attr_file.[hc] which contains utilities for dealing with a single attributes file, and src/attr.[hc] which contains the implementation of the APIs that merge all applicable attributes files.
* | refs: Fix double freeVicent Martí2011-12-251-9/+11
|/ | | | Includes relevant Clay test
* Use git_buf for path storage instead of stack-based buffersRussell Belfer2011-12-071-64/+119
| | | | | | | | | | | | | | | | | | | | 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.
* Rename all `_close` methodsVicent Marti2011-11-261-1/+1
| | | | | There's no difference between `_free` and `_close` semantics: keep everything with the same name to avoid confusions.
* repository: Change ownership semanticsVicent Marti2011-11-261-6/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* Merge pull request #491 from schu/refs-cleanupVicent Martí2011-11-251-23/+13
|\ | | | | reference_rename() cleanup
| * reference_rename: don't delete the reflogschu2011-11-211-22/+9
| | | | | | | | | | | | | | | | reference_rename used to delete an old reflog file when renaming a reference to not confuse git.git. Don't do this anymore but let the user take care of writing a reflog entry. Signed-off-by: schu <schu-github@schulog.org>
| * reference_rename: make sure to rollbackschu2011-11-211-1/+4
| | | | | | | | | | | | | | Actually rollback when we can't create the new reference. Mark the rolled back reference as loose. Signed-off-by: schu <schu-github@schulog.org>
* | filebuf: add GIT_FILEBUF_INIT and protect multiple opens and cleanupsRussell Belfer2011-11-221-2/+2
|/ | | | | | | | Update all stack allocations of git_filebuf to use GIT_FILEBUF_INIT and make git_filebuf_open and git_filebuf_cleanup safe to be called multiple times on the same buffer. Signed-off-by: Vicent Marti <tanoku@gmail.com>
* refs: move GIT_PACKED_REFS_FILE_MODE to refs.h as GIT_PACKEDREFS_FILE_MODEBrodie Rao2011-11-161-3/+1
| | | | | This groups the #define with the other ref-related file modes, and it makes the name consistent with the other packed-refs definitions.
* refs: use 0666 permissions when writing packed-refs, not 0644Brodie Rao2011-11-161-1/+1
| | | | This matches stock Git's behavior.
* 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