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

[PATCH v2 15/24] refs: convert read_ref_at to struct object_id

From
brian m. carlson <sandals@crustytoothpaste.net>
Date
Oct 9, 2017, 01:11 UTC
Message-ID
<20171009011132.675341-16-sandals@crustytoothpaste.net>
In-Reply-To
<20171009011132.675341-1-sandals@crustytoothpaste.net>

Convert the callers and internals, including struct read_ref_at_cb, of read_ref_at to use struct object_id.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 builtin/show-branch.c |  4 ++--
 refs.c                | 34 +++++++++++++++++-----------------
 refs.h                |  2 +-
 sha1_name.c           |  2 +-
 4 files changed, 21 insertions(+), 21 deletions(-)
diff --git a/builtin/show-branch.c b/builtin/show-branch.c
index 722a7f4bec..8bf42e529d 100644
--- a/builtin/show-branch.c
+++ b/builtin/show-branch.c
@@ -731,7 +731,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
 				/* Ah, that is a date spec... */
 				timestamp_t at;
 				at = approxidate(reflog_base);
-				read_ref_at(ref, flags, at, -1, oid.hash, NULL,
+				read_ref_at(ref, flags, at, -1, &oid, NULL,
 					    NULL, NULL, &base);
 			}
 		}
@@ -743,7 +743,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
 			timestamp_t timestamp;
 			int tz;
 
