summaryrefslogtreecommitdiff
path: root/src/refs.c
Commit message (Collapse)AuthorAgeFilesLines
* refs: refuse to delete HEADJosh Bleecher Snyder2020-01-151-0/+5
| | | | | | | This requires adding a new symbolic ref to the testrepo fixture. Some of the existing tests attempt to delete HEAD, expecting a different failure. Introduce and use a non-HEAD symbolic ref instead. Adjust a few other tests as needed. Fixes #5357
* refs: rename git_reference__set_name to git_reference__reallocEtienne Samson2019-12-131-5/+10
| | | | | | | | | | | As git_reference__name will reallocate storage to account for longer names (it's actually allocator-dependent), it will cause all existing pointers to the old object to become dangling, as they now point to freed memory. Fix the issue by renaming to a more descriptive name, and pass a pointer to the actual reference that can safely be invalidated if the realloc succeeds.
* fileops: rename to "futils.h" to match function signaturesPatrick Steinhardt2019-07-201-1/+1
| | | | | | | | | Our file utils functions all have a "futils" prefix, e.g. `git_futils_touch`. One would thus naturally guess that their definitions and implementation would live in files "futils.h" and "futils.c", respectively, but in fact they live in "fileops.h". Rename the files to match expectations.
* configuration: cvar -> configmapPatrick Steinhardt2019-07-181-1/+1
| | | | | `cvar` is an unhelpful name. Refactor its usage to `configmap` for more clarity.
* oid: `is_zero` instead of `iszero`Edward Thomson2019-06-161-2/+2
| | | | | | The only function that is named `issomething` (without underscore) was `git_oid_iszero`. Rename it to `git_oid_is_zero` for consistency with the rest of the library.
* refs: loosen restriction on wildcard "*" refspecsPatrick Steinhardt2019-04-261-13/+19
| | | | | | | | | | | | In commit cd377f45c9 (refs: loosen restriction on wildcard "*" refspecs, 2015-07-22) in git.git, the restrictions on wildcard "*" refspecs has been loosened. While wildcards were previously only allowed if the component is a single "*", this was changed to also accept other patterns as part of the component. We never adapted to that change and still reject any wildcard patterns that aren't a single "*" only. Update our tests to reflect the upstream change and adjust our own code accordingly.
* branches: introduce flag to skip enumeration of certain HEADsPatrick Steinhardt2019-02-141-1/+1
| | | | | | | Right now, the function `git_repository_foreach_head` will always iterate over all HEADs of the main repository and its worktrees. In some cases, it might be required to skip either of those, though. Add a flag in preparation for the following commit that enables this behaviour.
* git_error: use new names in internal APIs and usageEdward Thomson2019-01-221-25/+25
| | | | | Move to the `git_error` name in the internal API for error-related functions.
* references: use new names in internal usageethomson/git_refEdward Thomson2019-01-171-38/+38
| | | | Update internal usage to use the `git_reference` names for constants.
* refs: assert that we're passed valid refs when renamingEtienne Samson2019-01-041-0/+2
| | | CID 1382962
* refs: constify git_reference_peelCarlos Martín Nieto2018-12-141-7/+8
| | | | | | | We have no need to take a non-const reference. This does involve some other work to make sure we don't mix const and non-const variables, but by splitting what we want each variable to do we can also simplify the logic for when we do want to free a new reference we might have allocated.
* object_type: use new enumeration namesethomson/index_fixesEdward Thomson2018-12-011-6/+6
| | | | Use the new object_type enumeration names within the codebase.
* merge: make analysis possible against a non-HEAD referenceEtienne Samson2018-10-191-0/+24
| | | | | | | This moves the current merge analysis code into a more generic version that can work against any reference. Also change the tests to check returned analysis values exactly.
* Convert usage of `git_buf_free` to new `git_buf_dispose`Patrick Steinhardt2018-06-101-6/+6
|
* refs: preserve the owning refdb when duping referenceEtienne Samson2018-04-101-0/+3
| | | This fixes a segfault in git_reference_owner on references returned from git_reference__read_head and git_reference_dup ones.
* refs: do not use peeled OID if peeling to a tagPatrick Steinhardt2017-10-061-1/+7
| | | | | | | | | | | | | | | | | | | | | | If a reference stored in a packed-refs file does not directly point to a commit, tree or blob, the packed-refs file will also will include a fully-peeled OID pointing to the first underlying object of that type. If we try to peel a reference to an object, we will use that peeled OID to speed up resolving the object. As a reference for an annotated tag does not directly point to a commit, tree or blob but instead to the tag object, the packed-refs file will have an accomodating fully-peeled OID pointing to the object referenced by that tag. When we use the fully-peeled OID pointing to the referenced object when peeling, we obviously cannot peel that to the tag anymore. Fix this issue by not using the fully-peeled OID whenever we want to peel to a tag. Note that this does not include the case where we want to resolve to _any_ object type. Existing code may make use from the fact that we resolve those to commit objects instead of tag objects, even though that behaviour is inconsistent between packed and loose references. Furthermore, some tests of ours make the assumption that we in fact resolve those references to a commit.
* Make sure to always include "common.h" firstPatrick Steinhardt2017-07-031-0/+1
| | | | | | | | | | | | | | | | | | | | | | Next to including several files, our "common.h" header also declares various macros which are then used throughout the project. As such, we have to make sure to always include this file first in all implementation files. Otherwise, we might encounter problems or even silent behavioural differences due to macros or defines not being defined as they should be. So in fact, our header and implementation files should make sure to always include "common.h" first. This commit does so by establishing a common include pattern. Header files inside of "src" will now always include "common.h" as its first other file, separated by a newline from all the other includes to make it stand out as special. There are two cases for the implementation files. If they do have a matching header file, they will always include this one first, leading to "common.h" being transitively included as first file. If they do not have a matching header file, they instead include "common.h" as first file themselves. This fixes the outlined problems and will become our standard practice for header and source files inside of the "src/" from now on.
* refs: properly report errors from `update_wt_heads`Patrick Steinhardt2017-06-081-6/+16
|
* worktrees: cleanup some memory leaksEdward Thomson2017-05-011-2/+2
| | | | | Be sure to clean up looked up references. Free buffers instead of merely clearing them. Use `git__free` instead of `free`.
* refs: update worktree HEADs when renaming branchesPatrick Steinhardt2017-04-051-8/+45
| | | | | | | Whenever we rename a branch, we update the repository's symbolic HEAD reference if it currently points to the branch that is to be renamed. But with the introduction of worktrees, we also have to iterate over all HEADs of linked worktrees to adjust them. Do so.
* refs: implement function to read references from filePatrick Steinhardt2017-04-051-0/+34
| | | | | | | | | Currently, we only provide functions to read references directly from a repository's reference store via e.g. `git_reference_lookup`. But in some cases, we may want to read files not connected to the current repository, e.g. when looking up HEAD of connected work trees. This commit implements `git_reference__read_head`, which will read out and allocate a reference at an arbitrary path.
* Fix: make reflog include "(merge)" for merge commitsRichard Ipsum2017-02-271-1/+13
| | | | This fixes issue #4094
* strmap: remove GIT__USE_STRMAP macroPatrick Steinhardt2017-02-171-2/+0
|
* Merge branch 'pr/3912'Edward Thomson2017-01-211-6/+23
|\
| * symbolic ref target validation: fixupsEdward Thomson2017-01-211-29/+9
| | | | | | | | Fixups requested in #3912.
| * Make symbolic ref target validation optionalRichard Ipsum2016-08-271-4/+41
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Introduce GIT_OPT_ENABLE_SYMBOLIC_REF_TARGET_VALIDATION option. Setting this option to 0 allows validation of a symbolic ref's target to be bypassed. This option is enabled by default. This mechanism is added primarily to address a discrepancy between git behaviour and libgit2 behaviour, whereby the former allows the symbolic ref target to carry an arbitrary string and the latter does not, so: $ git symbolic-ref refs/heads/foo bar $ cat .git/refs/heads/foo ref: bar where as attempting the same via libgit2 raises an error: The given reference name 'bar' is not valid this mechanism also allows those that might want to make use of git's more lenient treatment of symbolic ref targets to do so.
* | giterr_set: consistent error messagesEdward Thomson2016-12-291-11/+11
|/ | | | | | | | Error messages should be sentence fragments, and therefore: 1. Should not begin with a capital letter, 2. Should not conclude with punctuation, and 3. Should not end a sentence and begin a new one
* Allow creating copies of `git_reference` objects.Arthur Schreiber2016-04-221-1/+13
|
* refs: provide a more general error message for dwimcmn/dwim-general-messageCarlos Martín Nieto2016-04-111-0/+3
| | | | | | | If we cannot dwim the input, set the error message to be explicit about that. Otherwise we leave the error for the last failed lookup, which can be rather unexpected as it mentions a remote when the user thought they were trying to look up a branch.
* refs: honor strict object creationEdward Thomson2016-02-281-7/+1
|
* Fixed Xcode 6.1 build warningsPierre-Olivier Latour2015-06-151-1/+1
|
* squash some leaksEdward Thomson2015-03-241-5/+3
|
* Plug a few leaksCarlos Martín Nieto2015-03-041-4/+6
|
* repository: remove log message override for switching the active branchCarlos Martín Nieto2015-03-031-4/+7
| | | | | | We want to use the "checkout: moving from ..." message in order to let git know when a change of branch has happened. Make the convenience functions for this goal write this message.
* Remove the signature from ref-modifying functionsCarlos Martín Nieto2015-03-031-68/+85
| | | | | | | | | | The signature for the reflog is not something which changes dynamically. Almost all uses will be NULL, since we want for the repository's default identity to be used, making it noise. In order to allow for changing the identity, we instead provide git_repository_set_ident() and git_repository_ident() which allow a user to override the choice of signature.
* Remove extra semicolon outside of a functionStefan Widgren2015-02-151-1/+1
| | | | | Without this change, compiling with gcc and pedantic generates warning: ISO C does not allow extra ‘;’ outside of a function.
* Make our overflow check look more like gcc/clang'sEdward Thomson2015-02-131-12/+10
| | | | | | | | | Make our overflow checking look more like gcc and clang's, so that we can substitute it out with the compiler instrinsics on platforms that support it. This means dropping the ability to pass `NULL` as an out parameter. As a result, the macros also get updated to reflect this as well.
* overflow checking: don't make callers set oomEdward Thomson2015-02-121-3/+1
| | | | | | Have the ALLOC_OVERFLOW testing macros also simply set_oom in the case where a computation would overflow, so that callers don't need to.
* allocations: test for overflow of requested sizeEdward Thomson2015-02-121-5/+13
| | | | | Introduce some helper macros to test integer overflow from arithmetic and set error message appropriately.
* git_rebase_commit: write HEAD's reflog appropriatelyEdward Thomson2014-10-261-0/+35
|
* Introduce reference transactionsCarlos Martín Nieto2014-09-301-3/+3
| | | | | | | | | A transaction allows you to lock multiple references and set up changes for them before applying the changes all at once (or as close as the backend supports). This can be used for replication purposes, or for making sure some operations run when the reference is locked and thus cannot be changed.
* Refs: Introduce `git_refname_t`.Arthur Schreiber2014-05-301-13/+10
|
* Refs: Fix some issue when core.precomposeunicode = true.Arthur Schreiber2014-05-301-24/+9
| | | | | | | | | | | This fixes two issues I found when core.precomposeunicode is enabled: * When creating a reference with a NFD string, the returned git_reference would return this NFD string as the reference’s name. But when looking up the reference later, the name would then be returned as NFC string. * Renaming a reference would not honor the core.precomposeunicode and apply no normalization to the new reference name.
* Const correctness!Jacques Germishuys2014-04-031-5/+7
|
* branch: constness fixesCarlos Martín Nieto2014-03-171-1/+1
|
* refs: move current_id before the reflog parametersCarlos Martín Nieto2014-02-101-8/+8
| | | | | Keep the reflog parameters as the last two, as they're the optional parameters.
* Merge pull request #2099 from libgit2/bs/more-reflog-stuffRussell Belfer2014-02-071-1/+3
|\ | | | | More reflogness
| * Add reset tests for reflogBen Straub2014-02-031-1/+3
| |
* | refs: add an unconditional deleteCarlos Martín Nieto2014-02-051-0/+11
| | | | | | | | | | Add it under the git_reference_remove() name, letting the user pass the repo and name, analogous to unconditional setting/creation.
* | refs: check the ref's old value when deletingCarlos Martín Nieto2014-02-051-1/+9
| | | | | | | | Recognize when the reference has changed since we loaded it.