the log_action
authorChristian Thaeter <ct@pipapo.org>
Tue, 15 Jan 2008 10:11:50 +0000 (11:11 +0100)
committerChristian Thaeter <ct@pipapo.org>
Tue, 15 Jan 2008 10:11:50 +0000 (11:11 +0100)
src/actions.c

index cbb67cc..0e4a169 100644 (file)
@@ -146,11 +146,169 @@ webgit_summary_action (struct webgit_query* query)
   Log page
 */
 static Html
-webgit_log_action (struct webgit_query* query)
+webgit_log_menu_action (struct webgit_query* query)
 {
-  
+  (void) query;
+  return html ("TODO: log sidebar");
+}
+
+
+static Html
+webgit_log_content_action (struct webgit_query* query)
+{
+  webgit_enter_repository (query);
+
+  struct rev_info rev;
+  const char* object;
+  if (query->object)
+    object = query->object;
+  else if (query->head)
+    object = query->head;
+  else
+    object = "HEAD";
+
+  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 ();
+
+  fprintf (stderr, "%s\n", query->object);
+
+  unsigned char sha1[20];
+  if (query->object)
+    get_sha1 (query->object, sha1);
 
-  return html("log");
+  int cnt = query->count;
+
+  struct commit *commit;
+  while ((commit = get_revision (&rev)))
+    {
+      if (query->object)
+        {
+          if (!hashcmp (sha1, commit->object.sha1))
+            {
+              /* found first commit to display */
+              free (query->object);
+              query->object = NULL;
+            }
+          else
+            /* not yet, fall through */
+            continue;
+        }
+
+      if (!cnt--)
+        {
+          /* 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;
+        }
+
+      struct tm tm;
+      webgit_commit_committer_date_parse (commit, &tm);
+
+      char pretty_date[256];
+      strftime (pretty_date, 255, "%c", &tm);
+
+      html_list_append (table,
+                        html (
+                              html (
+                                    html_tag ("tr"),
+                                    html(html_tag ("td"),
+                                         html_strndup (pretty_date, 254)
+                                         ),
+                                    html(html_tag ("td"),
+                                         webgit_object_link (query,
+                                                             query->repo,
+                                                             strlen (query->repo),
+                                                             sha1_to_hex (commit->object.sha1),
+                                                             40,
+                                                             NULL,
+                                                             webgit_header_parse (commit)
+                                                             )
+                                         )
+                                    ),
+                              html (
+                                    html_tag ("tr"),
+                                    html(html_tag ("td"),
+                                         webgit_email_link (
+                                                            webgit_commit_author_name_parse (commit),
+                                                            webgit_commit_author_email_parse (commit)
+                                                            )
+                                         ),
+                                    html (html_tag ("td"),
+                                         html(
+                                              "Diff ",
+                                              " ",
+                                              webgit_object_link (query,
+                                                                  query->repo,
+                                                                  strlen (query->repo),
+                                                                  webgit_commit_tree_parse (commit),
+                                                                  40,
+                                                                  NULL,
+                                                                  html ("Tree")
+                                                                  )
+                                              )
+                                          )
+                                    ),
+                              html (
+                                    html_tag ("tr"),
+                                    html(html_tag ("td", html_attr ("colspan", "2")),
+                                         html(html_tag ("pre"),
+                                              webgit_message_parse (commit)
+                                              ),
+                                         html(html_tag ("hr"))
+                                         )
+                                    )
+                              )
+                        );
+
+
+#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 ("table"), table), cont);
+}
+
+
+static Html
+webgit_log_action (struct webgit_query* query)
+{
+  return html(
+              html(html_tag("div"), webgit_log_menu_action (query)), html_nl (),
+              html(html_tag("div"), webgit_log_content_action (query)), html_nl ()
+              );
 }