git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v4 07/12] ref_newer: convert to use struct object_id

From
brian m. carlson <sandals@crustytoothpaste.net>
Date
Nov 10, 2015, 02:22 UTC
Message-ID
<1447122150-672570-8-git-send-email-sandals@crustytoothpaste.net>
In-Reply-To
<1447122150-672570-1-git-send-email-sandals@crustytoothpaste.net>

Convert ref_newer and its caller to use struct object_id instead of unsigned char *.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 builtin/remote.c | 2 +-
 http-push.c      | 4 ++--
 remote.c         | 8 ++++----
 remote.h         | 2 +-
 4 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/builtin/remote.c b/builtin/remote.c
index 68dec162..6694cf20 100644
--- a/builtin/remote.c
+++ b/builtin/remote.c
@@ -417,7 +417,7 @@ static int get_push_ref_states(const struct ref *remote_refs,
 		else if (is_null_oid(&ref->old_oid))
 			info->status = PUSH_STATUS_CREATE;
 		else if (has_object_file(&ref->old_oid) &&
-			 ref_newer(ref->new_oid.hash, ref->old_oid.hash))
+			 ref_newer(&ref->new_oid, &ref->old_oid))
 			info->status = PUSH_STATUS_FASTFORWARD;
 		else
 			info->status = PUSH_STATUS_OUTOFDATE;
diff --git a/http-push.c b/http-push.c
index f2db3a62..68ce3405 100644
--- a/http-push.c
+++ b/http-push.c
@@ -1886,8 +1886,8 @@ int main(int argc, char **argv)
 		    !is_null_oid(&ref->old_oid) &&
 		    !ref->force) {
 			if (!has_object_file(&ref->old_oid) ||
-			    !ref_newer(ref->peer_ref->new_oid.hash,
-				       ref->old_oid.hash)) {
+			    !ref_newer(&ref->peer_ref->new_oid,
+				       &ref->old_oid)) {
 				/*
 				 * We do not have the remote ref, or
 				 * we know that the remote ref is not
diff --git a/remote.c b/remote.c
index 4beebadc..bdae86c6 100644
--- a/remote.c
+++ b/remote.c
@@ -1590,7 +1590,7 @@ void set_ref_status_for_push(struct ref *remote_refs, int send_mirror,
 			else if (!lookup_commit_reference_gently(ref->old_oid.hash, 1) ||
 				 !lookup_commit_reference_gently(ref->new_oid.hash, 1))
 				reject_reason = REF_STATUS_REJECT_NEEDS_FORCE;
-			else if (!ref_newer(ref->new_oid.hash, ref->old_oid.hash))
+			else if (!ref_newer(&ref->new_oid, &ref->old_oid))
 				reject_reason = REF_STATUS_REJECT_NONFASTFORWARD;
 		}
 
@@ -1944,7 +1944,7 @@ static void unmark_and_free(struct commit_list *list, unsigned int mark)
 	}
 }
 
-int ref_newer(const unsigned char *new_sha1, const unsigned char *old_sha1)
+int ref_newer(const struct object_id *new_oid, const struct object_id *old_oid)
 {
 	struct object *o;
 	struct commit *old, *new;
@@ -1955,12 +1955,12 @@ int ref_newer(const unsigned char *new_sha1, const unsigned char *old_sha1)
 	 * Both new and old must be commit-ish and new is descendant of
 	 * old.  Otherwise we require --force.
 	 */
-	o = deref_tag(parse_object(old_sha1), NULL, 0);
+	o = deref_tag(parse_object(old_oid->hash), NULL, 0);
 	if (!o || o->type != OBJ_COMMIT)
 		return 0;
 	old = (struct commit *) o;
 
-	o = deref_tag(parse_object(new_sha1), NULL, 0);
+	o = deref_tag(parse_object(new_oid->hash), NULL, 0);
 	if (!o || o->type != OBJ_COMMIT)
 		return 0;
 	new = (struct commit *) o;
diff --git a/remote.h b/remote.h
index 163ea5e8..4a039bae 100644
--- a/remote.h
+++ b/remote.h
@@ -150,7 +150,7 @@ extern struct ref **get_remote_heads(int in, char *src_buf, size_t src_len,
 				     struct sha1_array *shallow);
 
 int resolve_remote_symref(struct ref *ref, struct ref *list);
-int ref_newer(const unsigned char *new_sha1, const unsigned char *old_sha1);
+int ref_newer(const struct object_id *new_oid, const struct object_id *old_oid);
 
 /*
  * Remove and free all but the first of any entries in the input list
-- 
2.6.2.409.gb049f0a
Previous: brian m. carlsonNext: brian m. carlson
Message 8 of 15 in “object_id part 2”
  1. 00/12 object_id part 2brian m. carlson, Nov 10, 2015
  2. 01/12 sha1_file: introduce has_object_file helper.brian m. carlson, Nov 10, 2015
  3. 02/12 Convert struct ref to use object_id.brian m. carlson, Nov 10, 2015
  4. 03/12 add_sought_entry_mem: convert to struct object_idbrian m. carlson, Nov 10, 2015
  5. 04/12 parse_fetch: convert to use struct object_idbrian m. carlson, Nov 10, 2015
  6. 05/12 get_remote_heads: convert to struct object_idbrian m. carlson, Nov 10, 2015
  7. 06/12 push_refs_with_export: convert to struct object_idbrian m. carlson, Nov 10, 2015
  8. 07/12 ref_newer: convert to use struct object_idbrian m. carlson, Nov 10, 2015
  9. 08/12 object: introduce get_object_hash macro.brian m. carlson, Nov 10, 2015
  10. 09/12 Add several uses of get_object_hash.brian m. carlson, Nov 10, 2015
  11. Jeff KingNov 20, 2015
  12. brian m. carlsonNov 20, 2015
  13. 10/12 Convert struct object to object_idbrian m. carlson, Nov 10, 2015
  14. 11/12 Remove get_object_hash.brian m. carlson, Nov 10, 2015
  15. 12/12 remote: convert functions to struct object_idbrian m. carlson, Nov 10, 2015

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.