[PATCH v1 5/8] sequencer: don't die in print_commit_summary()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Phillip Wood <phillip.wood@xxxxxxxxxxxxx>

Return an error rather than dying so that the sequencer can exit
cleanly once it starts committing without forking 'git commit'

Signed-off-by: Phillip Wood <phillip.wood@xxxxxxxxxxxxx>
---
 builtin/commit.c |  3 ++-
 sequencer.c      | 17 +++++++++++------
 sequencer.h      |  4 ++--
 3 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/builtin/commit.c b/builtin/commit.c
index b109feaca11e3e43b1a59dee1868244824eaf345..c924cbac9e0d55941e984b3cce3c1e565cd8cf3c 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -1612,7 +1612,8 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
 			flags |= SUMMARY_INITIAL_COMMIT;
 		if (author_date_is_interesting())
 			flags |= SUMMARY_SHOW_AUTHOR_DATE;
-		print_commit_summary(prefix, &oid, flags);
+		if (print_commit_summary(prefix, &oid, flags))
+			exit(128);
 	}
 
 	UNLEAK(err);
diff --git a/sequencer.c b/sequencer.c
index d4f77a5f24c89479a4a18c2b89a3cd4e7ba7ba6c..ae24405c23d021ed7916e5e2d9df6de27f867a2e 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -875,8 +875,8 @@ static const char *implicit_ident_advice(void)
 
 }
 
-void print_commit_summary(const char *prefix, const struct object_id *oid,
-			  int flags)
+int print_commit_summary(const char *prefix, const struct object_id *oid,
+			 int flags)
 {
 	struct rev_info rev;
 	struct commit *commit;
@@ -885,12 +885,13 @@ void print_commit_summary(const char *prefix, const struct object_id *oid,
 	struct pretty_print_context pctx = {0};
 	struct strbuf author_ident = STRBUF_INIT;
 	struct strbuf committer_ident = STRBUF_INIT;
+	int ret = 0;
 
 	commit = lookup_commit(oid);
 	if (!commit)
-		die(_("couldn't look up newly created commit"));
+		return error(_("couldn't look up newly created commit"));
 	if (parse_commit(commit))
-		die(_("could not parse newly created commit"));
+		return error(_("could not parse newly created commit"));
 
 	strbuf_addstr(&format, "format:%h] %s");
 
@@ -934,8 +935,10 @@ void print_commit_summary(const char *prefix, const struct object_id *oid,
 	diff_setup_done(&rev.diffopt);
 
 	head = resolve_ref_unsafe("HEAD", 0, NULL, NULL);
-	if (!head)
-		die_errno(_("unable to resolve HEAD after creating commit"));
+	if (!head) {
+		ret = error_errno(_("unable to resolve HEAD after creating commit"));
+		goto out;
+	}
 	if (!strcmp(head, "HEAD"))
 		head = _("detached HEAD");
 	else
@@ -948,7 +951,9 @@ void print_commit_summary(const char *prefix, const struct object_id *oid,
 		log_tree_commit(&rev, commit);
 	}
 
+out:
 	strbuf_release(&format);
+	return ret;
 }
 
 static int is_original_commit_empty(struct commit *commit)
diff --git a/sequencer.h b/sequencer.h
index c7989f93fcf08f979f5869cd4ec27f0dd0b88c82..0e3c2c9fd416349fb704a7ebc72c93a9b9a67703 100644
--- a/sequencer.h
+++ b/sequencer.h
@@ -76,6 +76,6 @@ void commit_post_rewrite(const struct commit *current_head,
 
 #define SUMMARY_INITIAL_COMMIT   (1 << 0)
 #define SUMMARY_SHOW_AUTHOR_DATE (1 << 1)
-void print_commit_summary(const char *prefix, const struct object_id *oid,
-			  int flags);
+int print_commit_summary(const char *prefix, const struct object_id *oid,
+			 int flags);
 #endif
-- 
2.14.3




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux