changed provisonal css class for test1 to message-summary .. cehteh, perhaps this...
[webgit] / src / log.c
index 66238d3..679eac7 100644 (file)
--- a/src/log.c
+++ b/src/log.c
     cehtehs git web frontend
 
   Copyright (C)
-    2007,               Christian Thaeter <ct@pipapo.org>
+    2007, 2008,         Christian Thaeter <ct@pipapo.org>
 
-  This program is free software; you can redistribute it and/or
-  modify it under the terms of the GNU General Public License as
-  published by the Free Software Foundation; either version 2 of the
-  License, or (at your option) any later version.
+  This program is free software: you can redistribute it and/or modify
+  it under the terms of the GNU Affero General Public License as published by
+  the Free Software Foundation, either version 3 of the License, or
+  (at your option) any later version.
 
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-  GNU General Public License for more details.
+  GNU Affero General Public License for more details.
 
-  You should have received a copy of the GNU General Public License
-  along with this program; if not, write to the Free Software
-  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+  You should have received a copy of the GNU Affero General Public License
+  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 #include "log.h"
+#include "repo.h"
+#include "summary.h"
+#include "actions.h"
+#include "object.h"
+
+#define SHA1_HEADER <openssl/sha.h>
+#include "git/cache.h"
+#include "git/commit.h"
+#include "git/diff.h"
+#include "git/revision.h"
 
 Html
-ctgit_log_link (struct ctgit_query* query, struct ctgit_repo_info* n, const char* head, Html text)
+webgit_log_link (struct webgit_query* query,
+                 const char* repo,
+                 const char* head,
+                 const char* object, int object_len,
+                 int count,
+                 Html text)
 {
   return html (
                html_tag ("a",
-                         html_attr ("href", html_fmt ("%s?repo=%s&action=log&head=%s",
-                                                      query->request->script_name,
-                                                      n->name,
-                                                      head?head:"master")
+                         html_attr ("href", html(
+                                                 html_fmt ("%s?repo=%s&action=log",
+                                                           query->request->script_name,
+                                                           repo),
+                                                 head ? html_fmt("&head=%s", head)
+                                                 : html (),
+                                                 object ? html_fmt("&object=%.*s",
+                                                                   object_len, object)
+                                                 : html (),
+                                                 count > 0 ? html_fmt("&count=%d",
+                                                                      count)
+                                                 : html ()
+                                                 )
                                     )
                          ),
                text
                );
 }
 
+
+Html
+webgit_log_menu_action (struct webgit_repo_info* repo)
+{
+  return html (html_tag ("div"),
+               webgit_repo_logo (repo), "<br />",
+               // TODO:  ...., "<br />",
+               webgit_summary_link (repo->query, repo, html("Summary")), "<br />",
+               webgit_main_link (repo->query, html ("Main"))
+               );
+}
+
+
+Html
+webgit_log_table (struct webgit_query* query, const char* object, int count, int verbosity)
+{
+  struct rev_info rev;
+  const char* argv[] = {NULL, object, NULL};
+  int argc = 2;
+
+  init_revisions (&rev, NULL);
+  rev.verbose_header = 1;
+  rev.topo_order = 1;
+
+  setup_revisions (argc, argv, &rev, NULL);
+
+  prepare_revision_walk(&rev);
+
+  Html table = html_list ();
+  Html cont = html_list ();
+  int row = 0;
+
+  struct commit *commit;
+  while ((commit = get_revision (&rev)))
+    {
+      if (!count--)
+        {
+          /* displayed query->count lines, finish */
+          html_list_append (cont,
+                            webgit_log_link (
+                                             query,
+                                             query->repo,
+                                             query->head,
+                                             sha1_to_hex(commit->object.sha1), 40,
+                                             query->count_def,
+                                             html("More..."))
+                            );
+          free(commit->buffer);
+          commit->buffer = NULL;
+          free_commit_list(commit->parents);
+          commit->parents = NULL;
+          break;
+        }
+
+      /* TODO: check if commit is one of the heads and display that */
+
+      struct tm tm;
+      webgit_object_commit_committer_date_parse (commit, &tm);
+
+      char pretty_date[256];
+      strftime (pretty_date, 255, "%c", &tm);
+
+      ++row;
+
+      html_list_append (table,
+                        html (
+                              html_tag ("div",
+                                        html_attr ("id", "commit"),
+                                        html_attr ("class", (row & 1) ? "odd" : "even")
+                                        ),
+                              html(html_tag ("div",
+                                             html_attr ("class", "date")
+                                             ),
+                                   html_strndup (pretty_date, 254)
+                                   ),
+                              html(html_tag ("div",
+                                             html_attr ("class", "message-summary")
+                                             ),
+                                   webgit_object_link (query,
+                                                       query->repo,
+                                                       strlen (query->repo),
+                                                       sha1_to_hex (commit->object.sha1),
+                                                       40,
+                                                       NULL,
+                                                       NULL,
+                                                       webgit_object_commit_header_parse (commit)
+                                                       )
+                                   ),
+                              // TODO please refactor this if it's really silly
+                              (verbosity > 0) ?
+                              html (
+                                    html(html_tag ("div",
+                                                   html_attr ("class", "author")
+                                                   ),
+                                         webgit_email_link (
+                                                            webgit_object_commit_author_name_parse (commit),
+                                                            webgit_object_commit_author_email_parse (commit)
+                                                            )
+                                         ),
+                                    html (html_tag ("div",
+                                                    html_attr ("class", "action")
+                                                    ),
+                                          html(
+                                               "Diff ",
+                                               " ",
+                                               webgit_object_link (query,
+                                                                   query->repo,
+                                                                   strlen (query->repo),
+                                                                   webgit_object_commit_tree_parse (commit),
+                                                                   40,
+                                                                   NULL,
+                                                                   NULL,
+                                                                   html ("Tree")
+                                                                   )
+                                               )
+                                          )
+                                    )
+                              : html()
+                              ,
+
+                              (verbosity > 1) ?
+                              html (
+                                    html(html_tag ("div",
+                                                   html_attr ("class", "message")
+                                                   ),
+                                         html(html_tag ("pre"),
+                                              webgit_object_commit_message_parse (commit)
+                                              )
+                                         )
+                                    )
+                              : html()
+
+                              )
+                        );
+
+#if 0 /* traverse parents */
+      struct commit *parent;
+      while ((parent = pop_commit (&commit->parents)))
+        {
+        }
+#endif
+
+      free(commit->buffer);
+      commit->buffer = NULL;
+      free_commit_list(commit->parents);
+      commit->parents = NULL;
+    }
+
+  return html (html( html_tag ("div", html_attr ("id", "log")), table), cont);
+}
+
+
+Html
+webgit_log_content_action (struct webgit_repo_info* repo)
+{
+  struct webgit_query* query = repo->query;
+
+  const char* object;
+  if (query->object)
+    object = query->object;
+  else if (query->head)
+    object = query->head;
+  else
+    object = "HEAD";
+
+  return webgit_log_table (query, object, query->count, 2);
+}
+
+/*
+//      Local Variables:
+//      mode: C
+//      c-file-style: "gnu"
+//      indent-tabs-mode: nil
+//      End:
+*/