urmoms-index: kill some lines
1 files changed, 9 insertions(+), 95 deletions(-) | |||
---|---|---|---|
M | urmoms-index.c | +9 | -95 |
1@@ -13,28 +13,6 @@
2 #include "config.h"
3 #include "git2.h"
4
5-struct commitinfo {
6- const git_oid *id;
7-
8- char oid[GIT_OID_HEXSZ + 1];
9- char parentoid[GIT_OID_HEXSZ + 1];
10-
11- const git_signature *author;
12- const char *summary;
13- const char *msg;
14-
15- git_diff_stats *stats;
16- git_diff *diff;
17- git_commit *commit;
18- git_commit *parent;
19- git_tree *commit_tree;
20- git_tree *parent_tree;
21-
22- size_t addcount;
23- size_t delcount;
24- size_t filecount;
25-};
26-
27 static git_repository *repo;
28
29 static const char *relpath = "";
30@@ -44,73 +22,6 @@ static char description[255] = "Repositories";
31 static char name[255];
32 static char owner[255];
33
34-void
35-commitinfo_free(struct commitinfo *ci)
36-{
37- if (!ci)
38- return;
39-
40- git_diff_stats_free(ci->stats);
41- git_diff_free(ci->diff);
42- git_tree_free(ci->commit_tree);
43- git_tree_free(ci->parent_tree);
44- git_commit_free(ci->commit);
45-}
46-
47-struct commitinfo *
48-commitinfo_getbyoid(const git_oid *id)
49-{
50- struct commitinfo *ci;
51- git_diff_options opts;
52- int error;
53-
54- if (!(ci = calloc(1, sizeof(struct commitinfo))))
55- err(1, "calloc");
56-
57- ci->id = id;
58- if (git_commit_lookup(&(ci->commit), repo, id))
59- goto err;
60-
61- /* TODO: show tags when commit has it */
62- git_oid_tostr(ci->oid, sizeof(ci->oid), git_commit_id(ci->commit));
63- git_oid_tostr(ci->parentoid, sizeof(ci->parentoid), git_commit_parent_id(ci->commit, 0));
64-
65- ci->author = git_commit_author(ci->commit);
66- ci->summary = git_commit_summary(ci->commit);
67- ci->msg = git_commit_message(ci->commit);
68-
69- if ((error = git_commit_tree(&(ci->commit_tree), ci->commit)))
70- goto err; /* TODO: handle error */
71- if (!(error = git_commit_parent(&(ci->parent), ci->commit, 0))) {
72- if ((error = git_commit_tree(&(ci->parent_tree), ci->parent)))
73- goto err;
74- } else {
75- ci->parent = NULL;
76- ci->parent_tree = NULL;
77- }
78-
79- git_diff_init_options(&opts, GIT_DIFF_OPTIONS_VERSION);
80- opts.flags |= GIT_DIFF_DISABLE_PATHSPEC_MATCH;
81- if ((error = git_diff_tree_to_tree(&(ci->diff), repo, ci->parent_tree, ci->commit_tree, &opts)))
82- goto err;
83- if (git_diff_get_stats(&(ci->stats), ci->diff))
84- goto err;
85-
86- ci->addcount = git_diff_stats_insertions(ci->stats);
87- ci->delcount = git_diff_stats_deletions(ci->stats);
88- ci->filecount = git_diff_stats_files_changed(ci->stats);
89-
90- /* TODO: show tag when commit has it */
91-
92- return ci;
93-
94-err:
95- commitinfo_free(ci);
96- free(ci);
97-
98- return NULL;
99-}
100-
101 FILE *
102 efopen(const char *name, const char *flags)
103 {
104@@ -211,7 +122,8 @@ writefooter(FILE *fp)
105 int
106 writelog(FILE *fp)
107 {
108- struct commitinfo *ci;
109+ git_commit *commit = NULL;
110+ const git_signature *author;
111 git_revwalk *w = NULL;
112 git_oid id;
113 int ret = 0;
114@@ -222,11 +134,13 @@ writelog(FILE *fp)
115 git_revwalk_simplify_first_parent(w);
116
117 if (git_revwalk_next(&id, w) ||
118- !(ci = commitinfo_getbyoid(&id))) {
119+ git_commit_lookup(&commit, repo, &id)) {
120 ret = -1;
121 goto err;
122 }
123
124+ author = git_commit_author(commit);
125+
126 fputs("<tr><td><a href=\"", fp);
127 xmlencode(fp, name, strlen(name));
128 fputs("/log.html\">", fp);
129@@ -236,10 +150,11 @@ writelog(FILE *fp)
130 fputs("</td><td>", fp);
131 xmlencode(fp, owner, strlen(owner));
132 fputs("</td><td>", fp);
133- if (ci->author)
134- printtimeshort(fp, &(ci->author->when));
135+ if (author)
136+ printtimeshort(fp, &(author->when));
137 fputs("</td></tr>", fp);
138
139+ git_commit_free(commit);
140 err:
141 git_revwalk_free(w);
142
143@@ -252,8 +167,7 @@ main(int argc, char *argv[])
144 const git_error *e = NULL;
145 FILE *fp;
146 char path[PATH_MAX], *p;
147- int status;
148- size_t i;
149+ int i, status;
150
151 if (argc < 2) {
152 fprintf(stderr, "%s [repodir...]\n", argv[0]);