All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] commit: check return value of lookup_commit()
@ 2011-08-15 15:38 Nguyễn Thái Ngọc Duy
  2011-08-15 17:46 ` Junio C Hamano
  2011-08-17  1:42 ` [PATCH v2] commit: accept tag objects in HEAD/MERGE_HEAD Nguyễn Thái Ngọc Duy
  0 siblings, 2 replies; 21+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2011-08-15 15:38 UTC (permalink / raw)
  To: git, Junio C Hamano; +Cc: Nguyễn Thái Ngọc Duy

If lookup_commit() returns NULL, there's usually serious error and the
command aborts anyway. However it's still nicer to have a message
telling us where it aborts, rather than segmentation fault.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 I suppose die() also cleans up $GIT_DIR/index.lock while sigsegv does not.

 builtin/commit.c |   17 +++++++++++++----
 1 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/builtin/commit.c b/builtin/commit.c
index 2088b6b..bfb7a5a 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -1387,6 +1387,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
 	unsigned char commit_sha1[20];
 	struct ref_lock *ref_lock;
 	struct commit_list *parents = NULL, **pptr = &parents;
+	struct commit *commit;
 	struct stat statbuf;
 	int allow_fast_forward = 1;
 	struct wt_status s;
@@ -1423,7 +1424,6 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
 			reflog_msg = "commit (initial)";
 	} else if (amend) {
 		struct commit_list *c;
-		struct commit *commit;
 
 		if (!reflog_msg)
 			reflog_msg = "commit (amend)";
@@ -1439,7 +1439,10 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
 
 		if (!reflog_msg)
 			reflog_msg = "commit (merge)";
-		pptr = &commit_list_insert(lookup_commit(head_sha1), pptr)->next;
+		commit = lookup_commit(head_sha1);
+		if (!commit)
+			die(_("could not parse HEAD commit"));
+		pptr = &commit_list_insert(commit, pptr)->next;
 		fp = fopen(git_path("MERGE_HEAD"), "r");
 		if (fp == NULL)
 			die_errno(_("could not open '%s' for reading"),
@@ -1448,7 +1451,10 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
 			unsigned char sha1[20];
 			if (get_sha1_hex(m.buf, sha1) < 0)
 				die(_("Corrupt MERGE_HEAD file (%s)"), m.buf);
-			pptr = &commit_list_insert(lookup_commit(sha1), pptr)->next;
+			commit = lookup_commit(sha1);
+			if (!commit)
+				die(_("could not parse commit %s"), sha1_to_hex(sha1));
+			pptr = &commit_list_insert(commit, pptr)->next;
 		}
 		fclose(fp);
 		strbuf_release(&m);
@@ -1465,7 +1471,10 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
 			reflog_msg = (whence == FROM_CHERRY_PICK)
 					? "commit (cherry-pick)"
 					: "commit";
-		pptr = &commit_list_insert(lookup_commit(head_sha1), pptr)->next;
+		commit = lookup_commit(head_sha1);
+		if (!commit)
+			die(_("could not parse HEAD commit"));
+		pptr = &commit_list_insert(commit, pptr)->next;
 	}
 
 	/* Finally, get the commit message */
-- 
1.7.4.74.g639db

^ permalink raw reply related	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2011-08-23 18:47 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-08-15 15:38 [PATCH] commit: check return value of lookup_commit() Nguyễn Thái Ngọc Duy
2011-08-15 17:46 ` Junio C Hamano
2011-08-16 13:22   ` Nguyen Thai Ngoc Duy
2011-08-16 18:02     ` Junio C Hamano
2011-08-17  1:32       ` Nguyen Thai Ngoc Duy
2011-08-17  1:42 ` [PATCH v2] commit: accept tag objects in HEAD/MERGE_HEAD Nguyễn Thái Ngọc Duy
2011-08-17 17:59   ` Junio C Hamano
2011-08-18  2:10     ` Nguyen Thai Ngoc Duy
2011-08-18 13:43   ` [PATCH v3] Accept tags in HEAD or MERGE_HEAD Nguyễn Thái Ngọc Duy
2011-08-18 18:54     ` Junio C Hamano
2011-08-19 12:53       ` Nguyen Thai Ngoc Duy
2011-08-19 14:50     ` [PATCH v4 1/4] commit: remove global variable head_sha1[] Nguyễn Thái Ngọc Duy
2011-08-19 14:50       ` [PATCH v4 2/4] merge: keep stash[] a local variable Nguyễn Thái Ngọc Duy
2011-08-19 22:59         ` Junio C Hamano
2011-08-19 14:50       ` [PATCH v4 3/4] merge: remove global variable head[] Nguyễn Thái Ngọc Duy
2011-08-23 18:46         ` Junio C Hamano
2011-08-19 14:50       ` [PATCH v4 4/4] Accept tags in HEAD or MERGE_HEAD Nguyễn Thái Ngọc Duy
2011-08-19 20:17         ` Junio C Hamano
2011-08-20 16:37           ` Nguyen Thai Ngoc Duy
2011-08-19 18:57       ` [PATCH v4 1/4] commit: remove global variable head_sha1[] Junio C Hamano
2011-08-20 12:03         ` Nguyen Thai Ngoc Duy

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.