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

[PATCH 04/20] builtin/diff: convert to struct object_id

From
brian m. carlson <sandals@crustytoothpaste.net>
Date
Mar 18, 2017, 21:19 UTC
Message-ID
<20170318211954.564030-5-sandals@crustytoothpaste.net>
In-Reply-To
<20170318211954.564030-1-sandals@crustytoothpaste.net>
Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 builtin/diff.c | 34 +++++++++++++++++-----------------
 1 file changed, 17 insertions(+), 17 deletions(-)
diff --git a/builtin/diff.c b/builtin/diff.c
index 3d64b85337..398eee00d5 100644
--- a/builtin/diff.c
+++ b/builtin/diff.c
@@ -21,7 +21,7 @@
 #define DIFF_NO_INDEX_IMPLICIT 2
 
 struct blobinfo {
-	unsigned char sha1[20];
+	struct object_id oid;
 	const char *name;
 	unsigned mode;
 };
@@ -31,22 +31,22 @@ static const char builtin_diff_usage[] =
 
 static void stuff_change(struct diff_options *opt,
 			 unsigned old_mode, unsigned new_mode,
-			 const unsigned char *old_sha1,
-			 const unsigned char *new_sha1,
-			 int old_sha1_valid,
-			 int new_sha1_valid,
+			 const struct object_id *old_oid,
+			 const struct object_id *new_oid,
+			 int old_oid_valid,
+			 int new_oid_valid,
 			 const char *old_name,
 			 const char *new_name)
 {
 	struct diff_filespec *one, *two;
 
-	if (!is_null_sha1(old_sha1) && !is_null_sha1(new_sha1) &&
-	    !hashcmp(old_sha1, new_sha1) && (old_mode == new_mode))
+	if (!is_null_oid(old_oid) && !is_null_oid(new_oid) &&
+	    !oidcmp(old_oid, new_oid) && (old_mode == new_mode))
 		return;
 
 	if (DIFF_OPT_TST(opt, REVERSE_DIFF)) {
 		SWAP(old_mode, new_mode);
-		SWAP(old_sha1, new_sha1);
+		SWAP(old_oid, new_oid);
 		SWAP(old_name, new_name);
 	}
 
@@ -57,8 +57,8 @@ static void stuff_change(struct diff_options *opt,
 
 	one = alloc_filespec(old_name);
 	two = alloc_filespec(new_name);
-	fill_filespec(one, old_sha1, old_sha1_valid, old_mode);
-	fill_filespec(two, new_sha1, new_sha1_valid, new_mode);
+	fill_filespec(one, old_oid->hash, old_oid_valid, old_mode);
+	fill_filespec(two, new_oid->hash, new_oid_valid, new_mode);
 
 	diff_queue(&diff_queued_diff, one, two);
 }
@@ -89,7 +89,7 @@ static int builtin_diff_b_f(struct rev_info *revs,
 
 	stuff_change(&revs->diffopt,
 		     blob[0].mode, canon_mode(st.st_mode),
-		     blob[0].sha1, null_sha1,
+		     &blob[0].oid, &null_oid,
 		     1, 0,
 		     path, path);
 	diffcore_std(&revs->diffopt);
@@ -114,7 +114,7 @@ static int builtin_diff_blobs(struct rev_info *revs,
 
 	stuff_change(&revs->diffopt,
 		     blob[0].mode, blob[1].mode,
-		     blob[0].sha1, blob[1].sha1,
+		     &blob[0].oid, &blob[1].oid,
 		     1, 1,
 		     blob[0].name, blob[1].name);
 	diffcore_std(&revs->diffopt);
@@ -160,7 +160,7 @@ static int builtin_diff_tree(struct rev_info *revs,
 			     struct object_array_entry *ent0,
 			     struct object_array_entry *ent1)
 {
-	const unsigned char *(sha1[2]);
+	const struct object_id *(oid[2]);
 	int swap = 0;
 
 	if (argc > 1)
@@ -172,9 +172,9 @@ static int builtin_diff_tree(struct rev_info *revs,
 	 */
 	if (ent1->item->flags & UNINTERESTING)
 		swap = 1;
-	sha1[swap] = ent0->item->oid.hash;
-	sha1[1 - swap] = ent1->item->oid.hash;
-	diff_tree_sha1(sha1[0], sha1[1], "", &revs->diffopt);
+	oid[swap] = &ent0->item->oid;
+	oid[1 - swap] = &ent1->item->oid;
+	diff_tree_sha1(oid[0]->hash, oid[1]->hash, "", &revs->diffopt);
 	log_tree_diff_flush(revs);
 	return 0;
 }
@@ -408,7 +408,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
 		} else if (obj->type == OBJ_BLOB) {
 			if (2 <= blobs)
 				die(_("more than two blobs given: '%s'"), name);
-			hashcpy(blob[blobs].sha1, obj->oid.hash);
+			hashcpy(blob[blobs].oid.hash, obj->oid.hash);
 			blob[blobs].name = name;
 			blob[blobs].mode = entry->mode;
 			blobs++;
Previous: brian m. carlsonNext: brian m. carlson
Message 13 of 31 in “object_id part 7”
  1. 00/20 object_id part 7brian m. carlson, Mar 18, 2017
  2. 14/20 sha1-array: convert internal storage for struct sha1_array to object_idbrian m. carlson, Mar 18, 2017
  3. 13/20 builtin/pull: convert to struct object_idbrian m. carlson, Mar 18, 2017
  4. 17/20 Convert sha1_array_lookup to take struct object_idbrian m. carlson, Mar 18, 2017
  5. 20/20 Documentation: update and rename api-sha1-array.txtbrian m. carlson, Mar 18, 2017
  6. 16/20 Convert remaining callers of sha1_array_lookup to object_idbrian m. carlson, Mar 18, 2017
  7. 18/20 Convert sha1_array_for_each_unique and for_each_abbrev to object_idbrian m. carlson, Mar 18, 2017
  8. 19/20 Rename sha1_array to oid_arraybrian m. carlson, Mar 18, 2017
  9. Duy NguyenMar 20, 2017
  10. brian m. carlsonMar 21, 2017
  11. 15/20 Make sha1_array_append take a struct object_id *brian m. carlson, Mar 18, 2017
  12. 07/20 fsck: convert init_skiplist to struct object_idbrian m. carlson, Mar 18, 2017
  13. 04/20 builtin/diff: convert to struct object_idbrian m. carlson, Mar 18, 2017
  14. 08/20 parse-options-cb: convert sha1_array_append caller to struct object_idbrian m. carlson, Mar 18, 2017
  15. 02/20 Convert GIT_SHA1_HEXSZ used for allocation to GIT_MAX_HEXSZbrian m. carlson, Mar 18, 2017
  16. 03/20 Convert GIT_SHA1_RAWSZ used for allocation to GIT_MAX_RAWSZbrian m. carlson, Mar 18, 2017
  17. 10/20 sha1_name: convert struct disambiguate_state to object_idbrian m. carlson, Mar 18, 2017
  18. Duy NguyenMar 20, 2017
  19. brian m. carlsonMar 20, 2017
  20. Duy NguyenMar 21, 2017
  21. 06/20 builtin/receive-pack: convert portions to struct object_idbrian m. carlson, Mar 18, 2017
  22. Duy NguyenMar 20, 2017
  23. brian m. carlsonMar 20, 2017
  24. Duy NguyenMar 21, 2017
  25. 05/20 builtin/pull: convert portions to struct object_idbrian m. carlson, Mar 18, 2017
  26. 11/20 sha1_name: convert disambiguate_hint_fn to take object_idbrian m. carlson, Mar 18, 2017
  27. 12/20 submodule: convert check_for_new_submodule_commits to object_idbrian m. carlson, Mar 18, 2017
  28. 09/20 test-sha1-array: convert most code to struct object_idbrian m. carlson, Mar 18, 2017
  29. 01/20 Define new hash-size constants for allocating memorybrian m. carlson, Mar 18, 2017
  30. Duy NguyenMar 20, 2017
  31. brian m. carlsonMar 21, 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.