-			if (read_ref_at(ref, flags, 0, base+i, oid.hash, &logmsg,
+			if (read_ref_at(ref, flags, 0, base + i, &oid, &logmsg,
 					&timestamp, &tz, NULL)) {
 				reflog = i;
 				break;
diff --git a/refs.c b/refs.c
index 0a3754f6da..b781acc8b1 100644
--- a/refs.c
+++ b/refs.c
@@ -734,11 +734,11 @@ struct read_ref_at_cb {
 	timestamp_t at_time;
 	int cnt;
 	int reccnt;
-	unsigned char *sha1;
+	struct object_id *oid;
 	int found_it;
 
-	unsigned char osha1[20];
-	unsigned char nsha1[20];
+	struct object_id ooid;
+	struct object_id noid;
 	int tz;
 	timestamp_t date;
 	char **msg;
@@ -770,25 +770,25 @@ static int read_ref_at_ent(struct object_id *ooid, struct object_id *noid,
 		 * we have not yet updated cb->[n|o]sha1 so they still
 		 * hold the values for the previous record.
 		 */
-		if (!is_null_sha1(cb->osha1)) {
-			hashcpy(cb->sha1, noid->hash);
-			if (hashcmp(cb->osha1, noid->hash))
+		if (!is_null_oid(&cb->ooid)) {
+			oidcpy(cb->oid, noid);
+			if (oidcmp(&cb->ooid, noid))
 				warning("Log for ref %s has gap after %s.",
 					cb->refname, show_date(cb->date, cb->tz, DATE_MODE(RFC2822)));
 		}
 		else if (cb->date == cb->at_time)
-			hashcpy(cb->sha1, noid->hash);
-		else if (hashcmp(noid->hash, cb->sha1))
+			oidcpy(cb->oid, noid);
+		else if (oidcmp(noid, cb->oid))
 			warning("Log for ref %s unexpectedly ended on %s.",
 				cb->refname, show_date(cb->date, cb->tz,
 						       DATE_MODE(RFC2822)));
-		hashcpy(cb->osha1, ooid->hash);
-		hashcpy(cb->nsha1, noid->hash);
+		oidcpy(&cb->ooid, ooid);
+		oidcpy(&cb->noid, noid);
 		cb->found_it = 1;
 		return 1;
 	}
-	hashcpy(cb->osha1, ooid->hash);
-	hashcpy(cb->nsha1, noid->hash);
+	oidcpy(&cb->ooid, ooid);
+	oidcpy(&cb->noid, noid);
 	if (cb->cnt > 0)
 		cb->cnt--;
 	return 0;
@@ -808,15 +808,15 @@ static int read_ref_at_ent_oldest(struct object_id *ooid, struct object_id *noid
 		*cb->cutoff_tz = tz;
 	if (cb->cutoff_cnt)
 		*cb->cutoff_cnt = cb->reccnt;
-	hashcpy(cb->sha1, ooid->hash);
-	if (is_null_sha1(cb->sha1))
-		hashcpy(cb->sha1, noid->hash);
+	oidcpy(cb->oid, ooid);
+	if (is_null_oid(cb->oid))
+		oidcpy(cb->oid, noid);
 	/* We just want the first entry */
 	return 1;
 }
 
 int read_ref_at(const char *refname, unsigned int flags, timestamp_t at_time, int cnt,
-		unsigned char *sha1, char **msg,
+		struct object_id *oid, char **msg,
 		timestamp_t *cutoff_time, int *cutoff_tz, int *cutoff_cnt)
 {
 	struct read_ref_at_cb cb;
@@ -829,7 +829,7 @@ int read_ref_at(const char *refname, unsigned int flags, timestamp_t at_time, in
 	cb.cutoff_time = cutoff_time;
 	cb.cutoff_tz = cutoff_tz;
 	cb.cutoff_cnt = cutoff_cnt;
-	cb.sha1 = sha1;
+	cb.oid = oid;
 
 	for_each_reflog_ent_reverse(refname, read_ref_at_ent, &cb);
 
diff --git a/refs.h b/refs.h
index 832ade2b13..3afecd2e8a 100644
--- a/refs.h
+++ b/refs.h
@@ -363,7 +363,7 @@ int safe_create_reflog(const char *refname, int force_create, struct strbuf *err
 /** Reads log for the value of ref during at_time. **/
 int read_ref_at(const char *refname, unsigned int flags,
 		timestamp_t at_time, int cnt,
-		unsigned char *sha1, char **msg,
+		struct object_id *oid, char **msg,
 		timestamp_t *cutoff_time, int *cutoff_tz, int *cutoff_cnt);
 
 /** Check if a particular reflog exists */
diff --git a/sha1_name.c b/sha1_name.c
index 7de12743f3..9b806104a4 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -697,7 +697,7 @@ static int get_oid_basic(const char *str, int len, struct object_id *oid,
 				return -1;
 			}
 		}
-		if (read_ref_at(real_ref, flags, at_time, nth, oid->hash, NULL,
+		if (read_ref_at(real_ref, flags, at_time, nth, oid, NULL,
 				&co_time, &co_tz, &co_cnt)) {
 			if (!len) {
 				if (starts_with(real_ref, "refs/heads/")) {
-- 
2.14.2.920.gcf0c67979c
Previous: brian m. carlsonNext: brian m. carlson
Message 28 of 53 in “object_id part 10”
  1. 00/24 object_id part 10brian m. carlson, Oct 9, 2017
  2. 01/24 walker: convert to struct object_idbrian m. carlson, Oct 9, 2017
  3. Jonathan NiederOct 9, 2017
  4. 03/24 refs: convert delete_ref and refs_delete_ref to struct object_idbrian m. carlson, Oct 9, 2017
  5. Jonathan NiederOct 9, 2017
  6. 02/24 refs/files-backend: convert struct ref_to_prune to object_idbrian m. carlson, Oct 9, 2017
  7. Jonathan NiederOct 9, 2017
  8. 04/24 refs: convert update_ref and refs_update_ref to use struct object_idbrian m. carlson, Oct 9, 2017
  9. Jonathan NiederOct 9, 2017
  10. Michael HaggertyOct 11, 2017
  11. brian m. carlsonOct 12, 2017
  12. 10/24 builtin/reflog: convert remaining unsigned char uses to object_idbrian m. carlson, Oct 9, 2017
  13. Jonathan NiederOct 10, 2017
  14. 09/24 refs: convert dwim_ref and expand_ref to struct object_idbrian m. carlson, Oct 9, 2017
  15. Jonathan NiederOct 10, 2017
  16. 12/24 pack-bitmap: convert traverse_bitmap_commit_list to object_idbrian m. carlson, Oct 9, 2017
  17. Jonathan NiederOct 10, 2017
  18. 18/24 Convert remaining callers of resolve_gitlink_ref to object_idbrian m. carlson, Oct 9, 2017
  19. 21/24 refs: convert resolve_ref_unsafe to struct object_idbrian m. carlson, Oct 9, 2017
  20. Michael HaggertyOct 11, 2017
  21. 24/24 refs/files-backend: convert static functions to object_idbrian m. carlson, Oct 9, 2017
  22. Michael HaggertyOct 11, 2017
  23. 22/24 refs: convert peel_object to struct object_idbrian m. carlson, Oct 9, 2017
  24. 23/24 refs: convert read_raw_ref backends to struct object_idbrian m. carlson, Oct 9, 2017
  25. Michael HaggertyOct 11, 2017
  26. 19/24 refs: convert resolve_gitlink_ref to struct object_idbrian m. carlson, Oct 9, 2017
  27. 20/24 worktree: convert struct worktree to object_idbrian m. carlson, Oct 9, 2017
  28. 15/24 refs: convert read_ref_at to struct object_idbrian m. carlson, Oct 9, 2017
  29. 14/24 refs: convert peel_ref to struct object_idbrian m. carlson, Oct 9, 2017
  30. Michael HaggertyOct 11, 2017
  31. 17/24 sha1_file: convert index_path and index_fd to struct object_idbrian m. carlson, Oct 9, 2017
  32. 13/24 builtin/pack-objects: convert to struct object_idbrian m. carlson, Oct 9, 2017
  33. Jonathan NiederOct 10, 2017
  34. 16/24 refs: convert reflog_expire parameter to struct object_idbrian m. carlson, Oct 9, 2017
  35. 08/24 refs: convert read_ref and read_ref_full to object_idbrian m. carlson, Oct 9, 2017
  36. Jonathan NiederOct 10, 2017
  37. 11/24 refs: convert dwim_log to struct object_idbrian m. carlson, Oct 9, 2017
  38. Jonathan NiederOct 10, 2017
  39. 07/24 refs: convert resolve_refdup and refs_resolve_refdup to struct object_idbrian m. carlson, Oct 9, 2017
  40. Jonathan NiederOct 9, 2017
  41. Junio C HamanoOct 10, 2017
  42. 05/24 refs: update ref transactions to use struct object_idbrian m. carlson, Oct 9, 2017
  43. Jonathan NiederOct 9, 2017
  44. Michael HaggertyOct 11, 2017
  45. 06/24 Convert check_connected to use struct object_idbrian m. carlson, Oct 9, 2017
  46. Jonathan NiederOct 9, 2017
  47. Stefan BellerOct 9, 2017
  48. Junio C HamanoOct 9, 2017
  49. Michael HaggertyOct 11, 2017
  50. Junio C HamanoOct 11, 2017
  51. brian m. carlsonOct 12, 2017
  52. Junio C HamanoOct 12, 2017
  53. brian m. carlsonOct 12, 2017

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.