]> git.ipfire.org Git - thirdparty/git.git/commitdiff
refs/files-backend: don't peek into `struct lock_file`
authorMartin Ågren <martin.agren@gmail.com>
Tue, 5 Jan 2021 19:23:49 +0000 (20:23 +0100)
committerJunio C Hamano <gitster@pobox.com>
Wed, 6 Jan 2021 21:53:32 +0000 (13:53 -0800)
Similar to the previous commits, avoid peeking into the `struct
lock_file`. Use the lock file API instead. Note how we obtain the path
to the lock file if `fdopen_lock_file()` failed and that this is not a
problem: as documented in lockfile.h, failure to "fdopen" does not roll
back the lock file and we're free to, e.g., query it for its path.

Signed-off-by: Martin Ågren <martin.agren@gmail.com>
Reviewed-by: Derrick Stolee <dstolee@microsoft.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
refs/files-backend.c

index 04e85e70029bf04e03ec25e008ae334cd35de39a..4fdc68810b3c1563d8e7301a67d9ff1396be3bbf 100644 (file)
@@ -1824,12 +1824,12 @@ static int create_symref_locked(struct files_ref_store *refs,
 
        if (!fdopen_lock_file(&lock->lk, "w"))
                return error("unable to fdopen %s: %s",
-                            lock->lk.tempfile->filename.buf, strerror(errno));
+                            get_lock_file_path(&lock->lk), strerror(errno));
 
        update_symref_reflog(refs, lock, refname, target, logmsg);
 
        /* no error check; commit_ref will check ferror */
-       fprintf(lock->lk.tempfile->fp, "ref: %s\n", target);
+       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));