Code

Fix open_editor to make the file path relative to the project root
authorJonas Fonseca <fonseca@diku.dk>
Wed, 19 Sep 2007 00:50:12 +0000 (02:50 +0200)
committerJonas Fonseca <fonseca@diku.dk>
Wed, 19 Sep 2007 00:55:46 +0000 (02:55 +0200)
.. by prefixing the file path with opt_cdup if requested.

tig.c

diff --git a/tig.c b/tig.c
index ac2aba0f1b26da9be2e928a88f2fb51ff6c5c59d..3811a228aebbd6ce018cef41600b22b491acdcd9 100644 (file)
--- a/tig.c
+++ b/tig.c
@@ -2143,11 +2143,12 @@ open_view(struct view *prev, enum request request, enum open_flags flags)
 }
 
 static void
-open_editor(struct view *view, char *file)
+open_editor(struct view *view, bool from_root, char *file)
 {
        char cmd[SIZEOF_STR];
        char file_sq[SIZEOF_STR];
        char *editor;
+       char *prefix = from_root ? opt_cdup : "";
 
        editor = getenv("GIT_EDITOR");
        if (!editor && *opt_editor)
@@ -2160,7 +2161,7 @@ open_editor(struct view *view, char *file)
                editor = "vi";
 
        if (sq_quote(file_sq, 0, file) < sizeof(file_sq) &&
-           string_format(cmd, "%s %s", editor, file_sq)) {
+           string_format(cmd, "%s %s%s", editor, prefix, file_sq)) {
                def_prog_mode();           /* save current tty modes */
                endwin();                  /* restore original tty modes */
                system(cmd);
@@ -3309,7 +3310,7 @@ status_request(struct view *view, enum request request, struct line *line)
                if (!status)
                        return request;
 
-               open_editor(view, status->name);
+               open_editor(view, status->status != '?', status->name);
                break;
 
        case REQ_ENTER:
@@ -3543,7 +3544,7 @@ stage_request(struct view *view, enum request request, struct line *line)
                if (!stage_status.name[0])
                        return request;
 
-               open_editor(view, stage_status.name);
+               open_editor(view, stage_status.status != '?', stage_status.name);
                break;
 
        case REQ_ENTER: