improve log, fix warnings
1 files changed, 75 insertions(+), 21 deletions(-) | |||
---|---|---|---|
M | urmoms.c | +75 | -21 |
1@@ -1,6 +1,7 @@
2 #include <sys/stat.h>
3
4 #include <err.h>
5+#include <inttypes.h>
6 #include <libgen.h>
7 #include <limits.h>
8 #include <stdio.h>
9@@ -58,8 +59,7 @@ efopen(const char *name, const char *flags)
10 {
11 FILE *fp;
12
13- fp = fopen(name, flags);
14- if (!fp)
15+ if (!(fp = fopen(name, flags)))
16 err(1, "fopen");
17
18 return fp;
19@@ -139,6 +139,7 @@ printcommit(FILE *fp, git_commit *commit)
20 int i, count;
21 const char *scan, *eol;
22
23+ /* TODO: show tag when commit has it */
24 git_oid_tostr(buf, sizeof(buf), git_commit_id(commit));
25 fprintf(fp, "commit <a href=\"%scommit/%s.html\">%s</a>\n",
26 relpath, buf, buf);
27@@ -186,8 +187,8 @@ printshowfile(git_commit *commit)
28 git_tree *commit_tree = NULL, *parent_tree = NULL;
29 git_patch *patch = NULL;
30 git_diff *diff = NULL;
31- git_buf diffstatsbuf;
32 git_diff_stats *diffstats = NULL;
33+ git_buf diffstatsbuf;
34 size_t i, j, k, ndeltas, nhunks = 0, nhunklines = 0;
35 char buf[GIT_OID_HEXSZ + 1], path[PATH_MAX];
36 FILE *fp;
37@@ -202,24 +203,20 @@ printshowfile(git_commit *commit)
38 writeheader(fp);
39 printcommit(fp, commit);
40
41- error = git_commit_parent(&parent, commit, 0);
42- if (error)
43+ if ((error = git_commit_parent(&parent, commit, 0)))
44 return;
45-
46- error = git_commit_tree(&commit_tree, commit);
47- if (error)
48+ if ((error = git_commit_tree(&commit_tree, commit)))
49 goto err;
50- error = git_commit_tree(&parent_tree, parent);
51- if (error)
52+ if ((error = git_commit_tree(&parent_tree, parent)))
53 goto err;
54- error = git_diff_tree_to_tree(&diff, repo, commit_tree, parent_tree, NULL);
55- if (error)
56+ if ((error = git_diff_tree_to_tree(&diff, repo, commit_tree, parent_tree, NULL)))
57 goto err;
58
59 /* diff stat */
60 if (!git_diff_get_stats(&diffstats, diff)) {
61 if (!git_diff_stats_to_buf(&diffstatsbuf, diffstats,
62- GIT_DIFF_STATS_FULL | GIT_DIFF_STATS_SHORT | GIT_DIFF_STATS_NUMBER | GIT_DIFF_STATS_INCLUDE_SUMMARY, 80)) {
63+ GIT_DIFF_STATS_FULL | GIT_DIFF_STATS_SHORT | GIT_DIFF_STATS_NUMBER |
64+ GIT_DIFF_STATS_INCLUDE_SUMMARY, 80)) {
65 fputs("<hr/>", fp);
66 fprintf(fp, "Diffstat:\n");
67 fputs(diffstatsbuf.ptr, fp);
68@@ -242,7 +239,9 @@ printshowfile(git_commit *commit)
69
70 #if 0
71 switch (delta->flags) {
72- case GIT_DIFF_FLAG_BINARY: continue; /* TODO: binary data */
73+ case GIT_DIFF_FLAG_BINARY:
74+ /* "Binary files /dev/null and b/favicon.png differ" or so */
75+ continue; /* TODO: binary data */
76 case GIT_DIFF_FLAG_NOT_BINARY: break;
77 case GIT_DIFF_FLAG_VALID_ID: break; /* TODO: check */
78 case GIT_DIFF_FLAG_EXISTS: break; /* TODO: check */
79@@ -286,27 +285,82 @@ writelog(FILE *fp)
80 {
81 git_revwalk *w = NULL;
82 git_oid id;
83- git_commit *c = NULL;
84- size_t i;
85+ git_commit *commit = NULL;
86+ const git_signature *author;
87+ git_diff_stats *stats;
88+ git_tree *commit_tree = NULL, *parent_tree = NULL;
89+ git_commit *parent = NULL;
90+ git_diff *diff = NULL;
91+ size_t i, nfiles, ndel, nadd;
92+ const char *summary;
93+ char buf[GIT_OID_HEXSZ + 1];
94+ int error;
95
96 mkdir("commit", 0755);
97
98 git_revwalk_new(&w, repo);
99 git_revwalk_push_head(w);
100
101+ /* TODO: also make "expanded" log ? (with message body) */
102 i = 0;
103+ fputs("<table><thead><tr><td>Summary</td><td>Author</td><td align=\"right\">Age</td>"
104+ "<td align=\"right\">Files</td><td align=\"right\">+</td><td align=\"right\">-</td></tr></thead><tbody>", fp);
105 while (!git_revwalk_next(&id, w)) {
106- if (git_commit_lookup(&c, repo, &id))
107+ if (git_commit_lookup(&commit, repo, &id))
108 return 1; /* TODO: error */
109- printcommit(fp, c);
110- printshowfile(c);
111- git_commit_free(c);
112+
113+ if ((error = git_commit_parent(&parent, commit, 0)))
114+ continue; /* TODO: handle error */
115+ if ((error = git_commit_tree(&commit_tree, commit)))
116+ continue; /* TODO: handle error */
117+ if ((error = git_commit_tree(&parent_tree, parent)))
118+ continue; /* TODO: handle error */
119+ if ((error = git_diff_tree_to_tree(&diff, repo, commit_tree, parent_tree, NULL)))
120+ continue; /* TODO: handle error */
121+ if (git_diff_get_stats(&stats, diff))
122+ continue; /* TODO: handle error */
123+
124+ git_oid_tostr(buf, sizeof(buf), git_commit_id(commit));
125+
126+ ndel = git_diff_stats_deletions(stats);
127+ nadd = git_diff_stats_insertions(stats);
128+ nfiles = git_diff_stats_files_changed(stats);
129+
130+ /* TODO: show tag when commit has it */
131+
132+ author = git_commit_author(commit);
133+ summary = git_commit_summary(commit);
134+
135+ fputs("<tr><td>", fp);
136+ if (summary) {
137+ fprintf(fp, "<a href=\"%scommit/%s.html\">", relpath, buf);
138+ xmlencode(fp, summary, strlen(summary));
139+ fputs("</a>", fp);
140+ }
141+ fputs("</td><td>", fp);
142+ if (author)
143+ xmlencode(fp, author->name, strlen(author->name));
144+ fputs("</td><td align=\"right\">", fp);
145+ printtime(fp, &author->when);
146+ fputs("</td><td align=\"right\">", fp);
147+ fprintf(fp, "%zu", nfiles);
148+ fputs("</td><td align=\"right\">", fp);
149+ fprintf(fp, "+%zu", nadd);
150+ fputs("</td><td align=\"right\">", fp);
151+ fprintf(fp, "-%zu", ndel);
152+ fputs("</td></tr>", fp);
153+
154+ printshowfile(commit);
155+
156+ git_diff_free(diff);
157+ git_commit_free(commit);
158
159 /* DEBUG */
160 i++;
161 if (i > 100)
162 break;
163 }
164+ fprintf(fp, "</tbody></table>");
165 git_revwalk_free(w);
166
167 return 0;
168@@ -348,7 +402,7 @@ writefiles(FILE *fp)
169 count = git_index_entrycount(index);
170 for (i = 0; i < count; i++) {
171 entry = git_index_get_byindex(index, i);
172- fprintf(fp, "name: %s, size: %lu, mode: %lu\n",
173+ fprintf(fp, "name: %s, size: %" PRIu64 ", mode: %u\n",
174 entry->path, entry->file_size, entry->mode);
175 }
176