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

[PATCH 5/6] use parse_commit_or_die instead of custom message

From
Jeff King <peff@peff.net>
Date
Oct 24, 2013, 08:54 UTC
Message-ID
<20131024085401.GE1346@sigill.intra.peff.net>
In-Reply-To
<20131024085213.GA1267@sigill.intra.peff.net>

Many calls to parse_commit detect errors and die. In some cases, the custom error messages are more useful than what parse_commit_or_die could produce, because they give some context, like which ref the commit came from. Some, however, just say "invalid commit". Let's convert the latter to use parse_commit_or_die; its message is slightly more informative, and it makes the error more consistent throughout git.

Signed-off-by: Jeff King <peff@peff.net>
---
 shallow.c     | 3 +--
 upload-pack.c | 3 +--
 2 files changed, 2 insertions(+), 4 deletions(-)
diff --git a/shallow.c b/shallow.c
index cdf37d6..961cf6f 100644
--- a/shallow.c
+++ b/shallow.c
@@ -90,8 +90,7 @@ struct commit_list *get_shallow_commits(struct object_array *heads, int depth,
 				cur_depth = *(int *)commit->util;
 			}
 		}
-		if (parse_commit(commit))
-			die("invalid commit");
+		parse_commit_or_die(commit);
 		cur_depth++;
 		if (cur_depth >= depth) {
 			commit_list_insert(commit, &result);
diff --git a/upload-pack.c b/upload-pack.c
index a6c54e0..abe6636 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -649,8 +649,7 @@ static void receive_needs(void)
 				/* make sure the real parents are parsed */
 				unregister_shallow(object->sha1);
 				object->parsed = 0;
-				if (parse_commit((struct commit *)object))
-					die("invalid commit");
+				parse_commit_or_die((struct commit *)object);
 				parents = ((struct commit *)object)->parents;
 				while (parents) {
 					add_object_array(&parents->item->object,
-- 
1.8.4.1.898.g8bf8a41.dirty
Previous: Jeff KingNext: Jeff King
Message 6 of 7 in “fix some parse_commit segfaults”
  1. 0/6 fix some parse_commit segfaultsJeff King, Oct 24, 2013
  2. 1/6 log_tree_diff: die when we fail to parse a commitJeff King, Oct 24, 2013
  3. 2/6 assume parse_commit checks commit->object.parsedJeff King, Oct 24, 2013
  4. 3/6 assume parse_commit checks for NULL commitJeff King, Oct 24, 2013
  5. 4/6 use parse_commit_or_die instead of segfaultingJeff King, Oct 24, 2013
  6. 5/6 use parse_commit_or_die instead of custom messageJeff King, Oct 24, 2013
  7. 6/6 checkout: do not die when leaving broken detached HEADJeff King, Oct 24, 2013

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.