summaryrefslogtreecommitdiff
path: root/src/refdb.c
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2020-06-30 13:26:05 +0200
committerPatrick Steinhardt <ps@pks.im>2020-07-12 16:01:21 +0200
commitcf7dd05bdab243e1150f771359be6c2a766a0a3a (patch)
treeb47f658cefc33e485122d1e47a61235aa874e5cd /src/refdb.c
parentc54f40e47193af508b81eeec3ac7002649101360 (diff)
downloadlibgit2-cf7dd05bdab243e1150f771359be6c2a766a0a3a.tar.gz
refdb: return resolved symbolic refs pointing to nonexistent refs
In some cases, resolving references requires us to also know about the final symbolic reference that's pointing to a nonexistent branch, e.g. in an empty repository where the main branch is yet unborn but HEAD already points to it. Right now, the resolving logic is thus split up into two, where one is the new refdb implementation and the second one is an ad-hoc implementation inside "refs.c". Let's extend `git_refdb_resolve` to also return such final dangling references pointing to nonexistent branches so we can deduplicate the resolving logic.
Diffstat (limited to 'src/refdb.c')
-rw-r--r--src/refdb.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/refdb.c b/src/refdb.c
index 12dfaf1e2..6879b6aab 100644
--- a/src/refdb.c
+++ b/src/refdb.c
@@ -161,8 +161,16 @@ int git_refdb_resolve(
if (ref->type == GIT_REFERENCE_DIRECT)
break;
- if ((error = git_refdb_lookup(&resolved, db, git_reference_symbolic_target(ref))) < 0)
+
+ if ((error = git_refdb_lookup(&resolved, db, git_reference_symbolic_target(ref))) < 0) {
+ /* If we found a symbolic reference with a nonexistent target, return it. */
+ if (error == GIT_ENOTFOUND) {
+ error = 0;
+ *out = ref;
+ ref = NULL;
+ }
goto out;
+ }
git_reference_free(ref);
ref = resolved;