git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Jeff King <peff@peff.net>
To: git@vger.kernel.org
Cc: Michael Haggerty <mhagger@alum.mit.edu>,
	Kevin Willford <kewillf@microsoft.com>,
	Xiaolong Ye <xiaolong.ye@intel.com>,
	Johannes Schindelin <Johannes.Schindelin@gmx.de>,
	Josh Triplett <josh@joshtriplett.org>
Subject: [PATCH 2/3] diff_flush_patch_id: stop returning error result
Date: Wed, 7 Sep 2016 18:04:09 -0400	[thread overview]
Message-ID: <20160907220409.oowxymhvkof2xsk5@sigill.intra.peff.net> (raw)
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


  parent reply	other threads:[~2016-09-07 22:04 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-07  7:53 [RFC/PATCH 0/2] more patch-id speedups Jeff King
2016-09-07  7:54 ` [PATCH 1/2] patch-ids: turn off rename detection Jeff King
2016-09-07 12:53   ` Johannes Schindelin
2016-09-07  7:54 ` [PATCH 2/2] patch-ids: skip merge commits Jeff King
2016-09-07 12:52   ` Johannes Schindelin
2016-09-07 18:46     ` Jeff King
2016-09-07 22:08       ` Jeff King
2016-09-07 13:06 ` [RFC/PATCH 0/2] more patch-id speedups Johannes Schindelin
2016-09-07 18:49   ` Jeff King
2016-09-07 22:01 ` [RFC/PATCH v2 0/3] patch-id for merges Jeff King
2016-09-07 22:02   ` [PATCH 1/3] patch-ids: turn off rename detection Jeff King
2016-09-07 22:12     ` Jacob Keller
2016-09-07 22:04   ` Jeff King [this message]
2016-09-08  0:51     ` [PATCH 2/3] diff_flush_patch_id: stop returning error result Ramsay Jones
2016-09-08  7:20       ` Jeff King
2016-09-09 10:28     ` Johannes Schindelin
2016-09-09 10:40       ` Jeff King
2016-09-09 12:58         ` Johannes Schindelin
2016-09-09 19:37           ` Jeff King
2016-09-07 22:04   ` [PATCH 3/3] patch-ids: use commit sha1 as patch-id for merge commits Jeff King
2016-09-07 22:28     ` Jacob Keller
2016-09-07 22:38       ` Jeff King
2016-09-07 22:51   ` [RFC/PATCH v2 0/3] patch-id for merges Josh Triplett
2016-09-08  7:30     ` Jeff King
2016-09-09 20:34   ` [PATCH v3 0/2] " Jeff King
2016-09-09 20:34     ` [PATCH v3 1/2] patch-ids: turn off rename detection Jeff King
2016-09-09 20:34     ` [PATCH v3 2/2] patch-ids: define patch-id of merge commits as "null" Jeff King
2016-09-09 20:37       ` Jeff King
2016-09-09 21:13       ` Junio C Hamano
2016-09-09 21:01     ` [PATCH v3 0/2] patch-id for merges Junio C Hamano
2016-09-12 15:59       ` Jeff King
2016-09-12 17:18         ` Junio C Hamano
2016-09-12 17:56           ` Jeff King
2016-09-12 20:44             ` Junio C Hamano
2016-09-25 18:25     ` Johannes Schindelin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160907220409.oowxymhvkof2xsk5@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=josh@joshtriplett.org \
    --cc=kewillf@microsoft.com \
    --cc=mhagger@alum.mit.edu \
    --cc=xiaolong.ye@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).