first object ui for commits
authorChristian Thaeter <ct@pipapo.org>
Wed, 2 Jan 2008 18:06:13 +0000 (19:06 +0100)
committerChristian Thaeter <ct@pipapo.org>
Wed, 2 Jan 2008 18:06:13 +0000 (19:06 +0100)
src/actions.c
src/object.c
src/object.h

index 953a94d..60b9298 100644 (file)
 
 #include "cwa.h"
 
+/* todo configure this */
+#define SHA1_HEADER <openssl/sha.h>
+#include "git/cache.h"
+
 #include <stdio.h>
 
 
@@ -111,7 +115,40 @@ ctgit_diff_action (struct ctgit_query* query)
 static Html
 ctgit_object_action (struct ctgit_query* query)
 {
-  return html("object");
+  LLIST_FOREACH (&query->repos, node)
+    {
+      struct ctgit_repo_info* ri = (struct ctgit_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 ctgit_object_commit_action (query, sha1);
+    case OBJ_TREE:
+      return ctgit_object_tree_action (query, sha1);
+    case OBJ_BLOB:
+      return html ("its a blob");
+
+      break;
+    case OBJ_TAG:
+      return html ("its a tag");
+
+      break;
+    default:
+      return html ("error: unknown object type");
+      break;
+    }
 }
 
 static Html
index 01767ca..84b8663 100644 (file)
 
 #include "object.h"
 
+#define SHA1_HEADER <openssl/sha.h>
+#include "git/git-compat-util.h"
+#include "git/object.h"
+
+
 Html
 ctgit_object_link (struct ctgit_query* query, struct ctgit_repo_info* n, const char* object, Html text)
 {
@@ -38,3 +43,243 @@ ctgit_object_link (struct ctgit_query* query, struct ctgit_repo_info* n, const c
 
 
 
+static Html
+ctgit_object_commit_menu_action (struct ctgit_query* query, unsigned char* sha1, void* buf, unsigned long size)
+{
+  return html ("TODO: commit-object sidebar");
+}
+
+static Html
+ctgit_object_commit_content_action (struct ctgit_query* query, unsigned char* sha1, void* buf, unsigned long size)
+{
+  Html tree = html_list ();
+  Html parents = html_list ();
+  Html author_text = html_list ();
+  Html author = html_list ();
+  Html committer = html_list ();
+
+  const char* author_beg = NULL;
+  const char* author_end = NULL;
+
+  const char* i = buf;
+  while (i && i < buf+size)
+    {
+      if (*i == '\n')
+        {
+          while (*i == '\n')
+            ++i;
+          break; /* message */
+        }
+      if (!strncmp (i, "tree ", 5))
+        {
+          html_list_append (tree, html (
+                                           "Tree: ",
+                                           html (
+                                                 html_tag ("a",
+                                                           html_attr ("href", html_fmt ("%s?repo=%s&object=%.40s",
+                                                                                        query->request->script_name,
+                                                                                        query->repo,
+                                                                                        i+5)
+                                                                      )
+                                                           ),
+                                                 html_fmt ("%.40s", i + 5)
+                                                 )
+                                           )
+                            );
+
+          (i = strchr (i, '\n')) && ++i;
+          continue;
+        }
+      else if (!strncmp (i, "parent ", 7))
+        {
+          html_list_append (parents, html (
+                                           "Parent: ",
+                                           html (
+                                                 html_tag ("a",
+                                                           html_attr ("href", html_fmt ("%s?repo=%s&object=%.40s",
+                                                                                        query->request->script_name,
+                                                                                        query->repo,
+                                                                                        i+7)
+                                                                      )
+                                                           ),
+                                                 html_fmt ("%.40s", i + 7)
+                                                 )
+                                           )
+                            );
+          (i = strchr (i, '\n')) && ++i;
+          continue;
+        }
+      else if (!strncmp (i, "author ", 7))
+        {
+          char* email_beg = strchr (i, '<');
+          char* email_end = strchr (email_beg, '>');
+
+          author_beg = i+7;
+          author_end = strchr (author_beg, '\n');
+
+          Html name = html_strndup (i+7, email_beg - i - 8);
+          Html email = html_strndup (email_beg + 1, email_end - email_beg - 1);
+
+          struct tm tm;
+          strptime (email_end + 2, "%s %Z", &tm);
+          char pretty_date[256];
+          strftime (pretty_date, 255, "%c", &tm);
+
+          html_list_append (author_text, "Author");
+
+          html_list_append (author, html (
+                                          html ( author_text ), /*BUG: libcwa bug, must be wraped in html()*/
+                                          html (
+                                                html_tag("a",
+                                                         html_attr ("href",
+                                                                    html ("mailto:", email))
+                                                         ),
+                                                name
+                                                ),
+                                          html_strndup (pretty_date, 255)
+                                          )
+                            );
+          (i = strchr (i, '\n')) && ++i;
+          continue;
+        }
+      else if (!strncmp (i, "committer ", 10))
+        {
+          char* email_beg = strchr (i, '<');
+          char* email_end = strchr (email_beg, '>');
+
+          if (author_beg && author_end && strncmp (i + 10, author_beg, author_end - author_beg))
+            {
+              Html name = html_strndup (i+10, email_beg - i - 11);
+              Html email = html_strndup (email_beg + 1, email_end - email_beg - 1);
+
+              struct tm tm;
+              strptime (email_end + 2, "%s %Z", &tm);
+              char pretty_date[256];
+              strftime (pretty_date, 255, "%c", &tm);
+
+              html_list_append (committer, html ("Committer: ",
+                                                 html(
+                                                      html_tag("a",
+                                                               html_attr("href",
+                                                                         html ("mailto:", email))
+                                                               ),
+                                                      name
+                                                      ),
+                                                 html_strndup (pretty_date, 255)
+                                                 )
+                                );
+            }
+          else
+            html_list_append (author_text, "and Committer");
+
+          (i = strchr (i, '\n')) && ++i;
+          continue;
+        }
+      ++i;
+    }
+
+  html_list_append (author_text, ": ");
+
+
+
+  Html headline = html_list ();
+  Html message = html_list ();
+
+  if (i)
+    {
+      const char* message_beg = strchr (i, '\n');
+
+      if (message_beg)
+        {
+          html_list_append (headline,
+                            html_strndup (i, message_beg - i)
+                            );
+
+          while (*message_beg == '\n')
+            ++message_beg;
+
+          html_list_append (message,
+                            html_strndup (message_beg, SIZE_MAX)
+                            );
+        }
+      else
+        {
+          html_list_append (headline,
+                            html_strndup (i, SIZE_MAX)
+                            );
+          html_list_append (message,
+                            html_strndup (i, SIZE_MAX)
+                            );
+        }
+    }
+
+  /* diffstat */
+
+
+  return html (
+               html (html_tag ("h3"), headline),
+               html (html_tag ("div"), tree), html_nl (),
+               html (html_tag ("div"), parents), html_nl (),
+               html (html_tag ("div"), author), html_nl (),
+               html (html_tag ("div"), committer), html_nl (),
+               html (html_tag ("pre"), message)
+               );
+}
+
+Html
+ctgit_object_commit_action (struct ctgit_query* query, unsigned char* sha1)
+{
+  void* buf;
+  unsigned long size;
+
+  buf = read_object_with_reference (sha1, "commit", &size, NULL);
+
+  return html(
+              html(html_tag("div"), ctgit_object_commit_menu_action (query, sha1, buf, size)), html_nl (),
+              html(html_tag("div"), ctgit_object_commit_content_action (query, sha1, buf, size)), html_nl ()
+              );
+}
+
+
+
+
+
+
+
+
+
+
+
+
+static Html
+ctgit_object_tree_menu_action (struct ctgit_query* query, unsigned char* sha1, void* buf, unsigned long size)
+{
+  return html ("TODO: tree-object sidebar");
+}
+
+static Html
+ctgit_object_tree_content_action (struct ctgit_query* query, unsigned char* sha1, void* buf, unsigned long size)
+{
+
+  return html_fmt ("tree content %s", buf);
+}
+
+Html
+ctgit_object_tree_action (struct ctgit_query* query, unsigned char* sha1)
+{
+  unsigned long size;
+  void* buf;
+  buf = read_object_with_reference (sha1, "tree", &size, NULL);
+
+  return html(
+              html(html_tag("div"), ctgit_object_tree_menu_action (query, sha1, buf, size)), html_nl (),
+              html(html_tag("div"), ctgit_object_tree_content_action (query, sha1, buf, size)), html_nl ()
+              );
+}
+
+
+
+
+/*pretty printer for sourcecode*/
+//Html
+//ctgit_object_blob_dispatch (struct ctgit_query* query, const char *sha1);
index 082b836..1370f65 100644 (file)
 
 #include "ctgit.h"
 
+
+
 Html
 ctgit_object_link (struct ctgit_query* query, struct ctgit_repo_info* n, const char* object, Html text);
 
+Html
+ctgit_object_commit_action (struct ctgit_query* query, unsigned char* sha1);
+
+Html
+ctgit_object_tree_action (struct ctgit_query* query, unsigned char* sha1);
+
+
 #endif