Code

Enhance prepare_update_file to add support for refreshable file IO
authorJonas Fonseca <fonseca@diku.dk>
Fri, 11 Mar 2011 03:44:54 +0000 (22:44 -0500)
committerJonas Fonseca <fonseca@diku.dk>
Thu, 17 Mar 2011 01:18:55 +0000 (21:18 -0400)
io.c
tig.c

diff --git a/io.c b/io.c
index edd6e85cfe110a45b1ee76a05ca476ccc8ef755b..fabde00747eb5130e4b33c0dbe744ed05bc64977 100644 (file)
--- a/io.c
+++ b/io.c
@@ -97,6 +97,7 @@ argv_copy(const char ***dst, const char *src[])
 {
        int argc;
 
+       argv_free(*dst);
        for (argc = 0; src[argc]; argc++)
                if (!argv_append(dst, src[argc]))
                        return FALSE;
diff --git a/tig.c b/tig.c
index 1d3122db059320cb194783ea24b0e0607808dd7a..8b46fa7f79629ed6bde86251f838530c05dcc071 100644 (file)
--- a/tig.c
+++ b/tig.c
@@ -2524,10 +2524,11 @@ start_update(struct view *view, const char **argv, const char *dir)
 static bool
 prepare_update_file(struct view *view, const char *name)
 {
+       const char *file_argv[] = { opt_cdup, name , NULL };
+
        if (view->pipe)
                end_update(view, TRUE);
-       argv_free(view->argv);
-       return io_open(&view->io, "%s/%s", opt_cdup[0] ? opt_cdup : ".", name);
+       return argv_copy(&view->argv, file_argv);
 }
 
 static bool
@@ -2556,6 +2557,9 @@ begin_update(struct view *view, const char *dir, const char **argv, enum open_fl
        if (view->argv && view->argv[0] &&
            !io_run(&view->io, IO_RD, view->dir, view->argv))
                return FALSE;
+       else if (view->argv && !strcmp(view->argv[0], opt_cdup) &&
+                !io_open(&view->io, "%s%s", opt_cdup, view->argv[1]))
+               return FALSE;
 
        setup_update(view, view->id);
 
@@ -5687,17 +5691,6 @@ stage_request(struct view *view, enum request request, struct line *line)
                return REQ_VIEW_CLOSE;
        }
 
-       if (stage_line_type == LINE_STAT_UNTRACKED) {
-               if (!suffixcmp(stage_status.new.name, -1, "/")) {
-                       report("Cannot display a directory");
-                       return REQ_NONE;
-               }
-
-               if (!prepare_update_file(view, stage_status.new.name)) {
-                       report("Failed to open file: %s", strerror(errno));
-                       return REQ_NONE;
-               }
-       }
        open_view(view, REQ_VIEW_STAGE, OPEN_REFRESH);
 
        return REQ_NONE;