commit - fb2756b9645e56a7371fbb658d2b2634a7f62dfe
commit + e942472989b7ef6987c982f41c38a77d4ea958fc
blob - 717b19eb897fabfc8c02dd72eb86fd837ae01367
blob + ddc8b9dd0d1ca040aa6c0a8df5e18a69740f5b3f
--- tog/tog.c
+++ tog/tog.c
struct got_repository *repo;
};
+struct tog_blame_cb_args {
+ pthread_mutex_t *mutex;
+ struct tog_blame_line *lines; /* one per line */
+ int nlines;
+
+ struct tog_view *view;
+ struct got_object_id *commit_id;
+ FILE *f;
+ const char *path;
+ int *first_displayed_line;
+ int *last_displayed_line;
+ int *selected_line;
+ int *quit;
+};
+
+struct tog_blame_thread_args {
+ const char *path;
+ struct got_repository *repo;
+ struct tog_blame_cb_args *cb_args;
+ int *complete;
+};
+
+struct tog_blame {
+ FILE *f;
+ size_t filesize;
+ struct tog_blame_line *lines;
+ size_t nlines;
+ pthread_t thread;
+ struct tog_blame_thread_args thread_args;
+ struct tog_blame_cb_args cb_args;
+ const char *path;
+};
+
struct tog_blame_view_state {
int first_displayed_line;
int last_displayed_line;
const char *path;
struct got_repository *repo;
struct got_object_id *commit_id;
+ struct tog_blame blame;
};
struct tog_parent_tree {
return NULL;
}
-
-struct tog_blame_cb_args {
- pthread_mutex_t *mutex;
- struct tog_blame_line *lines; /* one per line */
- int nlines;
-
- struct tog_view *view;
- struct got_object_id *commit_id;
- FILE *f;
- const char *path;
- int *first_displayed_line;
- int *last_displayed_line;
- int *selected_line;
- int *quit;
-};
static const struct got_error *
blame_cb(void *arg, int nlines, int lineno, struct got_object_id *id)
return err;
}
-struct tog_blame_thread_args {
- const char *path;
- struct got_repository *repo;
- struct tog_blame_cb_args *cb_args;
- int *complete;
-};
-
static void *
blame_thread(void *arg)
{
got_object_commit_close(commit);
return err;
}
-
-struct tog_blame {
- FILE *f;
- size_t filesize;
- struct tog_blame_line *lines;
- size_t nlines;
- pthread_t thread;
- struct tog_blame_thread_args thread_args;
- struct tog_blame_cb_args cb_args;
- const char *path;
-};
static const struct got_error *
stop_blame(struct tog_blame *blame)
s->path = path;
s->repo = repo;
s->commit_id = commit_id;
+ memset(&s->blame, 0, sizeof(s->blame));
return NULL;
}
const struct got_error *err = NULL, *thread_err = NULL;
int ch, done = 0, eof;
struct got_object *obj = NULL, *pobj = NULL;
- struct tog_blame blame;
struct tog_view *diff_view;
struct tog_blame_view_state *s = &view->state.blame;
view_show(view);
- memset(&blame, 0, sizeof(blame));
- err = run_blame(&blame, &s->mutex, view, &s->blame_complete,
+ err = run_blame(&s->blame, &s->mutex, view, &s->blame_complete,
&s->first_displayed_line, &s->last_displayed_line,
&s->selected_line, &done, s->path, s->blamed_commit->id, s->repo);
if (err)
err = got_error_from_errno();
goto done;
}
- err = draw_blame(view, s->blamed_commit->id, blame.f,
- s->path, blame.lines, blame.nlines, s->blame_complete,
+ err = draw_blame(view, s->blamed_commit->id, s->blame.f,
+ s->path, s->blame.lines, s->blame.nlines, s->blame_complete,
s->selected_line, &s->first_displayed_line,
&s->last_displayed_line, &eof, view->nlines);
if (pthread_mutex_unlock(&s->mutex) != 0) {
case KEY_DOWN:
if (s->selected_line < view->nlines - 2 &&
s->first_displayed_line +
- s->selected_line <= blame.nlines)
+ s->selected_line <= s->blame.nlines)
s->selected_line++;
- else if (s->last_displayed_line < blame.nlines)
+ else if (s->last_displayed_line <
+ s->blame.nlines)
s->first_displayed_line++;
break;
case 'b':
case 'p': {
struct got_object_id *id;
- id = get_selected_commit_id(blame.lines,
+ id = get_selected_commit_id(s->blame.lines,
s->first_displayed_line, s->selected_line);
if (id == NULL || got_object_id_cmp(id,
s->blamed_commit->id) == 0)
break;
err = open_selected_commit(&pobj, &obj,
- blame.lines, s->first_displayed_line,
+ s->blame.lines, s->first_displayed_line,
s->selected_line, s->repo);
if (err)
break;
err = got_error_from_errno();
goto done;
}
- thread_err = stop_blame(&blame);
+ thread_err = stop_blame(&s->blame);
done = 0;
if (pthread_mutex_lock(&s->mutex) != 0) {
err = got_error_from_errno();
goto done;
SIMPLEQ_INSERT_HEAD(&s->blamed_commits,
s->blamed_commit, entry);
- err = run_blame(&blame, &s->mutex, view,
+ err = run_blame(&s->blame, &s->mutex, view,
&s->blame_complete,
&s->first_displayed_line,
&s->last_displayed_line,
err = got_error_from_errno();
goto done;
}
- thread_err = stop_blame(&blame);
+ thread_err = stop_blame(&s->blame);
done = 0;
if (pthread_mutex_lock(&s->mutex) != 0) {
err = got_error_from_errno();
got_object_qid_free(s->blamed_commit);
s->blamed_commit =
SIMPLEQ_FIRST(&s->blamed_commits);
- err = run_blame(&blame, &s->mutex, view,
+ err = run_blame(&s->blame, &s->mutex, view,
&s->blame_complete,
&s->first_displayed_line,
&s->last_displayed_line,
case KEY_ENTER:
case '\r':
err = open_selected_commit(&pobj, &obj,
- blame.lines, s->first_displayed_line,
+ s->blame.lines, s->first_displayed_line,
s->selected_line, s->repo);
if (err)
break;
break;
case KEY_NPAGE:
case ' ':
- if (s->last_displayed_line >= blame.nlines &&
+ if (s->last_displayed_line >= s->blame.nlines &&
s->selected_line < view->nlines - 2) {
- s->selected_line = MIN(blame.nlines,
+ s->selected_line = MIN(s->blame.nlines,
view->nlines - 2);
break;
}
if (s->last_displayed_line + view->nlines - 2
- <= blame.nlines)
+ <= s->blame.nlines)
s->first_displayed_line +=
view->nlines - 2;
else
s->first_displayed_line =
- blame.nlines - (view->nlines - 3);
+ s->blame.nlines -
+ (view->nlines - 3);
break;
case KEY_RESIZE:
err = view_resize(view);
if (err)
break;
if (s->selected_line > view->nlines - 2) {
- s->selected_line = MIN(blame.nlines,
+ s->selected_line = MIN(s->blame.nlines,
view->nlines - 2);
}
break;
done:
if (pobj)
got_object_close(pobj);
- if (blame.thread)
- thread_err = stop_blame(&blame);
+ if (s->blame.thread)
+ thread_err = stop_blame(&s->blame);
return thread_err ? thread_err : err;
}