refs: convert delete_ref and refs_delete_ref to struct object_id
Convert delete_ref and refs_delete_ref to take a pointer to struct object_id. Update the documentation accordingly, including referring to null_oid in lowercase, as it is not a #define constant. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
brian m. carlson committed
Oct 15, 2017 at 22:06 UTC
2616a5e5089814188a583572bd9bf578b18a2a40
9 files changed
+26
-25
builtin/branch.c
+1
-1
@@ -257,7 +257,7 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,
257
goto next;
258
}
259
260
- if (delete_ref(NULL, name, is_null_oid(&oid) ? NULL : oid.hash,
260
+ if (delete_ref(NULL, name, is_null_oid(&oid) ? NULL : &oid,
261
REF_NODEREF)) {
262
error(remote_branch
263
? _("Error deleting remote-tracking branch '%s'")
builtin/replace.c
+1
-1
@@ -128,7 +128,7 @@ static int for_each_replace_name(const char **argv, each_replace_name_fn fn)
128
static int delete_replace_ref(const char *name, const char *ref,
129
const struct object_id *oid)
130
{
131
- if (delete_ref(NULL, ref, oid->hash, 0))
131
+ if (delete_ref(NULL, ref, oid, 0))
132
return 1;
133
printf("Deleted replace ref '%s'\n", name);
134
return 0;
builtin/reset.c
+1
-1
@@ -269,7 +269,7 @@ static int reset_refs(const char *rev, const struct object_id *oid)
269
update_ref_oid(msg.buf, "ORIG_HEAD", orig, old_orig, 0,
270
UPDATE_REFS_MSG_ON_ERR);
271
} else if (old_orig)
272
- delete_ref(NULL, "ORIG_HEAD", old_orig->hash, 0);
272
+ delete_ref(NULL, "ORIG_HEAD", old_orig, 0);
273
set_reflog_message(&msg, "updating HEAD", rev);
274
update_ref_status = update_ref_oid(msg.buf, "HEAD", oid, orig, 0,
275
UPDATE_REFS_MSG_ON_ERR);
builtin/tag.c
+1
-1
@@ -97,7 +97,7 @@ static int for_each_tag_name(const char **argv, each_tag_name_fn fn,
97
static int delete_tag(const char *name, const char *ref,
98
const struct object_id *oid, const void *cb_data)
99
{
100
- if (delete_ref(NULL, ref, oid->hash, 0))
100
+ if (delete_ref(NULL, ref, oid, 0))
101
return 1;
102
printf(_("Deleted tag '%s' (was %s)\n"), name, find_unique_abbrev(oid->hash, DEFAULT_ABBREV));
103
return 0;
builtin/update-ref.c
+1
-1
@@ -434,7 +434,7 @@ int cmd_update_ref(int argc, const char **argv, const char *prefix)
434
* NULL_SHA1 as "don't care" here:
435
*/
436
return delete_ref(msg, refname,
437
- (oldval && !is_null_oid(&oldoid)) ? oldoid.hash : NULL,
437
+ (oldval && !is_null_oid(&oldoid)) ? &oldoid : NULL,
438
flags);
439
else
440
return update_ref(msg, refname, oid.hash, oldval ? oldoid.hash : NULL,
refs.c
+11
-10
@@ -620,25 +620,25 @@ done:
620
return ret;
621
}
622
623
-static int delete_pseudoref(const char *pseudoref, const unsigned char *old_sha1)
623
+static int delete_pseudoref(const char *pseudoref, const struct object_id *old_oid)
624
{
625
static struct lock_file lock;
626
const char *filename;
627
628
filename = git_path("%s", pseudoref);
629
630
- if (old_sha1 && !is_null_sha1(old_sha1)) {
630
+ if (old_oid && !is_null_oid(old_oid)) {
631
int fd;
632
- unsigned char actual_old_sha1[20];
632
+ struct object_id actual_old_oid;
633
634
fd = hold_lock_file_for_update_timeout(
635
&lock, filename, LOCK_DIE_ON_ERROR,
636
get_files_ref_lock_timeout_ms());
637
if (fd < 0)
638
die_errno(_("Could not open '%s' for writing"), filename);
639
- if (read_ref(pseudoref, actual_old_sha1))
639
+ if (read_ref(pseudoref, actual_old_oid.hash))
640
die("could not read ref '%s'", pseudoref);
641
- if (hashcmp(actual_old_sha1, old_sha1)) {
641
+ if (oidcmp(&actual_old_oid, old_oid)) {
642
warning("Unexpected sha1 when deleting %s", pseudoref);
643
rollback_lock_file(&lock);
644
return -1;
@@ -655,7 +655,7 @@ static int delete_pseudoref(const char *pseudoref, const unsigned char *old_sha1
655
656
int refs_delete_ref(struct ref_store *refs, const char *msg,
657
const char *refname,
658
- const unsigned char *old_sha1,
658
+ const struct object_id *old_oid,
659
unsigned int flags)
660
{
661
struct ref_transaction *transaction;
@@ -663,12 +663,13 @@ int refs_delete_ref(struct ref_store *refs, const char *msg,
663
664
if (ref_type(refname) == REF_TYPE_PSEUDOREF) {
665
assert(refs == get_main_ref_store());
666
- return delete_pseudoref(refname, old_sha1);
666
+ return delete_pseudoref(refname, old_oid);
667
}
668
669
transaction = ref_store_transaction_begin(refs, &err);
670
if (!transaction ||
671
- ref_transaction_delete(transaction, refname, old_sha1,
671
+ ref_transaction_delete(transaction, refname,
672
+ old_oid ? old_oid->hash : NULL,
673
flags, msg, &err) ||
674
ref_transaction_commit(transaction, &err)) {
675
error("%s", err.buf);
@@ -682,10 +683,10 @@ int refs_delete_ref(struct ref_store *refs, const char *msg,
683
}
684
685
int delete_ref(const char *msg, const char *refname,
685
- const unsigned char *old_sha1, unsigned int flags)
686
+ const struct object_id *old_oid, unsigned int flags)
687
{
688
return refs_delete_ref(get_main_ref_store(), msg, refname,
688
- old_sha1, flags);
689
+ old_oid, flags);
690
}
691
692
int copy_reflog_msg(char *buf, const char *msg)
refs.h
+6
-6
@@ -371,19 +371,19 @@ int refs_reflog_exists(struct ref_store *refs, const char *refname);
371
int reflog_exists(const char *refname);
372
373
/*
374
- * Delete the specified reference. If old_sha1 is non-NULL, then
374
+ * Delete the specified reference. If old_oid is non-NULL, then
375
* verify that the current value of the reference is old_sha1 before
376
- * deleting it. If old_sha1 is NULL, delete the reference if it
377
- * exists, regardless of its old value. It is an error for old_sha1 to
378
- * be NULL_SHA1. msg and flags are passed through to
376
+ * deleting it. If old_oid is NULL, delete the reference if it
377
+ * exists, regardless of its old value. It is an error for old_oid to
378
+ * be null_oid. msg and flags are passed through to
379
* ref_transaction_delete().
380
*/
381
int refs_delete_ref(struct ref_store *refs, const char *msg,
382
const char *refname,
383
- const unsigned char *old_sha1,
383
+ const struct object_id *old_oid,
384
unsigned int flags);
385
int delete_ref(const char *msg, const char *refname,
386
- const unsigned char *old_sha1, unsigned int flags);
386
+ const struct object_id *old_oid, unsigned int flags);
387
388
/*
389
* Delete the specified references. If there are any problems, emit
refs/files-backend.c
+1
-1
@@ -1283,7 +1283,7 @@ static int files_copy_or_rename_ref(struct ref_store *ref_store,
1283
}
1284
1285
if (!copy && refs_delete_ref(&refs->base, logmsg, oldrefname,
1286
- orig_oid.hash, REF_NODEREF)) {
1286
+ &orig_oid, REF_NODEREF)) {
1287
error("unable to delete old %s", oldrefname);
1288
goto rollback;
1289
}
t/helper/test-ref-store.c
+3
-3
@@ -218,12 +218,12 @@ static int cmd_delete_ref(struct ref_store *refs, const char **argv)
218
const char *refname = notnull(*argv++, "refname");
219
const char *sha1_buf = notnull(*argv++, "old-sha1");
220
unsigned int flags = arg_flags(*argv++, "flags");
221
- unsigned char old_sha1[20];
221
+ struct object_id old_oid;
222
223
- if (get_sha1_hex(sha1_buf, old_sha1))
223
+ if (get_oid_hex(sha1_buf, &old_oid))
224
die("not sha-1");
225
226
- return refs_delete_ref(refs, msg, refname, old_sha1, flags);
226
+ return refs_delete_ref(refs, msg, refname, &old_oid, flags);
227
}
228
229
static int cmd_update_ref(struct ref_store *refs, const char **argv)