Code

Add support for launching the editor from the tree view
authorJonas Fonseca <fonseca@diku.dk>
Sun, 28 Dec 2008 18:47:12 +0000 (13:47 -0500)
committerJonas Fonseca <fonseca@diku.dk>
Sun, 28 Dec 2008 22:16:19 +0000 (17:16 -0500)
Only supported for files in the currently checked out head.

Requested by Cyril Romain.

NEWS
tig.c

diff --git a/NEWS b/NEWS
index 4d91c7eca9dce38ff9feb9957ead68d4efbf10c3..361e3b0399615991f0720e849994e3f1468c261b 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -9,6 +9,7 @@ Improvements:
  - Display repository references in the sorted order: tags, heads,
    tracked remotes, remotes.
  - Add bash completion for blame.
+ - Tree view: edit files of the current branch.
 
 Bug fixes:
 
diff --git a/tig.c b/tig.c
index 6e5b0b4b9e131db046d322deacefada5079bb5b4..4216d8700846bc48ba6ca7f95699dd4e0e59b6c3 100644 (file)
--- a/tig.c
+++ b/tig.c
@@ -495,6 +495,7 @@ static char opt_editor[SIZEOF_STR]  = "";
 static FILE *opt_tty                   = NULL;
 
 #define is_initial_commit()    (!*opt_head_rev)
+#define is_head_commit(rev)    (!strcmp((rev), "HEAD") || !strcmp(opt_head_rev, (rev)))
 
 static enum request
 parse_options(int argc, const char *argv[])
@@ -3372,9 +3373,18 @@ tree_request(struct view *view, enum request request, struct line *line)
                }
 
                string_copy(opt_ref, view->vid);
-               string_format(opt_file, "%s%s", opt_path, tree_path(line));
                return request;
 
+       case REQ_EDIT:
+               if (line->type != LINE_TREE_FILE) {
+                       report("Edit only supported for files");
+               } else if (!is_head_commit(view->vid)) {
+                       report("Edit only supported for files in the current work tree");
+               } else {
+                       open_editor(TRUE, opt_file);
+               }
+               return REQ_NONE;
+
        case REQ_TREE_PARENT:
                if (!*opt_path) {
                        /* quit view if at top of tree */
@@ -3438,6 +3448,7 @@ tree_select(struct view *view, struct line *line)
 
        if (line->type == LINE_TREE_FILE) {
                string_copy_rev(ref_blob, text);
+               string_format(opt_file, "%s%s", opt_path, tree_path(line));
 
        } else if (line->type != LINE_TREE_DIR) {
                return;