git config file viewing and editing
authorChristian Thaeter <ct@pipapo.org>
Sun, 20 Jan 2008 20:25:01 +0000 (21:25 +0100)
committerChristian Thaeter <ct@pipapo.org>
Sun, 20 Jan 2008 20:25:01 +0000 (21:25 +0100)
src/actions.c
src/actions.h

index 080943d..39d1854 100644 (file)
@@ -379,6 +379,78 @@ webgit_tag_action (struct webgit_query* query)
 }
 
 
+/*
+  show and edit config
+*/
+static Html
+webgit_config_menu_action (struct webgit_repo_info* repo)
+{
+  (void) repo;
+  return html ("TODO: config menu");
+}
+
+static Html
+webgit_config_content_action (struct webgit_repo_info* repo)
+{
+  return html (
+               html_tag ("form",
+                         html_attr ("name", "config-change"),
+                         html_attr ("enctype", "multipart/form-data"),
+                         html_attr ("method", "post"),
+                         html_attr ("action",
+                                    html_fmt ("%s",
+                                              repo->query->request->script_name
+                                              )
+                                    )
+                         ),
+
+               html_hidden ("repo", repo->name),
+               html_hidden ("action", "config"),
+               html (
+                     html_tag ("textarea",
+                               html_attr ("name", "blob"),
+                               html_attr ("rows", "40"),
+                               html_attr ("cols", "80")
+                               ),
+                     html_include_escaped (git_path("config"))
+                     ),
+               html (
+                     html_tag ("input",
+                               html_attr ("type", "submit"),
+                               html_attr ("value", "Save")
+                               )
+                     )
+               );
+}
+
+static Html
+webgit_config_action (struct webgit_query* query)
+{
+  struct webgit_repo_info* repo = webgit_repo_enter (query);
+  webgit_repoinfo_find_last (repo);
+
+  if (query->blob)
+    {
+      FILE* cfg = fopen (git_path ("config"), "w");
+      /*TODO rxpd check */
+      if (!cfg)
+        webgit_warn ("could not open %s for writing", git_path("config"));
+      else
+        {
+          if (fwrite (query->blob, query->blob_size, 1, cfg) < 1)
+            webgit_warn ("could not write config");
+          fclose (cfg);
+        }
+    }
+
+  return html(
+              html (html_tag ("div"), webgit_config_menu_action (repo)), html_nl (),
+              html (html_tag ("div"), webgit_config_content_action (repo)), html_nl ()
+              );
+}
+
+
 /*
   edit an object
 */
index 70fbfa8..204d4e6 100644 (file)
@@ -38,6 +38,7 @@
  WEBGIT_ACTION(raw, "Show an object, raw format")                       \
  WEBGIT_ACTION(branch, "Show and manage branches")                      \
  WEBGIT_ACTION(tag, "Show and manage tags")                             \
+ WEBGIT_ACTION(config, "Show and edit the git configuration")           \
  WEBGIT_ACTION(edit, "Edit and object")                                 \
  WEBGIT_ACTION(commit, "Commit pending edits")