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

[PATCH v3 03/11] Convert hashcpy with null_sha1 to hashclr.

From
brian m. carlson <sandals@crustytoothpaste.net>
Date
Jun 24, 2016, 23:09 UTC
Message-ID
<20160624230929.82222-4-sandals@crustytoothpaste.net>
In-Reply-To
<20160624230929.82222-1-sandals@crustytoothpaste.net>

hashcpy with null_sha1 as the source is equivalent to hashclr. In addition to being simpler, using hashclr may give the compiler a chance to optimize better. Convert instances of hashcpy with the source argument of null_sha1 to hashclr.

This transformation was implemented using the following semantic patch:

@@ expression E1; @@ -hashcpy(E1, null_sha1); +hashclr(E1);

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 builtin/merge.c                  | 2 +-
 builtin/unpack-objects.c         | 4 ++--
 diff.c                           | 2 +-
 submodule-config.c               | 2 +-
 t/helper/test-submodule-config.c | 2 +-
 5 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/builtin/merge.c b/builtin/merge.c
index b555a1bf..a9b99c9f 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -1530,7 +1530,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
 	     * Stash away the local changes so that we can try more than one.
 	     */
 	    save_state(stash))
-		hashcpy(stash, null_sha1);
+		hashclr(stash);
 
 	for (i = 0; i < use_strategies_nr; i++) {
 		int ret;
diff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c
index 875e7ed9..172470bf 100644
--- a/builtin/unpack-objects.c
+++ b/builtin/unpack-objects.c
@@ -355,7 +355,7 @@ static void unpack_delta_entry(enum object_type type, unsigned long delta_size,
 			return; /* we are done */
 		else {
 			/* cannot resolve yet --- queue it */
-			hashcpy(obj_list[nr].sha1, null_sha1);
+			hashclr(obj_list[nr].sha1);
 			add_delta_to_list(nr, base_sha1, 0, delta_data, delta_size);
 			return;
 		}
@@ -406,7 +406,7 @@ static void unpack_delta_entry(enum object_type type, unsigned long delta_size,
 			 * The delta base object is itself a delta that
 			 * has not been resolved yet.
 			 */
-			hashcpy(obj_list[nr].sha1, null_sha1);
+			hashclr(obj_list[nr].sha1);
 			add_delta_to_list(nr, null_sha1, base_offset, delta_data, delta_size);
 			return;
 		}
diff --git a/diff.c b/diff.c
index fa78fc18..f2234012 100644
--- a/diff.c
+++ b/diff.c
@@ -3134,7 +3134,7 @@ static void diff_fill_sha1_info(struct diff_filespec *one)
 		if (!one->sha1_valid) {
 			struct stat st;
 			if (one->is_stdin) {
-				hashcpy(one->sha1, null_sha1);
+				hashclr(one->sha1);
 				return;
 			}
 			if (lstat(one->path, &st) < 0)
diff --git a/submodule-config.c b/submodule-config.c
index db1847ff..077db405 100644
--- a/submodule-config.c
+++ b/submodule-config.c
@@ -377,7 +377,7 @@ static int gitmodule_sha1_from_commit(const unsigned char *commit_sha1,
 	int ret = 0;
 
 	if (is_null_sha1(commit_sha1)) {
-		hashcpy(gitmodules_sha1, null_sha1);
+		hashclr(gitmodules_sha1);
 		return 1;
 	}
 
diff --git a/t/helper/test-submodule-config.c b/t/helper/test-submodule-config.c
index dab8c277..7922ffba 100644
--- a/t/helper/test-submodule-config.c
+++ b/t/helper/test-submodule-config.c
@@ -49,7 +49,7 @@ int main(int argc, char **argv)
 		path_or_name = arg[1];
 
 		if (commit[0] == '\0')
-			hashcpy(commit_sha1, null_sha1);
+			hashclr(commit_sha1);
 		else if (get_sha1(commit, commit_sha1) < 0)
 			die_usage(argc, argv, "Commit not found.");
 
Previous: brian m. carlsonNext: brian m. carlson
Message 3 of 14 in “struct object_id, Part 4”
  1. 00/11 struct object_id, Part 4brian m. carlson, Jun 24, 2016
  2. 01/11 hex: add oid_to_hex_r.brian m. carlson, Jun 24, 2016
  3. 03/11 Convert hashcpy with null_sha1 to hashclr.brian m. carlson, Jun 24, 2016
  4. 04/11 coccinelle: apply object_id Coccinelle transformationsbrian m. carlson, Jun 24, 2016
  5. 05/11 diff: convert struct diff_filespec to struct object_idbrian m. carlson, Jun 24, 2016
  6. 10/11 merge-recursive: convert merge_recursive_generic to object_idbrian m. carlson, Jun 24, 2016
  7. 09/11 merge-recursive: convert leaf functions to use struct object_idbrian m. carlson, Jun 24, 2016
  8. 11/11 diff: convert prep_temp_blob to struct object_id.brian m. carlson, Jun 24, 2016
  9. 07/11 merge-recursive: convert struct stage_data to use object_idbrian m. carlson, Jun 24, 2016
  10. 02/11 contrib/coccinelle: add basic Coccinelle transformsbrian m. carlson, Jun 24, 2016
  11. 06/11 diff: rename struct diff_filespec's sha1_valid memberbrian m. carlson, Jun 24, 2016
  12. Junio C HamanoJun 25, 2016
  13. brian m. carlsonJun 25, 2016
  14. 08/11 merge-recursive: convert struct merge_file_info to object_idbrian m. carlson, Jun 24, 2016

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.