stagit

fix when commit has no parent

also dont show parent when there is no id for it.

Hiltjo Posthuma contact@arjunchoudhary.com

commit: b9e4939 parent: 2c0bb5b
1 files changed, 26 insertions(+), 15 deletions(-)
Murmoms.c+26-15
M · urmoms.c +26, -15
 1@@ -168,7 +168,7 @@ printcommit(FILE *fp, git_commit *commit)
 2 	fprintf(fp, "<b>commit</b> <a href=\"%scommit/%s.html\">%s</a>\n",
 3 		relpath, buf, buf);
 4 
 5-	if (git_oid_tostr(buf, sizeof(buf), git_commit_parent_id(commit, 0)))
 6+	if (git_oid_tostr(buf, sizeof(buf), git_commit_parent_id(commit, 0)) && buf[0])
 7 		fprintf(fp, "<b>parent</b> <a href=\"%scommit/%s.html\">%s</a>\n",
 8 			relpath, buf, buf);
 9 
10@@ -225,12 +225,15 @@ printshowfile(git_commit *commit)
11 	writeheader(fp);
12 	printcommit(fp, commit);
13 
14-	if ((error = git_commit_parent(&parent, commit, 0)))
15-		return;
16 	if ((error = git_commit_tree(&commit_tree, commit)))
17 		goto err;
18-	if ((error = git_commit_tree(&parent_tree, parent)))
19-		goto err;
20+	if (!(error = git_commit_parent(&parent, commit, 0))) {
21+		if ((error = git_commit_tree(&parent_tree, parent)))
22+			goto err; /* TODO: handle error */
23+	} else {
24+		parent = NULL;
25+		parent_tree = NULL;
26+	}
27 	if ((error = git_diff_tree_to_tree(&diff, repo, parent_tree, commit_tree, NULL)))
28 		goto err;
29 
30@@ -334,7 +337,7 @@ writelog(FILE *fp)
31 	size_t i, nfiles, ndel, nadd;
32 	const char *summary;
33 	char buf[GIT_OID_HEXSZ + 1];
34-	int error;
35+	int error, ret = 0;
36 
37 	mkdir("commit", 0755);
38 
39@@ -352,14 +355,20 @@ writelog(FILE *fp)
40 
41 		relpath = "";
42 
43-		if (git_commit_lookup(&commit, repo, &id))
44-			return 1; /* TODO: error */
45-		if ((error = git_commit_parent(&parent, commit, 0)))
46-			continue; /* TODO: handle error */
47+		if (git_commit_lookup(&commit, repo, &id)) {
48+			ret = 1;
49+			goto err;
50+		}
51 		if ((error = git_commit_tree(&commit_tree, commit)))
52-			continue; /* TODO: handle error */
53-		if ((error = git_commit_tree(&parent_tree, parent)))
54-			continue; /* TODO: handle error */
55+			goto errdiff; /* TODO: handle error */
56+		if (!(error = git_commit_parent(&parent, commit, 0))) {
57+			if ((error = git_commit_tree(&parent_tree, parent)))
58+				goto errdiff; /* TODO: handle error */
59+		} else {
60+			parent = NULL;
61+			parent_tree = NULL;
62+		}
63+
64 		if ((error = git_diff_tree_to_tree(&diff, repo, parent_tree, commit_tree, NULL)))
65 			continue; /* TODO: handle error */
66 		if (git_diff_get_stats(&stats, diff))
67@@ -399,14 +408,16 @@ writelog(FILE *fp)
68 		relpath = "../";
69 		printshowfile(commit);
70 
71+errdiff:
72 		git_diff_free(diff);
73 		git_commit_free(commit);
74 	}
75 	fprintf(fp, "</tbody></table>");
76+err:
77 	git_revwalk_free(w);
78 	relpath = "";
79 
80-	return 0;
81+	return ret;
82 }
83 
84 void
85@@ -439,7 +450,7 @@ printcommitatom(FILE *fp, git_commit *commit)
86 
87 	fputs("<content type=\"text\">", fp);
88 	fprintf(fp, "commit %s\n", buf);
89-	if (git_oid_tostr(buf, sizeof(buf), git_commit_parent_id(commit, 0)))
90+	if (git_oid_tostr(buf, sizeof(buf), git_commit_parent_id(commit, 0)) && buf[0])
91 		fprintf(fp, "parent %s\n", buf);
92 
93 	if ((count = (int)git_commit_parentcount(commit)) > 1) {