webgit_tree_action() dereferences an treeish to the tree object
authorChristian Thaeter <ct@pipapo.org>
Tue, 8 Jan 2008 00:16:54 +0000 (01:16 +0100)
committerChristian Thaeter <ct@pipapo.org>
Tue, 8 Jan 2008 00:16:54 +0000 (01:16 +0100)
This is used for seamless module integration, a commit sha1 (module)
suffice to jump right to the tree of a submodule

src/actions.c
src/actions.h
src/object.c
src/query.c
src/webgit.c
src/webgit.h

index cb2a1ba..f3ff404 100644 (file)
@@ -148,7 +148,9 @@ webgit_object_action (struct webgit_query* query)
   switch (sha1_object_info(sha1, NULL))
     {
     case OBJ_COMMIT:
-      return webgit_object_commit_action (query, sha1);
+      if (!query->deref_to_tree)
+        return webgit_object_commit_action (query, sha1);
+      /* else fallthrough */
     case OBJ_TREE:
       return webgit_object_tree_action (query, sha1);
     case OBJ_BLOB:
@@ -163,6 +165,18 @@ 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);
+}
+
+
 static Html
 webgit_raw_action (struct webgit_query* query)
 {
index 6275e6e..52e9c6a 100644 (file)
 /*
   Pages presented to the user and other main actions
 */
-#define WEBGIT_ACTIONS                                           \
- WEBGIT_ACTION(main, "Display a list of available repositories") \
- WEBGIT_ACTION(summary, "Show an overview page of a repository") \
- WEBGIT_ACTION(log, "Browse the logs")                           \
- WEBGIT_ACTION(diff, "Show the diff between two objects")        \
- WEBGIT_ACTION(object, "Show an object, pretty format")          \
- WEBGIT_ACTION(raw, "Show an object, raw format")                \
- WEBGIT_ACTION(tag, "Show and manage tags")                      \
- WEBGIT_ACTION(edit, "Edit and object")                          \
+#define WEBGIT_ACTIONS                                                  \
+ WEBGIT_ACTION(main, "Display a list of available repositories")        \
+ WEBGIT_ACTION(summary, "Show an overview page of a repository")        \
+ WEBGIT_ACTION(log, "Browse the logs")                                  \
+ WEBGIT_ACTION(diff, "Show the diff between two objects")               \
+ WEBGIT_ACTION(object, "Show an object, pretty format")                 \
+ WEBGIT_ACTION(tree, "Show object derefed to tree, pretty format")      \
+ WEBGIT_ACTION(raw, "Show an object, raw format")                       \
+ WEBGIT_ACTION(tag, "Show and manage tags")                             \
+ WEBGIT_ACTION(edit, "Edit and object")                                 \
  WEBGIT_ACTION(commit, "Commit pending edits")
 
 Html
index f237515..d61b943 100644 (file)
@@ -271,14 +271,14 @@ webgit_html_tree (const unsigned char *sha1, const char *base, int baselen,
                                                     html (html_tag ("td"), pretty_mode (mode)),
                                                     html (html_tag ("td"),
                                                           webgit_repo_link (query_in_flight,
-                                                                           query_in_flight->repo,
-                                                                           strlen (query_in_flight->repo),
-                                                                           pathname, strlen (pathname),
-                                                                           NULL, 0,
-                                                                           "summary",
-                                                                           html_strndup (pathname, SIZE_MAX))
+                                                                            query_in_flight->repo,
+                                                                            strlen (query_in_flight->repo),
+                                                                            pathname, strlen (pathname),
+                                                                            sha1_to_hex (sha1), 40,
+                                                                            "tree",
+                                                                            html_strndup (pathname, SIZE_MAX))
                                                           ),
-                                                    html (html_tag ("td"), "history")
+                                                    html (html_tag ("td"), "history summary")
                                                     ),
                                               html_nl ()
                                               )
index dbe6f34..55b3b70 100644 (file)
@@ -34,6 +34,9 @@ webgit_query_init (struct webgit_query* q)
   q->request = NULL;
   q->now = time (NULL);
 
+  q->deref_to_tree = 0;
+  q->content_type = "text/html";
+
   q->repo = NULL;
   q->action = NULL;
   q->object = NULL;
index 40b2323..296954d 100644 (file)
@@ -135,7 +135,7 @@ main (int argc, char**argv)
               html_httpheader(
                               html_httpfield(
                                              "Content-type",
-                                             "text/html",
+                                             query.content_type,
                                              html_attr("charset", "UTF-8")
                                              )//,
                               //html_httpfield("Last-Modified", cgit_page.modified),
index 5a76be7..99d3354 100644 (file)
@@ -33,6 +33,10 @@ struct webgit_query
   Cgi request;
   time_t now;
 
+  int deref_to_tree;
+
+  const char* content_type;
+
   /* confiuration parameters */
   //int cache_read;
   //int cache_write;