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

[[PATCH v2] 3/4] patch-ids: add flag to create the diff patch id using header only data

From
KWKevin Willford <kcwillford@gmail.com>
Date
Jul 29, 2016, 16:19 UTC
Message-ID
<20160729161920.3792-4-kcwillford@gmail.com>
In-Reply-To
<20160729161920.3792-1-kcwillford@gmail.com>
From: Kevin Willford <kewillf@microsoft.com>

This will allow a diff patch id to be created using only the header data so that the contents of the file will not have to be loaded.

Signed-off-by: Kevin Willford <kcwillford@gmail.com>
---
 diff.c      | 16 ++++++++++------
 diff.h      |  2 +-
 patch-ids.c |  2 +-
 3 files changed, 12 insertions(+), 8 deletions(-)
diff --git a/diff.c b/diff.c
index 7d03419..28a4190 100644
--- a/diff.c
+++ b/diff.c
@@ -4455,7 +4455,7 @@ static void patch_id_consume(void *priv, char *line, unsigned long len)
 }
 
 /* returns 0 upon success, and writes result into sha1 */
-static int diff_get_patch_id(struct diff_options *options, unsigned char *sha1)
+static int diff_get_patch_id(struct diff_options *options, unsigned char *sha1, int diff_header_only)
 {
 	struct diff_queue_struct *q = &diff_queued_diff;
 	int i;
@@ -4490,9 +4490,6 @@ static int diff_get_patch_id(struct diff_options *options, unsigned char *sha1)
 
 		diff_fill_sha1_info(p->one);
 		diff_fill_sha1_info(p->two);
-		if (fill_mmfile(&mf1, p->one) < 0 ||
-				fill_mmfile(&mf2, p->two) < 0)
-			return error("unable to read files to diff");
 
 		len1 = remove_space(p->one->path, strlen(p->one->path));
 		len2 = remove_space(p->two->path, strlen(p->two->path));
@@ -4527,6 +4524,13 @@ static int diff_get_patch_id(struct diff_options *options, unsigned char *sha1)
 					len2, p->two->path);
 		git_SHA1_Update(&ctx, buffer, len1);
 
+		if (diff_header_only)
+			continue;
+
+		if (fill_mmfile(&mf1, p->one) < 0 ||
+			fill_mmfile(&mf2, p->two) < 0)
+			return error("unable to read files to diff");
+
 		if (diff_filespec_is_binary(p->one) ||
 		    diff_filespec_is_binary(p->two)) {
 			git_SHA1_Update(&ctx, oid_to_hex(&p->one->oid),
@@ -4549,11 +4553,11 @@ static int diff_get_patch_id(struct diff_options *options, unsigned char *sha1)
 	return 0;
 }
 
-int diff_flush_patch_id(struct diff_options *options, unsigned char *sha1)
+int diff_flush_patch_id(struct diff_options *options, unsigned char *sha1, int diff_header_only)
 {
 	struct diff_queue_struct *q = &diff_queued_diff;
 	int i;
-	int result = diff_get_patch_id(options, sha1);
+	int result = diff_get_patch_id(options, sha1, diff_header_only);
 
 	for (i = 0; i < q->nr; i++)
 		diff_free_filepair(q->queue[i]);
diff --git a/diff.h b/diff.h
index 125447b..7883729 100644
--- a/diff.h
+++ b/diff.h
@@ -342,7 +342,7 @@ extern int run_diff_files(struct rev_info *revs, unsigned int option);
 extern int run_diff_index(struct rev_info *revs, int cached);
 
 extern int do_diff_cache(const unsigned char *, struct diff_options *);
-extern int diff_flush_patch_id(struct diff_options *, unsigned char *);
+extern int diff_flush_patch_id(struct diff_options *, unsigned char *, int);
 
 extern int diff_result_code(struct diff_options *, int);
 
diff --git a/patch-ids.c b/patch-ids.c
index bafaae2..69a14a3 100644
--- a/patch-ids.c
+++ b/patch-ids.c
@@ -13,7 +13,7 @@ int commit_patch_id(struct commit *commit, struct diff_options *options,
 	else
 		diff_root_tree_sha1(commit->object.oid.hash, "", options);
 	diffcore_std(options);
-	return diff_flush_patch_id(options, sha1);
+	return diff_flush_patch_id(options, sha1, 0);
 }
 
 static int patch_id_cmp(struct patch_id *a,
-- 
2.9.2.gvfs.2.42.gb7633a3
Previous: Johannes SchindelinNext: Junio C Hamano
Message 23 of 25 in “0/4] Use header data patch ids for rebase to avoid loading file content”
  1. 0/4] Use header data patch ids for rebase to avoid loading file contentKevin Willford, Jul 29, 2016
  2. 1/4] patch-ids: stop using a hand-rolled hashmap implementationKevin Willford, Jul 29, 2016
  3. Junio C HamanoJul 29, 2016
  4. Johannes SchindelinAug 1, 2016
  5. Junio C HamanoAug 1, 2016
  6. Eric WongAug 1, 2016
  7. Johannes SchindelinAug 2, 2016
  8. Junio C HamanoAug 2, 2016
  9. Junio C HamanoAug 2, 2016
  10. Junio C HamanoJul 29, 2016
  11. 2/4] patch-ids: replace the seen indicator with a commit pointerKevin Willford, Jul 29, 2016
  12. Junio C HamanoJul 29, 2016
  13. 4/4] rebase: avoid computing unnecessary patch IDsKevin Willford, Jul 29, 2016
  14. Junio C HamanoJul 29, 2016
  15. Johannes SchindelinAug 1, 2016
  16. Junio C HamanoAug 1, 2016
  17. Jakub NarębskiAug 2, 2016
  18. Junio C HamanoAug 2, 2016
  19. Johannes SchindelinAug 2, 2016
  20. Junio C HamanoAug 2, 2016
  21. Junio C HamanoAug 4, 2016
  22. Johannes SchindelinAug 4, 2016
  23. 3/4] patch-ids: add flag to create the diff patch id using header only dataKevin Willford, Jul 29, 2016
  24. Junio C HamanoJul 29, 2016
  25. Johannes SchindelinAug 1, 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.