index 48fbca0042cac6b65a4ec0742fc0590a853c3918..e78c26c2377d64520123a9607dbdc1cd33cc27ea 100644 (file)
--- a/tig.c
+++ b/tig.c
*/
static inline void
-string_ncopy(char *dst, const char *src, int dstlen)
+string_ncopy(char *dst, const char *src, size_t dstlen)
{
strncpy(dst, src, dstlen - 1);
dst[dstlen - 1] = 0;
}
static bool
-string_nformat(char *buf, size_t bufsize, int *bufpos, const char *fmt, ...)
+string_nformat(char *buf, size_t bufsize, size_t *bufpos, const char *fmt, ...)
{
va_list args;
- int pos = bufpos ? *bufpos : 0;
+ size_t pos = bufpos ? *bufpos : 0;
va_start(args, fmt);
pos += vsnprintf(buf + pos, bufsize - pos, fmt, args);
{ 'z', REQ_STOP_LOADING },
{ 'v', REQ_SHOW_VERSION },
{ 'r', REQ_SCREEN_REDRAW },
- { 'n', REQ_TOGGLE_LINENO },
+ { '.', REQ_TOGGLE_LINENO },
{ 'g', REQ_TOGGLE_REV_GRAPH },
{ ':', REQ_PROMPT },
{
static char buf[BUFSIZ];
static char key_char[] = "'X'";
- int pos = 0;
+ size_t pos = 0;
char *sep = " ";
int i;
static struct view *display[2];
static unsigned int current_view;
-#define foreach_view(view, i) \
+#define foreach_displayed_view(view, i) \
for (i = 0; i < ARRAY_SIZE(display) && (view = display[i]); i++)
#define displayed_views() (display[1] != NULL ? 2 : 1)
#define VIEW(req) (&views[(req) - REQ_OFFSET - 1])
+#define foreach_view(view, i) \
+ for (i = 0; i < ARRAY_SIZE(views) && (view = &views[i]); i++)
+
+#define view_is_displayed(view) \
+ (view == display[0] || view == display[1])
static bool
draw_view_line(struct view *view, unsigned int lineno)
{
+ assert(view_is_displayed(view));
+
if (view->offset + lineno >= view->lines)
return FALSE;
static void
update_view_title(struct view *view)
{
+ assert(view_is_displayed(view));
+
if (view == display[current_view])
wbkgdset(view->title, get_line_attr(LINE_TITLE_FOCUS));
else
offset = 0;
- foreach_view (view, i) {
+ foreach_displayed_view (view, i) {
if (!view->win) {
view->win = newwin(view->height, 0, offset, 0);
if (!view->win)
struct view *view;
int i;
- foreach_view (view, i) {
+ foreach_displayed_view (view, i) {
redraw_view(view);
update_view_title(view);
}
static void
do_scroll_view(struct view *view, int lines, bool redraw)
{
+ assert(view_is_displayed(view));
+
/* The rendering expects the new offset. */
view->offset += lines;
@@ -1586,6 +1597,8 @@ static void search_view(struct view *view, enum request request, const char *sea
static bool
find_next_line(struct view *view, unsigned long lineno, struct line *line)
{
+ assert(view_is_displayed(view));
+
if (!view->ops->grep(view, line))
return FALSE;
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;
}
}
+ if (!view_is_displayed(view))
+ goto check_pipe;
+
if (view == VIEW(REQ_VIEW_TREE)) {
/* Clear the view and redraw everything since the tree sorting
* might have rearranged things. */
* commit reference in view->ref it'll be available here. */
update_view_title(view);
+check_pipe:
if (ferror(view->pipe)) {
report("Failed to read: %s", strerror(errno));
goto end;
}
static bool
-add_describe_ref(char *buf, int *bufpos, char *commit_id, const char *sep)
+add_describe_ref(char *buf, size_t *bufpos, char *commit_id, const char *sep)
{
char refbuf[SIZEOF_STR];
char *ref = NULL;
char buf[SIZEOF_STR];
char *commit_id = line->data + STRING_SIZE("commit ");
struct ref **refs;
- int bufpos = 0, refpos = 0;
+ size_t bufpos = 0, refpos = 0;
const char *sep = "Refs: ";
bool is_tag = FALSE;
dirsep[0] = 0;
} else {
- int pathlen = strlen(opt_path);
+ size_t pathlen = strlen(opt_path);
char *basename = data + SIZEOF_TREE_ATTR;
string_format_from(opt_path, &pathlen, "%s/", basename);