Skip to content

Commit 9849129

Browse files
bk2204gitster
authored andcommitted
refs: convert struct ref_update to use struct object_id
Convert struct ref_array_item to use struct object_id by changing the definition and applying the following semantic patch, plus the standard object_id transforms: @@ struct ref_update E1; @@ - E1.new_sha1 + E1.new_oid.hash @@ struct ref_update *E1; @@ - E1->new_sha1 + E1->new_oid.hash @@ struct ref_update E1; @@ - E1.old_sha1 + E1.old_oid.hash @@ struct ref_update *E1; @@ - E1->old_sha1 + E1->old_oid.hash This transformation allows us to convert write_ref_to_lockfile, which is required to convert parse_object. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 9850fe5 commit 9849129

File tree

3 files changed

+19
-18
lines changed

3 files changed

+19
-18
lines changed

refs.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -882,9 +882,9 @@ struct ref_update *ref_transaction_add_update(
882882
update->flags = flags;
883883

884884
if (flags & REF_HAVE_NEW)
885-
hashcpy(update->new_sha1, new_sha1);
885+
hashcpy(update->new_oid.hash, new_sha1);
886886
if (flags & REF_HAVE_OLD)
887-
hashcpy(update->old_sha1, old_sha1);
887+
hashcpy(update->old_oid.hash, old_sha1);
888888
update->msg = xstrdup_or_null(msg);
889889
return update;
890890
}

refs/files-backend.c

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2633,7 +2633,7 @@ static int split_head_update(struct ref_update *update,
26332633
new_update = ref_transaction_add_update(
26342634
transaction, "HEAD",
26352635
update->flags | REF_LOG_ONLY | REF_NODEREF,
2636-
update->new_sha1, update->old_sha1,
2636+
update->new_oid.hash, update->old_oid.hash,
26372637
update->msg);
26382638

26392639
item->util = new_update;
@@ -2690,7 +2690,7 @@ static int split_symref_update(struct files_ref_store *refs,
26902690

26912691
new_update = ref_transaction_add_update(
26922692
transaction, referent, new_flags,
2693-
update->new_sha1, update->old_sha1,
2693+
update->new_oid.hash, update->old_oid.hash,
26942694
update->msg);
26952695

26962696
new_update->parent_update = update;
@@ -2729,24 +2729,24 @@ static int check_old_oid(struct ref_update *update, struct object_id *oid,
27292729
struct strbuf *err)
27302730
{
27312731
if (!(update->flags & REF_HAVE_OLD) ||
2732-
!hashcmp(oid->hash, update->old_sha1))
2732+
!oidcmp(oid, &update->old_oid))
27332733
return 0;
27342734

2735-
if (is_null_sha1(update->old_sha1))
2735+
if (is_null_oid(&update->old_oid))
27362736
strbuf_addf(err, "cannot lock ref '%s': "
27372737
"reference already exists",
27382738
original_update_refname(update));
27392739
else if (is_null_oid(oid))
27402740
strbuf_addf(err, "cannot lock ref '%s': "
27412741
"reference is missing but expected %s",
27422742
original_update_refname(update),
2743-
sha1_to_hex(update->old_sha1));
2743+
oid_to_hex(&update->old_oid));
27442744
else
27452745
strbuf_addf(err, "cannot lock ref '%s': "
27462746
"is at %s but expected %s",
27472747
original_update_refname(update),
27482748
oid_to_hex(oid),
2749-
sha1_to_hex(update->old_sha1));
2749+
oid_to_hex(&update->old_oid));
27502750

27512751
return -1;
27522752
}
@@ -2773,13 +2773,13 @@ static int lock_ref_for_update(struct files_ref_store *refs,
27732773
{
27742774
struct strbuf referent = STRBUF_INIT;
27752775
int mustexist = (update->flags & REF_HAVE_OLD) &&
2776-
!is_null_sha1(update->old_sha1);
2776+
!is_null_oid(&update->old_oid);
27772777
int ret;
27782778
struct ref_lock *lock;
27792779

27802780
files_assert_main_repository(refs, "lock_ref_for_update");
27812781

2782-
if ((update->flags & REF_HAVE_NEW) && is_null_sha1(update->new_sha1))
2782+
if ((update->flags & REF_HAVE_NEW) && is_null_oid(&update->new_oid))
27832783
update->flags |= REF_DELETING;
27842784

27852785
if (head_ref) {
@@ -2861,12 +2861,12 @@ static int lock_ref_for_update(struct files_ref_store *refs,
28612861
!(update->flags & REF_DELETING) &&
28622862
!(update->flags & REF_LOG_ONLY)) {
28632863
if (!(update->type & REF_ISSYMREF) &&
2864-
!hashcmp(lock->old_oid.hash, update->new_sha1)) {
2864+
!oidcmp(&lock->old_oid, &update->new_oid)) {
28652865
/*
28662866
* The reference already has the desired
28672867
* value, so we don't need to write it.
28682868
*/
2869-
} else if (write_ref_to_lockfile(lock, update->new_sha1,
2869+
} else if (write_ref_to_lockfile(lock, update->new_oid.hash,
28702870
err)) {
28712871
char *write_err = strbuf_detach(err, NULL);
28722872

@@ -3002,7 +3002,7 @@ static int files_transaction_commit(struct ref_store *ref_store,
30023002
if (files_log_ref_write(refs,
30033003
lock->ref_name,
30043004
lock->old_oid.hash,
3005-
update->new_sha1,
3005+
update->new_oid.hash,
30063006
update->msg, update->flags,
30073007
err)) {
30083008
char *old_msg = strbuf_detach(err, NULL);
@@ -3151,7 +3151,7 @@ static int files_initial_transaction_commit(struct ref_store *ref_store,
31513151
struct ref_update *update = transaction->updates[i];
31523152

31533153
if ((update->flags & REF_HAVE_OLD) &&
3154-
!is_null_sha1(update->old_sha1))
3154+
!is_null_oid(&update->old_oid))
31553155
die("BUG: initial ref transaction with old_sha1 set");
31563156
if (refs_verify_refname_available(&refs->base, update->refname,
31573157
&affected_refnames, NULL,
@@ -3172,8 +3172,9 @@ static int files_initial_transaction_commit(struct ref_store *ref_store,
31723172
struct ref_update *update = transaction->updates[i];
31733173

31743174
if ((update->flags & REF_HAVE_NEW) &&
3175-
!is_null_sha1(update->new_sha1))
3176-
add_packed_ref(refs, update->refname, update->new_sha1);
3175+
!is_null_oid(&update->new_oid))
3176+
add_packed_ref(refs, update->refname,
3177+
update->new_oid.hash);
31773178
}
31783179

31793180
if (commit_packed_refs(refs)) {

refs/refs-internal.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,13 @@ struct ref_update {
130130
/*
131131
* If (flags & REF_HAVE_NEW), set the reference to this value:
132132
*/
133-
unsigned char new_sha1[20];
133+
struct object_id new_oid;
134134

135135
/*
136136
* If (flags & REF_HAVE_OLD), check that the reference
137137
* previously had this value:
138138
*/
139-
unsigned char old_sha1[20];
139+
struct object_id old_oid;
140140

141141
/*
142142
* One or more of REF_HAVE_NEW, REF_HAVE_OLD, REF_NODEREF,

0 commit comments

Comments
 (0)