add 'maxage' config/parameter to hide inactive repositories from main list
authorChristian Thaeter <ct@pipapo.org>
Wed, 23 Jan 2008 22:29:22 +0000 (23:29 +0100)
committerChristian Thaeter <ct@pipapo.org>
Wed, 23 Jan 2008 22:29:22 +0000 (23:29 +0100)
maxage can be given in webgit.conf, withing the repositories .git/config
or as cgi query parameter.

When a repository is idle for more than maxage days it will be hidden from
the main repository list.

For example to hide a repository always set maxage = 0 in its config or set
it to a huge value to unhide it.

When given as query parameter it will override all other configs.

src/actions.c
src/options.c
src/options.h
src/query.c
src/query.h
src/repo.c
src/repo.h
src/webgit.h

index 1f31fe6..5117070 100644 (file)
@@ -84,63 +84,66 @@ webgit_main_content_action (struct webgit_query* query)
 
       webgit_repoinfo_find_last (n);
 
-      html_list_append (table, html (
-                                     html_tag ("tr"),
-                                     html(html_tag ("td"),
-                                          webgit_summary_link (query, n, html (n->name))),
-                                     html(html_tag ("td"), n->url ?
-                                          html (
-                                                html_tag ("a", html_attr ("href", n->url)),
-                                                n->url)
-                                          : html("N/A")
-                                          ),
-                                     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))
-                                          ),
-                                     html(html_tag ("td"),
-                                          webgit_email_link (
-                                                             html (n->last_author_name),
-                                                             html (n->last_author_email)
-                                                             )
-                                          ),
-                                     html(html_tag ("td"),
-                                          webgit_email_link (
-                                                             html (n->last_committer_name),
-                                                             html (n->last_committer_email)
-                                                             )
-                                          ),
-                                     html(html_tag ("td"),
-                                          html(
-                                               webgit_log_link (query,
-                                                                n->name,
-                                                                n->last_head,
-                                                                NULL, 0,
-                                                                query->count,
-                                                                html("Log")
-                                                                ),
-                                               " ",
-
-                                               "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"))
-                                               )
-                                          )
-                                     ),
-                        html_nl()
-                        );
+      if (n->age < n->maxage)
+        {
+          html_list_append (table, html (
+                                         html_tag ("tr"),
+                                         html(html_tag ("td"),
+                                              webgit_summary_link (query, n, html (n->name))),
+                                         html(html_tag ("td"), n->url ?
+                                              html (
+                                                    html_tag ("a", html_attr ("href", n->url)),
+                                                    n->url)
+                                              : html("N/A")
+                                              ),
+                                         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))
+                                              ),
+                                         html(html_tag ("td"),
+                                              webgit_email_link (
+                                                                 html (n->last_author_name),
+                                                                 html (n->last_author_email)
+                                                                 )
+                                              ),
+                                         html(html_tag ("td"),
+                                              webgit_email_link (
+                                                                 html (n->last_committer_name),
+                                                                 html (n->last_committer_email)
+                                                                 )
+                                              ),
+                                         html(html_tag ("td"),
+                                              html(
+                                                   webgit_log_link (query,
+                                                                    n->name,
+                                                                    n->last_head,
+                                                                    NULL, 0,
+                                                                    query->count,
+                                                                    html("Log")
+                                                                    ),
+                                                   " ",
+
+                                                   "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"))
+                                                   )
+                                              )
+                                         ),
+                            html_nl()
+                            );
+        }
     }
 
   return html (html_tag ("table", html_attr ("id", "summary")), table);
index e1d4c70..71ec448 100644 (file)
@@ -101,6 +101,14 @@ conf_skin_opt (struct webgit_query* query, char* arg)
 }
 
 
+static int
+conf_maxage_opt (struct webgit_query* query, char* arg)
+{
+  query->maxage = atol (arg) * 86400UL;
+  return 0;
+}
+
+
 static int
 conf_count_opt (struct webgit_query* query, char* arg)
 {
@@ -108,6 +116,7 @@ conf_count_opt (struct webgit_query* query, char* arg)
   return 0;
 }
 
