refactor ctgit_object_link to be more flexible
authorChristian Thaeter <ct@pipapo.org>
Wed, 2 Jan 2008 21:26:30 +0000 (22:26 +0100)
committerChristian Thaeter <ct@pipapo.org>
Wed, 2 Jan 2008 21:26:30 +0000 (22:26 +0100)
src/actions.c
src/object.c
src/object.h

index 60b9298..434adb9 100644 (file)
@@ -66,7 +66,10 @@ ctgit_main_content_action (struct ctgit_query* query)
                                      html(html_tag ("td"), n->description),
                                      html(html_tag ("td"), n->owner),
                                      html(html_tag ("td"),
-                                          ctgit_object_link (query, n, n->last_commit, ctgit_pretty_age (n->age))
+                                          ctgit_object_link (query,
+                                                             n->name, strlen(n->name),
+                                                             n->last_commit, 40,
+                                                             ctgit_pretty_age (n->age))
                                           ),
                                      html(html_tag ("td"),
                                           html(
@@ -74,7 +77,10 @@ ctgit_main_content_action (struct ctgit_query* query)
                                                " ",
                                                //ctgit_diff_link (query, n, n->last_head, html("Diff")),
                                                //" ",
-                                               ctgit_object_link (query, n, n->last_tree, html("Tree"))
+                                               ctgit_object_link (query,
+                                                                  n->name, strlen(n->name),
+                                                                  n->last_tree, 40,
+                                                                  html("Tree"))
                                                )
                                           )
                                      ),
index 84b8663..4d3597e 100644 (file)
 
 
 Html
-ctgit_object_link (struct ctgit_query* query, struct ctgit_repo_info* n, const char* object, Html text)
+ctgit_object_link (struct ctgit_query* query,
+                   const char* repo,
+                   int repo_len,
+                   const char* object,
+                   int object_len,
+                   Html text)
 {
   return html (
                html_tag ("a",
-                         html_attr ("href", html_fmt ("%s?repo=%s&object=%s",
+                         html_attr ("href", html_fmt ("%s?repo=%.*s&object=%.*s",
                                                       query->request->script_name,
-                                                      n->name,
-                                                      object)
+                                                      repo_len, repo,
+                                                      object_len, object)
                                     )
                          ),
                text
@@ -42,6 +47,9 @@ ctgit_object_link (struct ctgit_query* query, struct ctgit_repo_info* n, const c
 }
 
 
+/*
+  Display committs
+*/
 
 static Html
 ctgit_object_commit_menu_action (struct ctgit_query* query, unsigned char* sha1, void* buf, unsigned long size)
@@ -72,19 +80,13 @@ ctgit_object_commit_content_action (struct ctgit_query* query, unsigned char* sh
         }
       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)
-                                                 )
-                                           )
+
+          html_list_append (tree,
+                            "Tree: ",
+                            ctgit_object_link (query,
+                                               query->repo, strlen (query->repo),
+                                               i+5, 40,
+                                               html_fmt ("%.40s", i+5))
                             );
 
           (i = strchr (i, '\n')) && ++i;
@@ -94,16 +96,10 @@ ctgit_object_commit_content_action (struct ctgit_query* query, unsigned char* sh
         {
           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)
-                                                 )
+                                           ctgit_object_link (query,
+                                                              query->repo, strlen (query->repo),
+                                                              i+7, 40,
+                                                              html_fmt ("%.40s", i+7))
                                            )
                             );
           (i = strchr (i, '\n')) && ++i;
@@ -170,7 +166,7 @@ ctgit_object_commit_content_action (struct ctgit_query* query, unsigned char* sh
                                 );
             }
           else
-            html_list_append (author_text, "and Committer");
+            html_list_append (author_text, " and Committer");
 
           (i = strchr (i, '\n')) && ++i;
           continue;
index 1370f65..a814546 100644 (file)
 
 #include "ctgit.h"
 
-
-
 Html
-ctgit_object_link (struct ctgit_query* query, struct ctgit_repo_info* n, const char* object, Html text);
+ctgit_object_link (struct ctgit_query* query,
+                   const char* repo,
+                   int repo_len,
+                   const char* object,
+                   int object_len,
+                   Html text);
 
 Html
 ctgit_object_commit_action (struct ctgit_query* query, unsigned char* sha1);