add a re-edit link for files in worktree diverted from head
authorChristian Thaeter <ct@pipapo.org>
Thu, 21 Feb 2008 16:07:37 +0000 (17:07 +0100)
committerChristian Thaeter <ct@pipapo.org>
Thu, 21 Feb 2008 16:07:37 +0000 (17:07 +0100)
src/actions.c
src/object_blob.c
src/object_tree.c
src/worktree.c
src/worktree.h

index 4d6700a..81c4985 100644 (file)
@@ -29,6 +29,7 @@
 #include "tag.h"
 #include "account.h"
 #include "edit.h"
+#include "worktree.h"
 
 #include "llist.h"
 #include <cwa.h>
@@ -627,8 +628,8 @@ webgit_edit_action (struct webgit_query* query)
   webgit_object_deduce (query);
 
   unsigned char sha1[20];
-  if (!query->object || get_sha1 (query->object, sha1))
-    return html("error: unknown object");
+  if (!webgit_worktree_getsha1 (query, sha1))
+    return html("error: no worktree");
 
   switch (sha1_object_info(sha1, NULL))
     {
@@ -655,6 +656,7 @@ webgit_stage_action (struct webgit_query* query)
   (void) query;
   query->current_repo =  webgit_repo_enter (query);
   webgit_worktree_stage (query->current_repo);
+  /*TODO: what to show now? tree? object? head? worktree? */
   return webgit_edit_action (query);
 }
 
index ce48a88..3efbd81 100644 (file)
@@ -53,7 +53,14 @@ webgit_object_blob_menu_action (struct webgit_repo_info* repo, unsigned char* sh
                                           "commit", query->commit,
                                           "path", query->path,
                                           "action", "edit")
-                   : html ("diff<br />")
+                   : html ("Diff<br />",
+                           webgit_object_link (query, html ("Reedit<br />"),
+                                               "repo", query->repo,
+                                               "ref", query->head,
+                                               "commit", query->commit,
+                                               "path", query->path,
+                                               "action", "edit")
+                           )
                    )
                : html (),
                webgit_object_tree_parent_link (query, "<<%s"),
index c2015be..1e14295 100644 (file)
@@ -180,17 +180,24 @@ webgit_html_tree (const unsigned char *sha1, const char *base, int baselen,
                                                               "path", pathname,
                                                               "action", "raw"),
                                           repo_in_flight->worktree
-                                          ? ( webgit_worktree_blob_eq (repo_in_flight, pathname)
-                                              ? html (
-                                                      " ",
-                                                      webgit_object_link (query, html ("edit"),
-                                                                          "repo", query->repo,
-                                                                          "ref", query->head,
-                                                                          "commit", query->commit,
-                                                                          "path", pathname,
-                                                                          "action", "edit")
-                                                      )
-                                              : html (" diff")
+                                          ? (webgit_worktree_blob_eq (repo_in_flight, pathname)
+                                             ? html (
+                                                     " ",
+                                                     webgit_object_link (query, html ("edit"),
+                                                                         "repo", query->repo,
+                                                                         "ref", query->head,
+                                                                         "commit", query->commit,
+                                                                         "path", pathname,
+                                                                         "action", "edit")
+                                                     )
+                                             : html (" diff ",
+                                                     webgit_object_link (query, html ("reedit"),
+                                                                         "repo", query->repo,
+                                                                         "ref", query->head,
+                                                                         "commit", query->commit,
+                                                                         "path", pathname,
+                                                                         "action", "edit")
+                                                     )
                                               )
                                           : html ()
                                           ),
index 88070a1..4cce9ee 100644 (file)
@@ -94,6 +94,7 @@ tree_sort (LList tree)
   return tree;
 }
 
+
 static LList tree_in_flight = NULL;
 
 LList
@@ -131,6 +132,58 @@ webgit_tree_parse (LList root, const unsigned char* sha1)
   return root;
 }
 
+
+int
+webgit_worktree_getsha1 (struct webgit_query* query, unsigned char* sha1)
+{
+  unsigned char sha1_tree[20];
+  if (get_sha1 (query->current_repo->worktree, sha1_tree))
+    return 0;
+
+  llist worktree;
+  llist_init (&worktree);
+  webgit_tree_parse (&worktree, sha1_tree);
+
+  int ret = 0;
+
+  const char* delim;
+  const char* name = query->path;
+  LList tree = &worktree;
+
+  do
+    {
+      delim = strchr (name, '/');
+      size_t len = delim ? (size_t)(delim - name - 1) : strlen (name);
+      LLIST_FOREACH (tree, n)
+        {
+          struct treenode* node = (struct treenode*)n;
+
+          if (strncmp (name, node->name, len))
+            continue;
+          else
+            {
+              if (delim)
+                {
+                  name = delim + 1;
+                  tree = webgit_tree_parse (&node->subtree, node->sha1);
+                  break;
+                }
+              else
+                {
+                  hashcpy (sha1, node->sha1);
+                  ret = 1;
+                }
+            }
+        }
+    } while (delim);
+
+  LLIST_WHILE_HEAD (&worktree, node)
+    treenode_free ((struct treenode*) node);
+
+  return ret;
+}
+
+
 static int
 webgit_worktree_create (struct webgit_repo_info* repo,
                         const char* ref,
index 2ebd425..7d17e7e 100644 (file)
@@ -25,6 +25,8 @@
 void
 webgit_worktree_setup (struct webgit_repo_info* repo);
 
+int
+webgit_worktree_getsha1 (struct webgit_query* query, unsigned char* sha1);
 
 int
 webgit_worktree_blob_eq (struct webgit_repo_info* repo, const char* path);