summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 18e2a6a)
raw | patch | inline | side by side (parent: 18e2a6a)
author | Jonas Fonseca <fonseca@diku.dk> | |
Sun, 9 Nov 2008 20:04:45 +0000 (21:04 +0100) | ||
committer | Jonas Fonseca <fonseca@diku.dk> | |
Tue, 13 Jan 2009 21:55:20 +0000 (22:55 +0100) |
NEWS | patch | blob | history | |
tig.c | patch | blob | history |
index 0463230378bda402844441b449eab14760703825..31ef9d529126a042f47195c7e881d4321445ff38 100644 (file)
--- a/NEWS
+++ b/NEWS
- Add bash completion for blame.
- Tree view: edit files of the current branch.
- Run requests: new identifiers %(directory), %(file), and %(ref)
+ - Improve responsiveness and view loading speed by using select(2).
Bug fixes:
index 36c32cd99962ebb92a4075c8503014ec15144190..544fd8544331ddf143c2659e9f747d89171c5da9 100644 (file)
--- a/tig.c
+++ b/tig.c
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/stat.h>
+#include <sys/select.h>
#include <unistd.h>
#include <time.h>
#include <fcntl.h>
return strerror(io->error);
}
+static bool
+io_can_read(struct io *io)
+{
+ struct timeval tv = { 0, 500 };
+ fd_set fds;
+
+ FD_ZERO(&fds);
+ FD_SET(io->pipe, &fds);
+
+ return select(io->pipe + 1, &fds, NULL, NULL, &tv) > 0;
+}
+
static ssize_t
io_read(struct io *io, void *buf, size_t bufsize)
{
{
char out_buffer[BUFSIZ * 2];
char *line;
- /* The number of lines to read. If too low it will cause too much
- * redrawing (and possible flickering), if too high responsiveness
- * will suffer. */
- unsigned long lines = view->height;
int redraw_from = -1;
+ bool can_read = TRUE;
if (!view->pipe)
return TRUE;
+ if (!io_can_read(view->pipe))
+ return TRUE;
+
/* Only redraw if lines are visible. */
if (view->offset + view->height >= view->lines)
redraw_from = view->lines - view->offset;
- /* FIXME: This is probably not perfect for backgrounded views. */
- if (!realloc_lines(view, view->lines + lines))
- goto alloc_error;
-
- while ((line = io_get(view->pipe, '\n', TRUE))) {
+ for (; (line = io_get(view->pipe, '\n', can_read)); can_read = FALSE) {
size_t linelen = strlen(line);
if (opt_iconv != ICONV_NONE) {
}
}
- if (!view->ops->read(view, line))
+ if (!realloc_lines(view, view->lines + 1) ||
+ !view->ops->read(view, line))
goto alloc_error;
-
- if (lines-- == 1)
- break;
}
{
+ unsigned long lines = view->lines;
int digits;
- lines = view->lines;
for (digits = 0; lines; digits++)
lines /= 10;