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>
brian m. carlson committed
May 6, 2017 at 22:10 UTC
984912989d6c4bc4c34bcf4296173ed96b22d272
3 files changed
+19
-18
refs.c
+2
-2
@@ -882,9 +882,9 @@ struct ref_update *ref_transaction_add_update(
882
update->flags = flags;
883
884
if (flags & REF_HAVE_NEW)
885
- hashcpy(update->new_sha1, new_sha1);
885
+ hashcpy(update->new_oid.hash, new_sha1);
886
if (flags & REF_HAVE_OLD)
887
- hashcpy(update->old_sha1, old_sha1);
887
+ hashcpy(update->old_oid.hash, old_sha1);
888
update->msg = xstrdup_or_null(msg);
889
return update;
890
}
refs/files-backend.c
+15
-14
@@ -2633,7 +2633,7 @@ static int split_head_update(struct ref_update *update,
2633
new_update = ref_transaction_add_update(
2634
transaction, "HEAD",
2635
update->flags | REF_LOG_ONLY | REF_NODEREF,
2636
- update->new_sha1, update->old_sha1,
2636
+ update->new_oid.hash, update->old_oid.hash,
2637
update->msg);
2638
2639
item->util = new_update;
@@ -2690,7 +2690,7 @@ static int split_symref_update(struct files_ref_store *refs,
2690
2691
new_update = ref_transaction_add_update(
2692
transaction, referent, new_flags,
2693
- update->new_sha1, update->old_sha1,
2693
+ update->new_oid.hash, update->old_oid.hash,
2694
update->msg);
2695
2696
new_update->parent_update = update;
@@ -2729,10 +2729,10 @@ static int check_old_oid(struct ref_update *update, struct object_id *oid,
2729
struct strbuf *err)
2730
{
2731
if (!(update->flags & REF_HAVE_OLD) ||
2732
- !hashcmp(oid->hash, update->old_sha1))
2732
+ !oidcmp(oid, &update->old_oid))
2733
return 0;
2734
2735
- if (is_null_sha1(update->old_sha1))
2735
+ if (is_null_oid(&update->old_oid))
2736
strbuf_addf(err, "cannot lock ref '%s': "
2737
"reference already exists",
2738
original_update_refname(update));
@@ -2740,13 +2740,13 @@ static int check_old_oid(struct ref_update *update, struct object_id *oid,
2740
strbuf_addf(err, "cannot lock ref '%s': "
2741
"reference is missing but expected %s",
2742
original_update_refname(update),
2743
- sha1_to_hex(update->old_sha1));
2743
+ oid_to_hex(&update->old_oid));
2744
else
2745
strbuf_addf(err, "cannot lock ref '%s': "
2746
"is at %s but expected %s",
2747
original_update_refname(update),
2748
oid_to_hex(oid),
2749
- sha1_to_hex(update->old_sha1));
2749
+ oid_to_hex(&update->old_oid));
2750
2751
return -1;
2752
}
@@ -2773,13 +2773,13 @@ static int lock_ref_for_update(struct files_ref_store *refs,
2773
{
2774
struct strbuf referent = STRBUF_INIT;
2775
int mustexist = (update->flags & REF_HAVE_OLD) &&
2776
- !is_null_sha1(update->old_sha1);
2776
+ !is_null_oid(&update->old_oid);
2777
int ret;
2778
struct ref_lock *lock;
2779
2780
files_assert_main_repository(refs, "lock_ref_for_update");
2781
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))
2783
update->flags |= REF_DELETING;
2784
2785
if (head_ref) {
@@ -2861,12 +2861,12 @@ static int lock_ref_for_update(struct files_ref_store *refs,
2861
!(update->flags & REF_DELETING) &&
2862
!(update->flags & REF_LOG_ONLY)) {
2863
if (!(update->type & REF_ISSYMREF) &&
2864
- !hashcmp(lock->old_oid.hash, update->new_sha1)) {
2864
+ !oidcmp(&lock->old_oid, &update->new_oid)) {
2865
/*
2866
* The reference already has the desired
2867
* value, so we don't need to write it.
2868
*/
2869
- } else if (write_ref_to_lockfile(lock, update->new_sha1,
2869
+ } else if (write_ref_to_lockfile(lock, update->new_oid.hash,
2870
err)) {
2871
char *write_err = strbuf_detach(err, NULL);
2872
@@ -3002,7 +3002,7 @@ static int files_transaction_commit(struct ref_store *ref_store,
3002
if (files_log_ref_write(refs,
3003
lock->ref_name,
3004
lock->old_oid.hash,
3005
- update->new_sha1,
3005
+ update->new_oid.hash,
3006
update->msg, update->flags,
3007
err)) {
3008
char *old_msg = strbuf_detach(err, NULL);
@@ -3151,7 +3151,7 @@ static int files_initial_transaction_commit(struct ref_store *ref_store,
3151
struct ref_update *update = transaction->updates[i];
3152
3153
if ((update->flags & REF_HAVE_OLD) &&
3154
- !is_null_sha1(update->old_sha1))
3154
+ !is_null_oid(&update->old_oid))
3155
die("BUG: initial ref transaction with old_sha1 set");
3156
if (refs_verify_refname_available(&refs->base, update->refname,
3157
&affected_refnames, NULL,
@@ -3172,8 +3172,9 @@ static int files_initial_transaction_commit(struct ref_store *ref_store,
3172
struct ref_update *update = transaction->updates[i];
3173
3174
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);
3178
}
3179
3180
if (commit_packed_refs(refs)) {
refs/refs-internal.h
+2
-2
@@ -130,13 +130,13 @@ struct ref_update {
130
/*
131
* If (flags & REF_HAVE_NEW), set the reference to this value:
132
*/
133
- unsigned char new_sha1[20];
133
+ struct object_id new_oid;
134
135
/*
136
* If (flags & REF_HAVE_OLD), check that the reference
137
* previously had this value:
138
*/
139
- unsigned char old_sha1[20];
139
+ struct object_id old_oid;
140
141
/*
142
* One or more of REF_HAVE_NEW, REF_HAVE_OLD, REF_NODEREF,