diff options
author | brian m. carlson <sandals@crustytoothpaste.net> | 2017-10-15 22:06:51 +0000 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2017-10-16 11:05:50 +0900 |
commit | ae077771b09fac4d663e3f8c039318a97eb3a15b (patch) | |
tree | 53b4ed92e41aad737b49a44fc60871f7df1445dc /refs.c | |
parent | 2616a5e5089814188a583572bd9bf578b18a2a40 (diff) | |
download | git-ae077771b09fac4d663e3f8c039318a97eb3a15b.tar.gz |
refs: convert update_ref and refs_update_ref to use struct object_id
Convert update_ref, refs_update_ref, and write_pseudoref to use struct
object_id. Update the existing callers as well. Remove update_ref_oid,
as it is no longer needed.
Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'refs.c')
-rw-r--r-- | refs.c | 39 |
1 files changed, 16 insertions, 23 deletions
@@ -574,8 +574,8 @@ long get_files_ref_lock_timeout_ms(void) return timeout_ms; } -static int write_pseudoref(const char *pseudoref, const unsigned char *sha1, - const unsigned char *old_sha1, struct strbuf *err) +static int write_pseudoref(const char *pseudoref, const struct object_id *oid, + const struct object_id *old_oid, struct strbuf *err) { const char *filename; int fd; @@ -583,7 +583,7 @@ static int write_pseudoref(const char *pseudoref, const unsigned char *sha1, struct strbuf buf = STRBUF_INIT; int ret = -1; - strbuf_addf(&buf, "%s\n", sha1_to_hex(sha1)); + strbuf_addf(&buf, "%s\n", oid_to_hex(oid)); filename = git_path("%s", pseudoref); fd = hold_lock_file_for_update_timeout(&lock, filename, @@ -595,12 +595,12 @@ static int write_pseudoref(const char *pseudoref, const unsigned char *sha1, goto done; } - if (old_sha1) { - unsigned char actual_old_sha1[20]; + if (old_oid) { + struct object_id actual_old_oid; - if (read_ref(pseudoref, actual_old_sha1)) + if (read_ref(pseudoref, actual_old_oid.hash)) die("could not read ref '%s'", pseudoref); - if (hashcmp(actual_old_sha1, old_sha1)) { + if (oidcmp(&actual_old_oid, old_oid)) { strbuf_addf(err, "unexpected sha1 when writing '%s'", pseudoref); rollback_lock_file(&lock); goto done; @@ -985,17 +985,9 @@ int ref_transaction_verify(struct ref_transaction *transaction, flags, NULL, err); } -int update_ref_oid(const char *msg, const char *refname, - const struct object_id *new_oid, const struct object_id *old_oid, - unsigned int flags, enum action_on_err onerr) -{ - return update_ref(msg, refname, new_oid ? new_oid->hash : NULL, - old_oid ? old_oid->hash : NULL, flags, onerr); -} - int refs_update_ref(struct ref_store *refs, const char *msg, - const char *refname, const unsigned char *new_sha1, - const unsigned char *old_sha1, unsigned int flags, + const char *refname, const struct object_id *new_oid, + const struct object_id *old_oid, unsigned int flags, enum action_on_err onerr) { struct ref_transaction *t = NULL; @@ -1004,11 +996,12 @@ int refs_update_ref(struct ref_store *refs, const char *msg, if (ref_type(refname) == REF_TYPE_PSEUDOREF) { assert(refs == get_main_ref_store()); - ret = write_pseudoref(refname, new_sha1, old_sha1, &err); + ret = write_pseudoref(refname, new_oid, old_oid, &err); } else { t = ref_store_transaction_begin(refs, &err); if (!t || - ref_transaction_update(t, refname, new_sha1, old_sha1, + ref_transaction_update(t, refname, new_oid ? new_oid->hash : NULL, + old_oid ? old_oid->hash : NULL, flags, msg, &err) || ref_transaction_commit(t, &err)) { ret = 1; @@ -1038,12 +1031,12 @@ int refs_update_ref(struct ref_store *refs, const char *msg, } int update_ref(const char *msg, const char *refname, - const unsigned char *new_sha1, - const unsigned char *old_sha1, + const struct object_id *new_oid, + const struct object_id *old_oid, unsigned int flags, enum action_on_err onerr) { - return refs_update_ref(get_main_ref_store(), msg, refname, new_sha1, - old_sha1, flags, onerr); + return refs_update_ref(get_main_ref_store(), msg, refname, new_oid, + old_oid, flags, onerr); } char *shorten_unambiguous_ref(const char *refname, int strict) |