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

[PATCH 16/16] refs: convert struct ref_lock to struct object_id

From
brian m. carlson <sandals@crustytoothpaste.net>
Date
Mar 20, 2015, 19:28 UTC
Message-ID
<1426879716-47835-17-git-send-email-sandals@crustytoothpaste.net>
In-Reply-To
<1426879716-47835-1-git-send-email-sandals@crustytoothpaste.net>
Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 refs.c | 22 +++++++++++-----------
 refs.h |  2 +-
 2 files changed, 12 insertions(+), 12 deletions(-)
diff --git a/refs.c b/refs.c
index 941e466..b54525a 100644
--- a/refs.c
+++ b/refs.c
@@ -2099,16 +2099,16 @@ static struct ref_lock *verify_lock(struct ref_lock *lock,
 {
 	if (read_ref_full(lock->ref_name,
 			  mustexist ? RESOLVE_REF_READING : 0,
-			  lock->old_sha1, NULL)) {
+			  lock->old_oid.hash, NULL)) {
 		int save_errno = errno;
 		error("Can't verify ref %s", lock->ref_name);
 		unlock_ref(lock);
 		errno = save_errno;
 		return NULL;
 	}
-	if (hashcmp(lock->old_sha1, old_sha1)) {
+	if (hashcmp(lock->old_oid.hash, old_sha1)) {
 		error("Ref %s is at %s but expected %s", lock->ref_name,
-			sha1_to_hex(lock->old_sha1), sha1_to_hex(old_sha1));
+			oid_to_hex(&lock->old_oid), sha1_to_hex(old_sha1));
 		unlock_ref(lock);
 		errno = EBUSY;
 		return NULL;
@@ -2254,7 +2254,7 @@ static struct ref_lock *lock_ref_sha1_basic(const char *refname,
 	}
 
 	refname = resolve_ref_unsafe(refname, resolve_flags,
-				     lock->old_sha1, &type);
+				     lock->old_oid.hash, &type);
 	if (!refname && errno == EISDIR) {
 		/* we are trying to lock foo but we used to
 		 * have foo/bar which now does not exist;
@@ -2268,7 +2268,7 @@ static struct ref_lock *lock_ref_sha1_basic(const char *refname,
 			goto error_return;
 		}
 		refname = resolve_ref_unsafe(orig_refname, resolve_flags,
-					     lock->old_sha1, &type);
+					     lock->old_oid.hash, &type);
 	}
 	if (type_p)
 	    *type_p = type;
@@ -2278,7 +2278,7 @@ static struct ref_lock *lock_ref_sha1_basic(const char *refname,
 			orig_refname, strerror(errno));
 		goto error_return;
 	}
-	missing = is_null_sha1(lock->old_sha1);
+	missing = is_null_oid(&lock->old_oid);
 	/* When the ref did not exist and we are creating it,
 	 * make sure there is no existing ref that is packed
 	 * whose name begins with our refname, nor a ref whose
@@ -2866,7 +2866,7 @@ int rename_ref(const char *oldrefname, const char *newrefname, const char *logms
 		goto rollback;
 	}
 	lock->force_write = 1;
-	hashcpy(lock->old_sha1, orig_sha1);
+	hashcpy(lock->old_oid.hash, orig_sha1);
 	if (write_ref_sha1(lock, orig_sha1, logmsg)) {
 		error("unable to write current sha1 into %s", newrefname);
 		goto rollback;
@@ -3069,7 +3069,7 @@ static int write_ref_sha1(struct ref_lock *lock,
 		errno = EINVAL;
 		return -1;
 	}
-	if (!lock->force_write && !hashcmp(lock->old_sha1, sha1)) {
+	if (!lock->force_write && !hashcmp(lock->old_oid.hash, sha1)) {
 		unlock_ref(lock);
 		return 0;
 	}
@@ -3098,9 +3098,9 @@ static int write_ref_sha1(struct ref_lock *lock,
 		return -1;
 	}
 	clear_loose_ref_cache(&ref_cache);
-	if (log_ref_write(lock->ref_name, lock->old_sha1, sha1, logmsg) < 0 ||
+	if (log_ref_write(lock->ref_name, lock->old_oid.hash, sha1, logmsg) < 0 ||
 	    (strcmp(lock->ref_name, lock->orig_ref_name) &&
-	     log_ref_write(lock->orig_ref_name, lock->old_sha1, sha1, logmsg) < 0)) {
+	     log_ref_write(lock->orig_ref_name, lock->old_oid.hash, sha1, logmsg) < 0)) {
 		unlock_ref(lock);
 		return -1;
 	}
@@ -3124,7 +3124,7 @@ static int write_ref_sha1(struct ref_lock *lock,
 					      head_sha1, &head_flag);
 		if (head_ref && (head_flag & REF_ISSYMREF) &&
 		    !strcmp(head_ref, lock->ref_name))
-			log_ref_write("HEAD", lock->old_sha1, sha1, logmsg);
+			log_ref_write("HEAD", lock->old_oid.hash, sha1, logmsg);
 	}
 	if (commit_ref(lock)) {
 		error("Couldn't set %s", lock->ref_name);
diff --git a/refs.h b/refs.h
index b893f4a..538391c 100644
--- a/refs.h
+++ b/refs.h
@@ -7,7 +7,7 @@ struct ref_lock {
 	char *ref_name;
 	char *orig_ref_name;
 	struct lock_file *lk;
-	unsigned char old_sha1[20];
+	struct object_id old_oid;
 	int lock_fd;
 	int force_write;
 };
-- 
2.2.1.209.g41e5f3a
Previous: brian m. carlsonNext: Junio C Hamano
Message 17 of 19 in “Convert parts of refs.c to struct object_id”
  1. 00/16 Convert parts of refs.c to struct object_idbrian m. carlson, Mar 20, 2015
  2. 01/16 refs: convert struct ref_entry to use struct object_idbrian m. carlson, Mar 20, 2015
  3. 02/16 refs: convert for_each_tag_ref to struct object_idbrian m. carlson, Mar 20, 2015
  4. 03/16 refs: convert remaining users of for_each_ref_in to object_idbrian m. carlson, Mar 20, 2015
  5. 04/16 refs: convert for_each_ref_in_submodule to object_idbrian m. carlson, Mar 20, 2015
  6. 05/16 refs: convert head_ref to struct object_idbrian m. carlson, Mar 20, 2015
  7. 06/16 refs: convert for_each_ref_submodule to struct object_idbrian m. carlson, Mar 20, 2015
  8. 07/16 revision: remove unused _oid helper.brian m. carlson, Mar 20, 2015
  9. 08/16 refs: convert for_each_ref to struct object_idbrian m. carlson, Mar 20, 2015
  10. 09/16 refs: convert for_each_replace_ref to struct object_idbrian m. carlson, Mar 20, 2015
  11. 10/16 refs: convert namespaced ref iteration functions to object_idbrian m. carlson, Mar 20, 2015
  12. 11/16 refs: convert for_each_rawref to struct object_id.brian m. carlson, Mar 20, 2015
  13. 12/16 refs: rename do_for_each_ref_oid to do_for_each_refbrian m. carlson, Mar 20, 2015
  14. 13/16 refs: convert for_each_reflog to struct object_idbrian m. carlson, Mar 20, 2015
  15. 14/16 refs: rename each_ref_fn_oid to each_ref_fnbrian m. carlson, Mar 20, 2015
  16. 15/16 Remove unneeded *_oid functions.brian m. carlson, Mar 20, 2015
  17. 16/16 refs: convert struct ref_lock to struct object_idbrian m. carlson, Mar 20, 2015
  18. Junio C HamanoMar 20, 2015
  19. brian m. carlsonMar 20, 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.