summaryrefslogtreecommitdiff
path: root/src/refdb_fs.c
diff options
context:
space:
mode:
authorCarlos Martín Nieto <cmn@dwim.me>2014-02-04 22:04:00 +0100
committerCarlos Martín Nieto <cmn@dwim.me>2014-02-05 12:07:56 +0100
commit911236619b5d774e33dd9f3de92a7c86c2befb26 (patch)
tree528d64a959077a604232980cc092f92d04f0e13f /src/refdb_fs.c
parentd6236cf662ebd4ba8ef4902c81a19bbfd92847f9 (diff)
downloadlibgit2-911236619b5d774e33dd9f3de92a7c86c2befb26.tar.gz
refdb: add conditional symbolic updates
Add a parameter to the backend to allow checking for the old symbolic target.
Diffstat (limited to 'src/refdb_fs.c')
-rw-r--r--src/refdb_fs.c35
1 files changed, 18 insertions, 17 deletions
diff --git a/src/refdb_fs.c b/src/refdb_fs.c
index 554fe42c9..879e48514 100644
--- a/src/refdb_fs.c
+++ b/src/refdb_fs.c
@@ -936,12 +936,13 @@ static int refdb_fs_backend__write(
int force,
const git_signature *who,
const char *message,
- const git_oid *old_id)
+ const git_oid *old_id,
+ const char *old_target)
{
refdb_fs_backend *backend = (refdb_fs_backend *)_backend;
git_filebuf file = GIT_FILEBUF_INIT;
- git_reference *old_ref;
- int error = 0, cmp;
+ git_reference *old_ref = NULL;
+ int error = 0, cmp = 0;
assert(backend);
@@ -953,25 +954,25 @@ static int refdb_fs_backend__write(
if ((error = loose_lock(&file, backend, ref)) < 0)
return error;
- if (old_id) {
+ if (old_id || old_target) {
if ((error = refdb_fs_backend__lookup(&old_ref, _backend, ref->name)) < 0)
goto on_error;
+ }
- if (old_ref->type == GIT_REF_SYMBOLIC) {
- git_reference_free(old_ref);
- giterr_set(GITERR_REFERENCE, "cannot compare id to symbolic reference target");
- error = -1;
- goto on_error;
- }
-
- /* Finally we can compare the ids */
+ if (old_id && old_ref->type == GIT_REF_OID) {
cmp = git_oid_cmp(old_id, &old_ref->target.oid);
git_reference_free(old_ref);
- if (cmp) {
- giterr_set(GITERR_REFERENCE, "old reference value does not match");
- error = GIT_EMODIFIED;
- goto on_error;
- }
+ }
+
+ if (old_target && old_ref->type == GIT_REF_SYMBOLIC) {
+ cmp = git__strcmp(old_target, old_ref->target.symbolic);
+ git_reference_free(old_ref);
+ }
+
+ if (cmp) {
+ giterr_set(GITERR_REFERENCE, "old reference value does not match");
+ error = GIT_EMODIFIED;
+ goto on_error;
}
if (should_write_reflog(backend->repo, ref->name) &&