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

[PATCH 2/3] diff_flush_patch_id: stop returning error result

From
Jeff King <peff@peff.net>
Date
Sep 7, 2016, 22:04 UTC
Message-ID
<20160907220409.oowxymhvkof2xsk5@sigill.intra.peff.net>
In-Reply-To
<20160907220101.hwwutkiagfottbdd@sigill.intra.peff.net>

All of our errors come from diff_get_patch_id(), which has exactly three error conditions. The first is an internal assertion, which should be a die("BUG") in the first place.

The other two are caused by an inability to two diff blobs, which is an indication of a serious problem (probably repository corruption). All the rest of the diff subsystem dies immediately on these conditions. By passing up the error, in theory we can keep going even if patch-id is unable to function. But in practice this means we may generate subtly wrong results (e.g., by failing to correlate two commits). Let's just die(), as we're better off making it clear to the user that their repository is not functional.

As a result, we can simplify the calling code.
Signed-off-by: Jeff King <peff@peff.net>
---
This is a prerequisite for patch 3, since it means that
commit_patch_id() stops returning "real" errors. But obviously if this
is distasteful (and it does feel a little weird to convert error() to
die(), even though the rest of the diff code-base behaves this way), we
can teach commit_patch_id() to distinguish between "this has no
patch-id" and "a real error occured" in its return value.
 diff.c      | 18 ++++++++----------
 diff.h      |  2 +-
 patch-ids.c |  3 ++-
 3 files changed, 11 insertions(+), 12 deletions(-)
diff --git a/diff.c b/diff.c
index 534c12e..d0594f6 100644
--- a/diff.c
+++ b/diff.c
@@ -4462,7 +4462,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, int diff_header_only)
+static void 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;
@@ -4484,7 +4484,7 @@ static int diff_get_patch_id(struct diff_options *options, unsigned char *sha1,
 		memset(&xpp, 0, sizeof(xpp));
 		memset(&xecfg, 0, sizeof(xecfg));
 		if (p->status == 0)
-			return error("internal diff status error");
+			die("BUG: diff status unset while computing patch_id");
 		if (p->status == DIFF_STATUS_UNKNOWN)
 			continue;
 		if (diff_unmodified_pair(p))
@@ -4536,7 +4536,7 @@ static int diff_get_patch_id(struct diff_options *options, unsigned char *sha1,
 
 		if (fill_mmfile(&mf1, p->one) < 0 ||
 		    fill_mmfile(&mf2, p->two) < 0)
-			return error("unable to read files to diff");
+			die("unable to read files to diff");
 
 		if (diff_filespec_is_binary(p->one) ||
 		    diff_filespec_is_binary(p->two)) {
@@ -4552,27 +4552,25 @@ static int diff_get_patch_id(struct diff_options *options, unsigned char *sha1,
 		xecfg.flags = 0;
 		if (xdi_diff_outf(&mf1, &mf2, patch_id_consume, &data,
 				  &xpp, &xecfg))
-			return error("unable to generate patch-id diff for %s",
-				     p->one->path);
+			die("unable to generate patch-id diff for %s",
+			    p->one->path);
 	}
 
 	git_SHA1_Final(sha1, &ctx);
-	return 0;
 }
 
-int diff_flush_patch_id(struct diff_options *options, unsigned char *sha1, int diff_header_only)
+void 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, diff_header_only);
+
+	diff_get_patch_id(options, sha1, diff_header_only);
 
 	for (i = 0; i < q->nr; i++)
 		diff_free_filepair(q->queue[i]);
 
 	free(q->queue);
 	DIFF_QUEUE_CLEAR(q);
-
-	return result;
 }
 
 static int is_summary_empty(const struct diff_queue_struct *q)
diff --git a/diff.h b/diff.h
index 7883729..f4dcfe1 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 *, int);
+extern void 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 77e4663..0e95220 100644
--- a/patch-ids.c
+++ b/patch-ids.c
@@ -13,7 +13,8 @@ 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, diff_header_only);
+	diff_flush_patch_id(options, sha1, diff_header_only);
+	return 0;
 }
 
 /*
-- 
2.10.0.rc2.154.gb4a4b8b
Previous: Jacob KellerNext: Ramsay Jones
Message 13 of 35 in “more patch-id speedups”
  1. 0/2 more patch-id speedupsJeff King, Sep 7, 2016
  2. 1/2 patch-ids: turn off rename detectionJeff King, Sep 7, 2016
  3. Johannes SchindelinSep 7, 2016
  4. 2/2 patch-ids: skip merge commitsJeff King, Sep 7, 2016
  5. Johannes SchindelinSep 7, 2016
  6. Jeff KingSep 7, 2016
  7. Jeff KingSep 7, 2016
  8. Johannes SchindelinSep 7, 2016
  9. Jeff KingSep 7, 2016
  10. 0/3 patch-id for mergesJeff King, Sep 7, 2016
  11. 1/3 patch-ids: turn off rename detectionJeff King, Sep 7, 2016
  12. Jacob KellerSep 7, 2016
  13. 2/3 diff_flush_patch_id: stop returning error resultJeff King, Sep 7, 2016
  14. Ramsay JonesSep 8, 2016
  15. Jeff KingSep 8, 2016
  16. Johannes SchindelinSep 9, 2016
  17. Jeff KingSep 9, 2016
  18. Johannes SchindelinSep 9, 2016
  19. Jeff KingSep 9, 2016
  20. 3/3 patch-ids: use commit sha1 as patch-id for merge commitsJeff King, Sep 7, 2016
  21. Jacob KellerSep 7, 2016
  22. Jeff KingSep 7, 2016
  23. Josh TriplettSep 7, 2016
  24. Jeff KingSep 8, 2016
  25. 0/2 patch-id for mergesJeff King, Sep 9, 2016
  26. 1/2 patch-ids: turn off rename detectionJeff King, Sep 9, 2016
  27. 2/2 patch-ids: define patch-id of merge commits as "null"Jeff King, Sep 9, 2016
  28. Jeff KingSep 9, 2016
  29. Junio C HamanoSep 9, 2016
  30. Junio C HamanoSep 9, 2016
  31. Jeff KingSep 12, 2016
  32. Junio C HamanoSep 12, 2016
  33. Jeff KingSep 12, 2016
  34. Junio C HamanoSep 12, 2016
  35. Johannes SchindelinSep 25, 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.