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

[PATCH v2 24/24] refs/files-backend: convert static functions to object_id

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

Convert several static functions to take pointers to struct object_id. Change the relevant parameters to write_packed_entry to be const, as we don't modify them. Rename lock_ref_sha1_basic to lock_ref_oid_basic to reflect its new argument.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 refs/files-backend.c | 48 ++++++++++++++++++++++++------------------------
 1 file changed, 24 insertions(+), 24 deletions(-)
diff --git a/refs/files-backend.c b/refs/files-backend.c
index 7281f27f62..84d8e3da99 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -811,7 +811,7 @@ static struct ref_iterator *files_ref_iterator_begin(
  * return a negative value.
  */
 static int verify_lock(struct ref_store *ref_store, struct ref_lock *lock,
-		       const unsigned char *old_sha1, int mustexist,
+		       const struct object_id *old_oid, int mustexist,
 		       struct strbuf *err)
 {
 	assert(err);
@@ -819,7 +819,7 @@ static int verify_lock(struct ref_store *ref_store, struct ref_lock *lock,
 	if (refs_read_ref_full(ref_store, lock->ref_name,
 			       mustexist ? RESOLVE_REF_READING : 0,
 			       &lock->old_oid, NULL)) {
-		if (old_sha1) {
+		if (old_oid) {
 			int save_errno = errno;
 			strbuf_addf(err, "can't verify ref '%s'", lock->ref_name);
 			errno = save_errno;
@@ -829,11 +829,11 @@ static int verify_lock(struct ref_store *ref_store, struct ref_lock *lock,
 			return 0;
 		}
 	}
-	if (old_sha1 && hashcmp(lock->old_oid.hash, old_sha1)) {
+	if (old_oid && oidcmp(&lock->old_oid, old_oid)) {
 		strbuf_addf(err, "ref '%s' is at %s but expected %s",
 			    lock->ref_name,
 			    oid_to_hex(&lock->old_oid),
-			    sha1_to_hex(old_sha1));
+			    oid_to_hex(old_oid));
 		errno = EBUSY;
 		return -1;
 	}
@@ -863,22 +863,22 @@ static int create_reflock(const char *path, void *cb)
  * Locks a ref returning the lock on success and NULL on failure.
  * On failure errno is set to something meaningful.
  */
-static struct ref_lock *lock_ref_sha1_basic(struct files_ref_store *refs,
-					    const char *refname,
-					    const unsigned char *old_sha1,
-					    const struct string_list *extras,
-					    const struct string_list *skip,
-					    unsigned int flags, int *type,
-					    struct strbuf *err)
+static struct ref_lock *lock_ref_oid_basic(struct files_ref_store *refs,
+					   const char *refname,
+					   const struct object_id *old_oid,
+					   const struct string_list *extras,
+					   const struct string_list *skip,
+					   unsigned int flags, int *type,
+					   struct strbuf *err)
 {
 	struct strbuf ref_file = STRBUF_INIT;
 	struct ref_lock *lock;
 	int last_errno = 0;
-	int mustexist = (old_sha1 && !is_null_sha1(old_sha1));
+	int mustexist = (old_oid && !is_null_oid(old_oid));
 	int resolve_flags = RESOLVE_REF_NO_RECURSE;
 	int resolved;
 
-	files_assert_main_repository(refs, "lock_ref_sha1_basic");
+	files_assert_main_repository(refs, "lock_ref_oid_basic");
 	assert(err);
 
 	lock = xcalloc(1, sizeof(struct ref_lock));
@@ -944,7 +944,7 @@ static struct ref_lock *lock_ref_sha1_basic(struct files_ref_store *refs,
 		goto error_return;
 	}
 
-	if (verify_lock(&refs->base, lock, old_sha1, mustexist, err)) {
+	if (verify_lock(&refs->base, lock, old_oid, mustexist, err)) {
 		last_errno = errno;
 		goto error_return;
 	}
@@ -1349,8 +1349,8 @@ static int files_rename_ref(struct ref_store *ref_store,
 
 	logmoved = log;
 
-	lock = lock_ref_sha1_basic(refs, newrefname, NULL, NULL, NULL,
-				   REF_NODEREF, NULL, &err);
+	lock = lock_ref_oid_basic(refs, newrefname, NULL, NULL, NULL,
+				  REF_NODEREF, NULL, &err);
 	if (!lock) {
 		error("unable to rename '%s' to '%s': %s", oldrefname, newrefname, err.buf);
 		strbuf_release(&err);
@@ -1369,8 +1369,8 @@ static int files_rename_ref(struct ref_store *ref_store,
 	goto out;
 
  rollback:
-	lock = lock_ref_sha1_basic(refs, oldrefname, NULL, NULL, NULL,
-				   REF_NODEREF, NULL, &err);
+	lock = lock_ref_oid_basic(refs, oldrefname, NULL, NULL, NULL,
+				  REF_NODEREF, NULL, &err);
 	if (!lock) {
 		error("unable to lock %s for rollback: %s", oldrefname, err.buf);
 		strbuf_release(&err);
@@ -1769,9 +1769,9 @@ static int files_create_symref(struct ref_store *ref_store,
 	struct ref_lock *lock;
 	int ret;
 
-	lock = lock_ref_sha1_basic(refs, refname, NULL,
-				   NULL, NULL, REF_NODEREF, NULL,
-				   &err);
+	lock = lock_ref_oid_basic(refs, refname, NULL,
+				  NULL, NULL, REF_NODEREF, NULL,
+				  &err);
 	if (!lock) {
 		error("%s", err.buf);
 		strbuf_release(&err);
@@ -2943,9 +2943,9 @@ static int files_reflog_expire(struct ref_store *ref_store,
 	 * reference itself, plus we might need to update the
 	 * reference if --updateref was specified:
 	 */
-	lock = lock_ref_sha1_basic(refs, refname, oid->hash,
-				   NULL, NULL, REF_NODEREF,
-				   &type, &err);
+	lock = lock_ref_oid_basic(refs, refname, oid,
+				  NULL, NULL, REF_NODEREF,
+				  &type, &err);
 	if (!lock) {
 		error("cannot lock ref '%s': %s", refname, err.buf);
 		strbuf_release(&err);
-- 
2.14.2.920.gcf0c67979c
Previous: Michael HaggertyNext: Michael Haggerty
Message 21 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.