Skip to content

Commit e9965ba

Browse files
KarthikNayakgitster
authored andcommitted
refs: move original_update_refname to 'refs.c'
The files backend and the reftable backend implement `original_update_refname` to obtain the original refname of the update. Move it out to 'refs.c' and only expose it internally to the refs library. This will be used in an upcoming commit to also introduce another common functionality for the two backends. We also rename the function to `ref_update_original_update_refname` to keep it consistent with the upcoming other 'ref_update_*' functions that'll be introduced. Signed-off-by: Karthik Nayak <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a8ae923 commit e9965ba

File tree

4 files changed

+25
-33
lines changed

4 files changed

+25
-33
lines changed

refs.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2814,3 +2814,11 @@ int copy_existing_ref(const char *oldref, const char *newref, const char *logmsg
28142814
{
28152815
return refs_copy_existing_ref(get_main_ref_store(the_repository), oldref, newref, logmsg);
28162816
}
2817+
2818+
const char *ref_update_original_update_refname(struct ref_update *update)
2819+
{
2820+
while (update->parent_update)
2821+
update = update->parent_update;
2822+
2823+
return update->refname;
2824+
}

refs/files-backend.c

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2423,17 +2423,6 @@ static int split_symref_update(struct ref_update *update,
24232423
return 0;
24242424
}
24252425

2426-
/*
2427-
* Return the refname under which update was originally requested.
2428-
*/
2429-
static const char *original_update_refname(struct ref_update *update)
2430-
{
2431-
while (update->parent_update)
2432-
update = update->parent_update;
2433-
2434-
return update->refname;
2435-
}
2436-
24372426
/*
24382427
* Check whether the REF_HAVE_OLD and old_oid values stored in update
24392428
* are consistent with oid, which is the reference's current value. If
@@ -2450,16 +2439,16 @@ static int check_old_oid(struct ref_update *update, struct object_id *oid,
24502439
if (is_null_oid(&update->old_oid))
24512440
strbuf_addf(err, "cannot lock ref '%s': "
24522441
"reference already exists",
2453-
original_update_refname(update));
2442+
ref_update_original_update_refname(update));
24542443
else if (is_null_oid(oid))
24552444
strbuf_addf(err, "cannot lock ref '%s': "
24562445
"reference is missing but expected %s",
2457-
original_update_refname(update),
2446+
ref_update_original_update_refname(update),
24582447
oid_to_hex(&update->old_oid));
24592448
else
24602449
strbuf_addf(err, "cannot lock ref '%s': "
24612450
"is at %s but expected %s",
2462-
original_update_refname(update),
2451+
ref_update_original_update_refname(update),
24632452
oid_to_hex(oid),
24642453
oid_to_hex(&update->old_oid));
24652454

@@ -2513,7 +2502,7 @@ static int lock_ref_for_update(struct files_ref_store *refs,
25132502

25142503
reason = strbuf_detach(err, NULL);
25152504
strbuf_addf(err, "cannot lock ref '%s': %s",
2516-
original_update_refname(update), reason);
2505+
ref_update_original_update_refname(update), reason);
25172506
free(reason);
25182507
goto out;
25192508
}
@@ -2533,7 +2522,7 @@ static int lock_ref_for_update(struct files_ref_store *refs,
25332522
if (update->flags & REF_HAVE_OLD) {
25342523
strbuf_addf(err, "cannot lock ref '%s': "
25352524
"error reading reference",
2536-
original_update_refname(update));
2525+
ref_update_original_update_refname(update));
25372526
ret = TRANSACTION_GENERIC_ERROR;
25382527
goto out;
25392528
}

refs/refs-internal.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -749,4 +749,9 @@ void base_ref_store_init(struct ref_store *refs, struct repository *repo,
749749
*/
750750
struct ref_store *maybe_debug_wrap_ref_store(const char *gitdir, struct ref_store *store);
751751

752+
/*
753+
* Return the refname under which update was originally requested.
754+
*/
755+
const char *ref_update_original_update_refname(struct ref_update *update);
756+
752757
#endif /* REFS_REFS_INTERNAL_H */

refs/reftable-backend.c

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -578,16 +578,6 @@ static int reftable_be_read_symbolic_ref(struct ref_store *ref_store,
578578
return ret;
579579
}
580580

581-
/*
582-
* Return the refname under which update was originally requested.
583-
*/
584-
static const char *original_update_refname(struct ref_update *update)
585-
{
586-
while (update->parent_update)
587-
update = update->parent_update;
588-
return update->refname;
589-
}
590-
591581
struct reftable_transaction_update {
592582
struct ref_update *update;
593583
struct object_id current_oid;
@@ -866,7 +856,7 @@ static int reftable_be_transaction_prepare(struct ref_store *ref_store,
866856
/* The reference does not exist, but we expected it to. */
867857
strbuf_addf(err, _("cannot lock ref '%s': "
868858
"unable to resolve reference '%s'"),
869-
original_update_refname(u), u->refname);
859+
ref_update_original_update_refname(u), u->refname);
870860
ret = -1;
871861
goto done;
872862
}
@@ -938,17 +928,17 @@ static int reftable_be_transaction_prepare(struct ref_store *ref_store,
938928
if (u->flags & REF_HAVE_OLD && !oideq(&current_oid, &u->old_oid)) {
939929
if (is_null_oid(&u->old_oid))
940930
strbuf_addf(err, _("cannot lock ref '%s': "
941-
"reference already exists"),
942-
original_update_refname(u));
931+
"reference already exists"),
932+
ref_update_original_update_refname(u));
943933
else if (is_null_oid(&current_oid))
944934
strbuf_addf(err, _("cannot lock ref '%s': "
945-
"reference is missing but expected %s"),
946-
original_update_refname(u),
935+
"reference is missing but expected %s"),
936+
ref_update_original_update_refname(u),
947937
oid_to_hex(&u->old_oid));
948938
else
949939
strbuf_addf(err, _("cannot lock ref '%s': "
950-
"is at %s but expected %s"),
951-
original_update_refname(u),
940+
"is at %s but expected %s"),
941+
ref_update_original_update_refname(u),
952942
oid_to_hex(&current_oid),
953943
oid_to_hex(&u->old_oid));
954944
ret = -1;

0 commit comments

Comments
 (0)