refs: add an update_ref_oid function.
authorbrian m. carlson <sandals@crustytoothpaste.net>
Mon, 5 Sep 2016 20:08:08 +0000 (20:08 +0000)
committerJunio C Hamano <gitster@pobox.com>
Wed, 7 Sep 2016 19:59:43 +0000 (12:59 -0700)
Several places around the codebase want to pass update_ref data from
struct object_id, but update_ref may also be passed NULL pointers.
Instead of checking and dereferencing in every caller, create an
update_ref_oid which wraps update_ref and provides this functionality.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
refs.c
refs.h
diff --git a/refs.c b/refs.c
index b4e7cac7b26d0903c4ab7361430c38232c1d5e82..f567a78ee8564922ab6dd1078f183c18acf81297 100644 (file)
--- a/refs.c
+++ b/refs.c
@@ -858,6 +858,14 @@ 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 update_ref(const char *msg, const char *refname,
               const unsigned char *new_sha1, const unsigned char *old_sha1,
               unsigned int flags, enum action_on_err onerr)
diff --git a/refs.h b/refs.h
index 1b020437586d4480377080c95adb446f28d03a46..7a77f3ef3218ee99e712bca64311bf09195211e9 100644 (file)
--- a/refs.h
+++ b/refs.h
@@ -477,6 +477,9 @@ void ref_transaction_free(struct ref_transaction *transaction);
 int update_ref(const char *msg, const char *refname,
               const unsigned char *new_sha1, const unsigned char *old_sha1,
               unsigned int flags, enum action_on_err onerr);
+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);
 
 int parse_hide_refs_config(const char *var, const char *value, const char *);