Skip to content

Commit ad4cd6c

Browse files
mhaggergitster
authored andcommitted
commit_ref_update(): new function, extracted from write_ref_sha1()
Signed-off-by: Michael Haggerty <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e6fd3c6 commit ad4cd6c

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

refs.c

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3059,15 +3059,13 @@ static int write_ref_to_lockfile(struct ref_lock *lock,
30593059
}
30603060

30613061
/*
3062-
* Write sha1 into the ref specified by the lock. Make sure that errno
3063-
* is sane on error.
3062+
* Commit a change to a loose reference that has already been written
3063+
* to the loose reference lockfile. Also update the reflogs if
3064+
* necessary, using the specified lockmsg (which can be NULL).
30643065
*/
3065-
static int write_ref_sha1(struct ref_lock *lock,
3066-
const unsigned char *sha1, const char *logmsg)
3066+
static int commit_ref_update(struct ref_lock *lock,
3067+
const unsigned char *sha1, const char *logmsg)
30673068
{
3068-
if (write_ref_to_lockfile(lock, sha1))
3069-
return -1;
3070-
30713069
clear_loose_ref_cache(&ref_cache);
30723070
if (log_ref_write(lock->ref_name, lock->old_sha1, sha1, logmsg) < 0 ||
30733071
(strcmp(lock->ref_name, lock->orig_ref_name) &&
@@ -3106,6 +3104,21 @@ static int write_ref_sha1(struct ref_lock *lock,
31063104
return 0;
31073105
}
31083106

3107+
/*
3108+
* Write sha1 as the new value of the reference specified by the
3109+
* (open) lock. On error, roll back the lockfile and set errno
3110+
* appropriately.
3111+
*/
3112+
static int write_ref_sha1(struct ref_lock *lock,
3113+
const unsigned char *sha1, const char *logmsg)
3114+
{
3115+
if (write_ref_to_lockfile(lock, sha1) ||
3116+
commit_ref_update(lock, sha1, logmsg))
3117+
return -1;
3118+
3119+
return 0;
3120+
}
3121+
31093122
int create_symref(const char *ref_target, const char *refs_heads_master,
31103123
const char *logmsg)
31113124
{

0 commit comments

Comments
 (0)