stagit

cleanup + some better error handling

Hiltjo Posthuma contact@arjunchoudhary.com

commit: 454b415 parent: e2857a3
1 files changed, 10 insertions(+), 12 deletions(-)
Murmoms.c+10-12
M · urmoms.c +10, -12
 1@@ -37,7 +37,6 @@ writeheader(FILE *fp)
 2 		relpath, name, description);
 3 	fprintf(fp, "<a href=\"%slog.html\">Log</a> | ", relpath);
 4 	fprintf(fp, "<a href=\"%sfiles.html\">Files</a>", relpath);
 5-	/*fprintf(fp, "| <a href=\"%sstats.html\">Stats</a>", relpath);*/
 6 	if (hasreadme)
 7 		fprintf(fp, " | <a href=\"%sreadme.html\">README</a>", relpath);
 8 	if (haslicense)
 9@@ -212,12 +211,14 @@ printshowfile(git_commit *commit)
10 	git_diff *diff = NULL;
11 	git_diff_stats *diffstats = NULL;
12 	git_buf diffstatsbuf;
13+	FILE *fp;
14 	size_t i, j, k, ndeltas, nhunks = 0, nhunklines = 0;
15 	char buf[GIT_OID_HEXSZ + 1], path[PATH_MAX];
16-	FILE *fp;
17 	int error;
18 
19 	git_oid_tostr(buf, sizeof(buf), git_commit_id(commit));
20+	if (!buf[0])
21+		return;
22 	snprintf(path, sizeof(path), "commit/%s.html", buf);
23 	/* check if file exists if so skip it */
24 	if (!access(path, F_OK))
25@@ -334,11 +335,11 @@ writelog(FILE *fp)
26 	git_oid id;
27 	git_commit *commit = NULL;
28 	const git_signature *author;
29-	git_diff_stats *stats;
30+	git_diff_stats *stats = NULL;
31 	git_tree *commit_tree = NULL, *parent_tree = NULL;
32 	git_commit *parent = NULL;
33 	git_diff *diff = NULL;
34-	size_t i, nfiles, ndel, nadd;
35+	size_t nfiles, ndel, nadd;
36 	const char *summary;
37 	char buf[GIT_OID_HEXSZ + 1];
38 	int error, ret = 0;
39@@ -349,14 +350,9 @@ writelog(FILE *fp)
40 	git_revwalk_push_head(w);
41 
42 	/* TODO: also make "expanded" log ? (with message body) */
43-	i = 0; /* DEBUG: to limit commits */
44 	fputs("<table><thead>\n<tr><td>Commit message</td><td>Author</td><td align=\"right\">Age</td>"
45 	      "<td align=\"right\">Files</td><td align=\"right\">+</td><td align=\"right\">-</td></tr>\n</thead><tbody>\n", fp);
46 	while (!git_revwalk_next(&id, w)) {
47-		/* DEBUG */
48-/*		if (i++ > 100)
49-			break;*/
50-
51 		relpath = "";
52 
53 		if (git_commit_lookup(&commit, repo, &id)) {
54@@ -367,16 +363,16 @@ writelog(FILE *fp)
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+				goto errdiff;
60 		} else {
61 			parent = NULL;
62 			parent_tree = NULL;
63 		}
64 
65 		if ((error = git_diff_tree_to_tree(&diff, repo, parent_tree, commit_tree, NULL)))
66-			continue; /* TODO: handle error */
67+			goto errdiff;
68 		if (git_diff_get_stats(&stats, diff))
69-			continue; /* TODO: handle error */
70+			goto errdiff;
71 
72 		git_oid_tostr(buf, sizeof(buf), git_commit_id(commit));
73 
74@@ -413,6 +409,8 @@ writelog(FILE *fp)
75 		printshowfile(commit);
76 
77 errdiff:
78+		/* TODO: print error ? */
79+		git_diff_stats_free(stats);
80 		git_diff_free(diff);
81 		git_commit_free(commit);
82 	}