@@ -1920,26 +1920,39 @@ static void update_symref_reflog(struct files_ref_store *refs,
}
}
-static int create_symref_locked(struct files_ref_store *refs,
- struct ref_lock *lock, const char *refname,
- const char *target, const char *logmsg)
+static int create_symref_lock(struct files_ref_store *refs,
+ struct ref_lock *lock, const char *refname,
+ const char *target)
{
+ if (!fdopen_lock_file(&lock->lk, "w"))
+ return error("unable to fdopen %s: %s",
+ get_lock_file_path(&lock->lk), strerror(errno));
+
+ /* no error check; commit_ref will check ferror */
+ fprintf(get_lock_file_fp(&lock->lk), "ref: %s\n", target);
+ return 0;
+}
+
+static int create_and_commit_symref(struct files_ref_store *refs,
+ struct ref_lock *lock, const char *refname,
+ const char *target, const char *logmsg)
+{
+ int ret;
+
if (prefer_symlink_refs && !create_ref_symlink(lock, target)) {
update_symref_reflog(refs, lock, refname, target, logmsg);
return 0;
}
- if (!fdopen_lock_file(&lock->lk, "w"))
- return error("unable to fdopen %s: %s",
- get_lock_file_path(&lock->lk), strerror(errno));
+ ret = create_symref_lock(refs, lock, refname, target);
+ if (!ret) {
+ update_symref_reflog(refs, lock, refname, target, logmsg);
- update_symref_reflog(refs, lock, refname, target, logmsg);
+ if (commit_ref(lock) < 0)
+ return error("unable to write symref for %s: %s", refname,
+ strerror(errno));
+ }
- /* no error check; commit_ref will check ferror */
- fprintf(get_lock_file_fp(&lock->lk), "ref: %s\n", target);
- if (commit_ref(lock) < 0)
- return error("unable to write symref for %s: %s", refname,
- strerror(errno));
return 0;
}
@@ -1960,7 +1973,8 @@ static int files_create_symref(struct ref_store *ref_store,
return -1;
}
- ret = create_symref_locked(refs, lock, refname, target, logmsg);
+ ret = create_and_commit_symref(refs, lock, refname, target, logmsg);
+
unlock_ref(lock);
return ret;
}