support for last_committer and last_author when scanning repos
[webgit] / src / actions.c
index c4a13537674be99ba6a9e0808f9e6ee30416f730..cb2a1ba6d75f5c14cec1410076f751eb62249860 100644 (file)
 
 #include "cwa.h"
 
+/* todo configure this */
+#define SHA1_HEADER <openssl/sha.h>
+#include "git/cache.h"
+
 #include <stdio.h>
 
 
 static Html
-ctgit_main_menu_action (struct ctgit_query* query)
+webgit_main_menu_action (struct webgit_query* query)
 {
   return html ("TODO: main menu sidebar");
 }
 
 static Html
-ctgit_main_content_action (struct ctgit_query* query)
+webgit_main_content_action (struct webgit_query* query)
 {
   Html table = html_list ();
 
@@ -47,6 +51,8 @@ ctgit_main_content_action (struct ctgit_query* query)
                                html(html_tag ("th"),"Description"),
                                html(html_tag ("th"),"Owner"),
                                html(html_tag ("th"),"Last Change"),
+                               html(html_tag ("th"),"Author"),
+                               html(html_tag ("th"),"Committer"),
                                html(html_tag ("th"),"Action")
                                ),
                           html_nl()
@@ -55,20 +61,34 @@ ctgit_main_content_action (struct ctgit_query* query)
 
   LLIST_FOREACH (&query->repos, node)
     {
-      struct ctgit_repo_info* n = (struct ctgit_repo_info*)node;
+      struct webgit_repo_info* n = (struct webgit_repo_info*)node;
       html_list_append (table, html (
                                      html_tag ("tr"),
-                                     html(html_tag ("td"), ctgit_summary_link (query, n, html (n->name))),
+                                     html(html_tag ("td"), webgit_summary_link (query, n, html (n->name))),
                                      html(html_tag ("td"), n->description),
                                      html(html_tag ("td"), n->owner),
                                      html(html_tag ("td"),
-                                          ctgit_object_link (query, n, "TODO: get last commit", ctgit_pretty_age (n->age))
+                                          webgit_object_link (query,
+                                                              n->name, strlen(n->name),
+                                                              n->last_commit, 40,
+                                                              webgit_pretty_age (n->age))
+                                          ),
+                                     html(html_tag ("td"),
+                                          webgit_email_link (n->last_author_name, n->last_author_email)
+                                          ),
+                                     html(html_tag ("td"),
+                                          webgit_email_link (n->last_committer_name, n->last_committer_email)
                                           ),
                                      html(html_tag ("td"),
                                           html(
-                                               ctgit_log_link (query, n, html("Log")),
+                                               webgit_log_link (query, n, n->last_head, html("Log")),
                                                " ",
-                                               ctgit_object_link (query, n, "TODO: get last tree", html("Tree"))
+                                               //webgit_diff_link (query, n, n->last_head, html("Diff")),
+                                               //" ",
+                                               webgit_object_link (query,
+                                                                  n->name, strlen(n->name),
+                                                                  n->last_tree, 40,
+                                                                  html("Tree"))
                                                )
                                           )
                                      ),
@@ -80,76 +100,107 @@ ctgit_main_content_action (struct ctgit_query* query)
 }
 
 static Html
-ctgit_main_action (struct ctgit_query* query)
+webgit_main_action (struct webgit_query* query)
 {
   return html(
-              html(html_tag("div"), ctgit_main_menu_action (query)), html_nl (),
-              html(html_tag("div"), ctgit_main_content_action (query)), html_nl ()
+              html(html_tag("div"), webgit_main_menu_action (query)), html_nl (),
+              html(html_tag("div"), webgit_main_content_action (query)), html_nl ()
               );
 }
 
 static Html
-ctgit_summary_action (struct ctgit_query* query)
+webgit_summary_action (struct webgit_query* query)
 {
   return html("summary");
 }
 
 static Html
-ctgit_log_action (struct ctgit_query* query)
+webgit_log_action (struct webgit_query* query)
 {
   return html("log");
 }
 
 static Html
-ctgit_diff_action (struct ctgit_query* query)
+webgit_diff_action (struct webgit_query* query)
 {
   return html("diff");
 }
 
 static Html
-ctgit_object_action (struct ctgit_query* query)
+webgit_object_action (struct webgit_query* query)
 {
-  return html("object");
+  LLIST_FOREACH (&query->repos, node)
+    {
+      struct webgit_repo_info* ri = (struct webgit_repo_info*) node;
+      if (!strcmp (ri->name, query->repo))
+        {
+          chdir (ri->path);
+          break;
+        }
+    }
+
+  setup_git_directory ();
+
+  unsigned char sha1[20];
+  if (get_sha1(query->object, sha1))
+    return html("error: unknown object");
+
+  switch (sha1_object_info(sha1, NULL))
+    {
+    case OBJ_COMMIT:
+      return webgit_object_commit_action (query, sha1);
+    case OBJ_TREE:
+      return webgit_object_tree_action (query, sha1);
+    case OBJ_BLOB:
+      return webgit_object_blob_action (query, sha1);
+    case OBJ_TAG:
+      return html ("its a tag");
+
+      break;
+    default:
+      return html ("error: unknown object type");
+      break;
+    }
 }
 
 static Html
-ctgit_raw_action (struct ctgit_query* query)
+webgit_raw_action (struct webgit_query* query)
 {
   return html("raw");
 }
 
 static Html
-ctgit_tag_action (struct ctgit_query* query)
+webgit_tag_action (struct webgit_query* query)
 {
   return html("tag");
 }
 
 static Html
-ctgit_edit_action (struct ctgit_query* query)
+webgit_edit_action (struct webgit_query* query)
 {
   return html("edit");
 }
 
 static Html
-ctgit_commit_action (struct ctgit_query* query)
+webgit_commit_action (struct webgit_query* query)
 {
   return html("commit");
 }
 
 
 Html
-ctgit_action_dispatch (struct ctgit_query* query)
+webgit_action_dispatch (struct webgit_query* query)
 {
-#define CTGIT_ACTION(name, _)                   \
+#define WEBGIT_ACTION(name, _)                   \
 {                                               \
  #name,                                         \
ctgit_##name##_action,                         \
webgit_##name##_action,                         \
 },
   struct action_table{
     char* name;
-    Html (*cb)(struct ctgit_query* query);
-  } cmds[] = {CTGIT_ACTIONS {"", NULL}};
-#undef CTGIT_ACTION
+    Html (*cb)(struct webgit_query* query);
+  } cmds[] = {WEBGIT_ACTIONS {"", NULL}};
+#undef WEBGIT_ACTION
 
   for (struct action_table* j = cmds; j->cb; ++j)
     {