Skip to content

Commit e6fd3c6

Browse files
mhaggergitster
authored andcommitted
write_ref_to_lockfile(): new function, extracted from write_ref_sha1()
This is the first step towards separating the checking and writing of the new reference value to committing the change. Signed-off-by: Michael Haggerty <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent fc38a9b commit e6fd3c6

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

refs.c

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3022,11 +3022,11 @@ int is_branch(const char *refname)
30223022
}
30233023

30243024
/*
3025-
* Write sha1 into the ref specified by the lock. Make sure that errno
3026-
* is sane on error.
3025+
* Write sha1 into the open lockfile, then close the lockfile. On
3026+
* errors, rollback the lockfile and set errno to reflect the problem.
30273027
*/
3028-
static int write_ref_sha1(struct ref_lock *lock,
3029-
const unsigned char *sha1, const char *logmsg)
3028+
static int write_ref_to_lockfile(struct ref_lock *lock,
3029+
const unsigned char *sha1)
30303030
{
30313031
static char term = '\n';
30323032
struct object *o;
@@ -3055,6 +3055,19 @@ static int write_ref_sha1(struct ref_lock *lock,
30553055
errno = save_errno;
30563056
return -1;
30573057
}
3058+
return 0;
3059+
}
3060+
3061+
/*
3062+
* Write sha1 into the ref specified by the lock. Make sure that errno
3063+
* is sane on error.
3064+
*/
3065+
static int write_ref_sha1(struct ref_lock *lock,
3066+
const unsigned char *sha1, const char *logmsg)
3067+
{
3068+
if (write_ref_to_lockfile(lock, sha1))
3069+
return -1;
3070+
30583071
clear_loose_ref_cache(&ref_cache);
30593072
if (log_ref_write(lock->ref_name, lock->old_sha1, sha1, logmsg) < 0 ||
30603073
(strcmp(lock->ref_name, lock->orig_ref_name) &&

0 commit comments

Comments
 (0)