putting all the commit details into a commit div
[webgit] / src / log.c
1 /*
2     cehtehs git web frontend
3
4   Copyright (C)
5     2007, 2008,         Christian Thaeter <ct@pipapo.org>
6
7   This program is free software: you can redistribute it and/or modify
8   it under the terms of the GNU Affero General Public License as published by
9   the Free Software Foundation, either version 3 of the License, or
10   (at your option) any later version.
11
12   This program is distributed in the hope that it will be useful,
13   but WITHOUT ANY WARRANTY; without even the implied warranty of
14   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   GNU Affero General Public License for more details.
16
17   You should have received a copy of the GNU Affero General Public License
18   along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #include "log.h"
22 #include "repo.h"
23 #include "summary.h"
24 #include "actions.h"
25 #include "object.h"
26
27 #define SHA1_HEADER <openssl/sha.h>
28 #include "git/cache.h"
29 #include "git/commit.h"
30 #include "git/diff.h"
31 #include "git/revision.h"
32
33 Html
34 webgit_log_link (struct webgit_query* query,
35                  const char* repo,
36                  const char* head,
37                  const char* object, int object_len,
38                  int count,
39                  Html text)
40 {
41   return html (
42                html_tag ("a",
43                          html_attr ("href", html(
44                                                  html_fmt ("%s?repo=%s&action=log",
45                                                            query->request->script_name,
46                                                            repo),
47                                                  head ? html_fmt("&head=%s", head)
48                                                  : html (),
49                                                  object ? html_fmt("&object=%.*s",
50                                                                    object_len, object)
51                                                  : html (),
52                                                  count > 0 ? html_fmt("&count=%d",
53                                                                       count)
54                                                  : html ()
55                                                  )
56                                     )
57                          ),
58                text
59                );
60 }
61
62
63 Html
64 webgit_log_menu_action (struct webgit_repo_info* repo)
65 {
66   return html (html_tag ("div"),
67                webgit_repo_logo (repo), "<br />",
68                // TODO:  ...., "<br />",
69                webgit_summary_link (repo->query, repo, html("Summary")), "<br />",
70                webgit_main_link (repo->query, html ("Main"))
71                );
72 }
73
74
75 Html
76 webgit_log_table (struct webgit_query* query, const char* object, int count, int verbosity)
77 {
78   struct rev_info rev;
79   const char* argv[] = {NULL, object, NULL};
80   int argc = 2;
81
82   init_revisions (&rev, NULL);
83   rev.verbose_header = 1;
84   rev.topo_order = 1;
85
86   setup_revisions (argc, argv, &rev, NULL);
87
88   prepare_revision_walk(&rev);
89
90   Html table = html_list ();
91   Html cont = html_list ();
92   int row = 0;
93
94   struct commit *commit;
95   while ((commit = get_revision (&rev)))
96     {
97       if (!count--)
98         {
99           /* displayed query->count lines, finish */
100           html_list_append (cont,
101                             webgit_log_link (
102                                              query,
103                                              query->repo,
104                                              query->head,
105                                              sha1_to_hex(commit->object.sha1), 40,
106                                              query->count_def,
107                                              html("More..."))
108                             );
109           free(commit->buffer);
110           commit->buffer = NULL;
111           free_commit_list(commit->parents);
112           commit->parents = NULL;
113           break;
114         }
115
116       /* TODO: check if commit is one of the heads and display that */
117
118       struct tm tm;
119       webgit_object_commit_committer_date_parse (commit, &tm);
120
121       char pretty_date[256];
122       strftime (pretty_date, 255, "%c", &tm);
123
124       ++row;
125
126       html_list_append (table,
127                         html (
128                               html_tag ("div",
129                                         html_attr ("id", "commit"),
130                                         html_attr ("class", (row & 1) ? "odd" : "even")
131                                         ),
132                               html(html_tag ("div",
133                                              html_attr ("class", "date")
134                                              ),
135                                    html_strndup (pretty_date, 254)
136                                    ),
137                               html(html_tag ("div",
138                                              html_attr ("class", "test1")
139                                              ),
140                                    webgit_object_link (query,
141                                                        query->repo,
142                                                        strlen (query->repo),
143                                                        sha1_to_hex (commit->object.sha1),
144                                                        40,
145                                                        NULL,
146                                                        NULL,
147                                                        webgit_object_commit_header_parse (commit)
148                                                        )
149                                    )
150                               )
151                         );
152                               /*                              if (verbosity > 0)
153                               ,
154                                 html (
155                                       html(html_tag ("div",
156                                                      html_attr ("class", "author")
157                                                      ),
158                                            webgit_email_link (
159                                                               webgit_object_commit_author_name_parse (commit),
160                                                               webgit_object_commit_author_email_parse (commit)
161                                                               )
162                                            ),
163                                       html (html_tag ("div",
164                                                       html_attr ("class", "action")
165                                                       ),
166                                             html(
167                                                  "Diff ",
168                                                  " ",
169                                                  webgit_object_link (query,
170                                                                      query->repo,
171                                                                      strlen (query->repo),
172                                                                      webgit_object_commit_tree_parse (commit),
173                                                                      40,
174                                                                      NULL,
175                                                                      NULL,
176                                                                      html ("Tree")
177                                                                      )
178                                                  )
179                                             )
180                                       )
181                                   if (verbosity > 1)
182                                   ,
183                                     html (
184                                           html(html_tag ("div",
185                                                          html_attr ("class", "message")
186                                                          ),
187                                                html(html_tag ("pre"),
188                                                     webgit_object_commit_message_parse (commit)
189                                                     )
190                                                )
191                                                )*/
192                               /*                                          )
193                         );
194                               */
195
196       /*        html_list_append (table,
197                           );
198
199
200         html_list_append (table,
201                           );
202       */
203       ,
204 #if 0 /* traverse parents */
205       struct commit *parent;
206       while ((parent = pop_commit (&commit->parents)))
207         {
208         }
209 #endif
210
211       free(commit->buffer);
212       commit->buffer = NULL;
213       free_commit_list(commit->parents);
214       commit->parents = NULL;
215     }
216
217   return html (html( html_tag ("div", html_attr ("id", "log")), table), cont);
218 }
219
220
221 Html
222 webgit_log_content_action (struct webgit_repo_info* repo)
223 {
224   struct webgit_query* query = repo->query;
225
226   const char* object;
227   if (query->object)
228     object = query->object;
229   else if (query->head)
230     object = query->head;
231   else
232     object = "HEAD";
233
234   return webgit_log_table (query, object, query->count, 2);
235 }
236
237 /*
238 //      Local Variables:
239 //      mode: C
240 //      c-file-style: "gnu"
241 //      indent-tabs-mode: nil
242 //      End:
243 */