remove 'deref_to_tree', not needed anymore
[webgit] / src / actions.c
index 19ada57..fa9d754 100644 (file)
 #include "object.h"
 #include "log.h"
 #include "repo.h"
-#include "age.h"
+#include "date.h"
 #include "branch.h"
 #include "tag.h"
 #include "account.h"
+#include "edit.h"
 
 #include "llist.h"
 #include <cwa.h>
@@ -128,12 +129,10 @@ webgit_main_content_action (struct webgit_query* query)
                                          html(html_tag ("td"), n->description),
                                          html(html_tag ("td"), n->owner),
                                          html(html_tag ("td"),
-                                              webgit_object_link (query,
-                                                                  n->name, strlen(n->name),
-                                                                  n->last_commit, 40,
-                                                                  NULL,
-                                                                  NULL,
-                                                                  webgit_pretty_age (n->age))
+                                              webgit_object_link (query, webgit_pretty_age (n->age),
+                                                                  "repo", n->name,
+                                                                  "ref", n->last_head,
+                                                                  "commit", n->last_commit)
                                               ),
                                          html(html_tag ("td"),
                                               webgit_email_link (
@@ -160,12 +159,12 @@ webgit_main_content_action (struct webgit_query* query)
                                                    "Diff ",
                                                    //webgit_diff_link (query, n, n->last_head, html("Diff")),
                                                    //" ",
-                                                   webgit_object_link (query,
-                                                                       n->name, strlen(n->name),
-                                                                       n->last_tree, 40,
-                                                                       NULL,
-                                                                       NULL,
-                                                                       html("Tree"))
+                                                   webgit_object_link (query, html("Tree"),
+                                                                       "repo", n->name,
+                                                                       "ref", n->last_head,
+                                                                       "commit", n->last_commit,
+                                                                       "path", ""
+                                                                       )
                                                    )
                                               )
                                          ),
@@ -174,7 +173,7 @@ webgit_main_content_action (struct webgit_query* query)
         }
     }
 
-  return html (html_tag ("table", html_attr ("id", "summary")), table);
+  return html (html_tag ("table", html_attr ("id", "summary"), html_attr ("class", "sortable"), html_attr ("cellpadding", "0"), html_attr ("cellspacing", "0")), table);
 }
 
 static Html
@@ -242,12 +241,10 @@ webgit_summary_content_action (struct webgit_repo_info* repo)
                           html(
                                html_tag ("div"),
                                "Last change: ",
-                               webgit_object_link (repo->query,
-                                                   repo->name, strlen(repo->name),
-                                                   repo->last_commit, 40,
-                                                   NULL,
-                                                   NULL,
-                                                   webgit_pretty_age (repo->age)),
+                               webgit_object_link (repo->query, webgit_pretty_age (repo->age),
+                                                   "repo", repo->name,
+                                                   "ref", repo->last_head,
+                                                   "commit", repo->last_commit),
                                " in branch ",
                                 webgit_log_link (repo->query,
                                                  repo->name,
@@ -269,7 +266,7 @@ webgit_summary_content_action (struct webgit_repo_info* repo)
                                                  html ("Log of branch '", repo->last_head, "'")
                                                  )
                                 ),
-                          webgit_log_table (repo->query, repo->last_head, 5 /*TODO: config this*/, 0))
+                          webgit_log_table (repo->query, repo->last_head, repo->last_head, 5 /*TODO: config this*/, 0))
                     );
 
 
@@ -297,7 +294,6 @@ webgit_summary_content_action (struct webgit_repo_info* repo)
                           )
                     );
 
-
   return content;
 }
 
@@ -356,6 +352,7 @@ static Html
 webgit_object_action (struct webgit_query* query)
 {
   struct webgit_repo_info* repo = webgit_repo_enter (query);
+  webgit_object_deduce (query);
 
   unsigned char sha1[20];
   if (get_sha1 (query->object, sha1))
@@ -364,9 +361,7 @@ webgit_object_action (struct webgit_query* query)
   switch (sha1_object_info(sha1, NULL))
     {
     case OBJ_COMMIT:
-      if (!query->deref_to_tree)
-        return webgit_object_commit_action (repo, sha1);
-      /* else fallthrough */
+      return webgit_object_commit_action (repo, sha1);
     case OBJ_TREE:
       return webgit_object_tree_action (repo, sha1);
     case OBJ_BLOB:
@@ -382,17 +377,6 @@ webgit_object_action (struct webgit_query* query)
 }
 
 
-/*
-  treeish dereferenced to tree
-*/
-static Html
-webgit_tree_action (struct webgit_query* query)
-{
-  query->deref_to_tree = 1;
-  return webgit_object_action (query);
-}
-
-
 /*
   spew out raw data
 */
@@ -400,6 +384,7 @@ static Html
 webgit_raw_action (struct webgit_query* query)
 {
   webgit_repo_enter (query);
+  webgit_object_deduce (query);
 
   unsigned char sha1[20];
   if (get_sha1 (query->object, sha1))
@@ -579,8 +564,26 @@ webgit_account_action (struct webgit_query* query)
 static Html
 webgit_edit_action (struct webgit_query* query)
 {
-  (void) query;
-  return html("edit");
+  struct webgit_repo_info* repo = webgit_repo_enter (query);
+  webgit_object_deduce (query);
+
+  unsigned char sha1[20];
+  if (get_sha1 (query->object, sha1))
+    return html("error: unknown object");
+
+  switch (sha1_object_info(sha1, NULL))
+    {
+    case OBJ_BLOB:
+      return webgit_edit_blob_action (repo, sha1);
+      //case OBJ_COMMIT:
+      //case OBJ_TREE:
+      //case OBJ_TAG:
+
+      break;
+    default:
+      return html ("error: unknown object type");
+      break;
+    }
 }