status: make it possible to batch updates by pressing on the section line
[tig] / tig.c
diff --git a/tig.c b/tig.c
index b9c10ab..50fbaa7 100644 (file)
--- a/tig.c
+++ b/tig.c
@@ -3024,16 +3024,17 @@ static bool
 status_enter(struct view *view, struct line *line)
 {
        struct status *status = line->data;
-       char path[SIZEOF_STR];
+       char path[SIZEOF_STR] = "";
        char *info;
        size_t cmdsize = 0;
 
-       if (!status || line->type == LINE_STAT_NONE) {
-               report("No file has been chosen");
+       if (line->type == LINE_STAT_NONE ||
+           (!status && line[1].type == LINE_STAT_NONE)) {
+               report("No file to diff");
                return TRUE;
        }
 
-       if (sq_quote(path, 0, status->name) >= sizeof(path))
+       if (status && sq_quote(path, 0, status->name) >= sizeof(path))
                return FALSE;
 
        if (opt_cdup[0] &&
@@ -3046,19 +3047,31 @@ status_enter(struct view *view, struct line *line)
                if (!string_format_from(opt_cmd, &cmdsize, STATUS_DIFF_SHOW_CMD,
                                        "--cached", path))
                        return FALSE;
-               info = "Staged changes to %s";
+               if (status)
+                       info = "Staged changes to %s";
+               else
+                       info = "Staged changes";
                break;
 
        case LINE_STAT_UNSTAGED:
                if (!string_format_from(opt_cmd, &cmdsize, STATUS_DIFF_SHOW_CMD,
                                        "", path))
                        return FALSE;
-               info = "Unstaged changes to %s";
+               if (status)
+                       info = "Unstaged changes to %s";
+               else
+                       info = "Unstaged changes";
                break;
 
        case LINE_STAT_UNTRACKED:
                if (opt_pipe)
                        return FALSE;
+
+               if (!status) {
+                       report("No file to show");
+                       return TRUE;
+               }
+
                opt_pipe = fopen(status->name, "r");
                info = "Untracked file %s";
                break;
@@ -3126,7 +3139,6 @@ status_update_file(struct view *view, struct status *status, enum line_type type
        if (written != bufsize)
                return FALSE;
 
-       open_view(view, REQ_VIEW_STATUS, OPEN_RELOAD);
        return TRUE;
 }
 
@@ -3134,16 +3146,26 @@ static void
 status_update(struct view *view)
 {
        if (view == VIEW(REQ_VIEW_STATUS)) {
-               struct line *line = view->lines
-                                 ? &view->line[view->lineno] : NULL;
+               struct line *line = &view->line[view->lineno];
 
-               if (!line || !line->data) {
-                       report("No file has been chosen");
-                       return;
-               }
+               assert(view->lines);
+
+               if (!line->data) {
+                       if (line[1].type == LINE_STAT_NONE) {
+                               report("Nothing to update");
+                               return;
+                       }
 
-               if (!status_update_file(view, line->data, line->type))
+                       while (++line < view->line + view->lines && line->data) {
+                               if (!status_update_file(view, line->data, line->type))
+                                       report("Failed to update file status");
+                       }
+
+               } else if (!status_update_file(view, line->data, line->type)) {
                        report("Failed to update file status");
+               }
+
+               open_view(view, REQ_VIEW_STATUS, OPEN_RELOAD);
        } else {
                report("This action is only valid for the status view");
        }