+
 int
 webgit_commandline_dispatch (int argc, char**argv, struct webgit_query* query)
 {
index ed7ae4b..462fd39 100644 (file)
@@ -35,6 +35,7 @@
  CONF_OPT(skindir, "Set dir to the skins")                      \
  CONF_OPT(webskindir, "Set dir to skins from webroot")          \
  CONF_OPT(skin, "Set default skin")                             \
+ CONF_OPT(maxage, "Age in days to hide inactive repositories")  \
  CONF_OPT(count, "Set default for 'items per page'")
 
 // CONF_OPT(conffile) CONF_OPT(include)
index 95578b6..d849e9b 100644 (file)
@@ -41,6 +41,7 @@ webgit_query_init (struct webgit_query* q)
   q->rxpd = NULL;
   q->skindir = cwa_strndup (WEBGIT_SKINDIR_DEFAULT, SIZE_MAX);
   q->webskindir = cwa_strndup (WEBGIT_WEBSKINDIR_DEFAULT, SIZE_MAX);
+  q->maxage = 1000000000;
 
   q->repo = NULL;
   q->action = NULL;
@@ -219,19 +220,32 @@ webgit_skin_param (const Cgi self, const char* v, size_t v_sz, void* u_dat)
 
 
 static void
-webgit_count_param (const Cgi self, const char* v, size_t v_sz, void* u_dat)
+webgit_maxage_param (const Cgi self, const char* v, size_t v_sz, void* u_dat)
 {
   (void) self;
   struct webgit_query* q = (struct webgit_query*) u_dat;
 
-  /* TODO validate that v is a probably legal reference (alnum() || one of '_/.') */
-  if (webgit_validate_string (v, v_sz))
+  if (v_sz)
     {
-      q->count = atoi (v);
+      unsigned long maxage = atol (v) * 86400UL;
+
+      LLIST_FOREACH (&q->repos, node)
+        ((struct webgit_repo_info*)node)->maxage = maxage;
     }
 }
 
 
+static void
+webgit_count_param (const Cgi self, const char* v, size_t v_sz, void* u_dat)
+{
+  (void) self;
+  struct webgit_query* q = (struct webgit_query*) u_dat;
+
+  if (v_sz)
+    q->count = atoi (v);
+}
+
+
 void
 webgit_param_dispatch (const Cgi self,
                       const char* name,
index 01224c6..aadaa40 100644 (file)
 /*
   parameters for cgi requests
 */
-#define WEBGIT_PARAMS                                           \
- WEBGIT_PARAM(repo, "Repository to be queried")                 \
- WEBGIT_PARAM(action, "Action to be performed")                 \
- WEBGIT_PARAM(ref, "Selected ref (branch, tag, ..) for query")  \
- WEBGIT_PARAM(path, "Path and filename for the queried object") \
- WEBGIT_PARAM(object, "Object to perform on")                   \
- WEBGIT_PARAM(blob, "Data recieved from an edit")               \
- WEBGIT_PARAM(skin, "Set skin")                                 \
+#define WEBGIT_PARAMS                                                   \
+ WEBGIT_PARAM(repo, "Repository to be queried")                         \
+ WEBGIT_PARAM(action, "Action to be performed")                         \
+ WEBGIT_PARAM(ref, "Selected ref (branch, tag, ..) for query")          \
+ WEBGIT_PARAM(path, "Path and filename for the queried object")         \
+ WEBGIT_PARAM(object, "Object to perform on")                           \
+ WEBGIT_PARAM(blob, "Data recieved from an edit")                       \
+ WEBGIT_PARAM(skin, "Set skin")                                         \
+ WEBGIT_PARAM(maxage, "Age in days to hide inactive repositories")      \
  WEBGIT_PARAM(count, "How many things to display")
 
 
index 4b58aa1..e4a58b4 100644 (file)
@@ -126,6 +126,13 @@ webgit_skin_conf (struct webgit_repo_info* self, const char *value)
 }
 
 
+static void
+webgit_maxage_conf (struct webgit_repo_info* self, const char *value)
+{
+  self->maxage = atol (value) * 86400UL;
+}
+
+
 int
 webgit_repo_conf_cb (const char *var, const char *value)
 {
@@ -268,7 +275,7 @@ webgit_repoinfo_new (struct webgit_query* query, const char* path)
   self->description = NULL;
   self->url = NULL;
   self->readme = NULL;
-
+  self->maxage = query->maxage;
 
   llist_init (&self->node);
   self->path = cwa_strndup (path, SIZE_MAX);
index b1771b5..365be02 100644 (file)
@@ -34,6 +34,7 @@
  WEBGIT_CONF(skindir, "Set dir to the skins")                                   \
  WEBGIT_CONF(webskindir, "Set dir to skins from webroot")                       \
  WEBGIT_CONF(skin, "Set default skin")                                          \
+ WEBGIT_CONF(maxage, "Age in days to hide inactive repositories")               \
  WEBGIT_CONF(readme, "Set a readme.html file to display")
 
 #define WEBGIT_CONF_PREFIX "web."
index d64ec73..68c9721 100644 (file)
@@ -54,6 +54,7 @@ struct webgit_query
   char* rxpd;
   char* skindir;
   char* webskindir;
+  unsigned long maxage;
   //int cache_read;
   //int cache_write;
   //int cache_expire;
@@ -86,6 +87,7 @@ struct webgit_repo_info
   char* description;
   char* url;
   char* readme;
+  unsigned long maxage;
 
   char* last_commit;
   char* last_tree;