show commit id in blame view header
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
diff --git a/tog/tog.c b/tog/tog.c
index 4c0093a..1c84a1f 100644
--- a/tog/tog.c
+++ b/tog/tog.c
@@ -1090,7 +1090,7 @@ struct tog_blame_line {
};
static const struct got_error *
-draw_blame(WINDOW *window, FILE *f, const char *path,
+draw_blame(WINDOW *window, struct got_object_id *id, FILE *f, const char *path,
struct tog_blame_line *lines, int nlines, int blame_complete,
int selected_line, int *first_displayed_line, int *last_displayed_line,
int *eof, int max_lines)
@@ -1103,14 +1103,34 @@ draw_blame(WINDOW *window, FILE *f, const char *path,
int width, wlimit;
struct tog_blame_line *blame_line;
struct got_object_id *prev_id = NULL;
+ char *id_str;
+
+ err = got_object_id_str(&id_str, id);
+ if (err)
+ return err;
rewind(f);
werase(window);
- if (asprintf(&line, "[%d-%d/%d] annotation of %s%s",
+ if (asprintf(&line, "commit: %s", id_str) == -1) {
+ err = got_error_from_errno();
+ free(id_str);
+ return err;
+ }
+
+ err = format_line(&wline, &width, line, COLS);
+ free(line);
+ waddwstr(window, wline);
+ if (width < COLS)
+ waddch(window, '\n');
+
+ if (asprintf(&line, "[%d-%d/%d] %s%s",
*first_displayed_line, *last_displayed_line, nlines,
- path, blame_complete ? "" : " in progress...") == -1)
+ path, blame_complete ? "" : " annotating...") == -1) {
+ free(id_str);
return got_error_from_errno();
+ }
+ free(id_str);
err = format_line(&wline, &width, line, COLS);
free(line);
if (err)
@@ -1120,7 +1140,7 @@ draw_blame(WINDOW *window, FILE *f, const char *path,
waddch(window, '\n');
*eof = 0;
- while (nprinted < max_lines - 1) {
+ while (nprinted < max_lines - 2) {
line = parse_next_line(f, &len);
if (line == NULL) {
*eof = 1;
@@ -1184,6 +1204,7 @@ struct tog_blame_cb_args {
struct tog_blame_line *lines; /* one per line */
int nlines;
+ struct got_object_id *commit_id;
FILE *f;
const char *path;
WINDOW *window;
@@ -1227,9 +1248,9 @@ blame_cb(void *arg, int nlines, int lineno, struct got_object_id *id)
}
line->annotated = 1;
- err = draw_blame(a->window, a->f, a->path, a->lines, a->nlines, 0,
- *a->selected_line, a->first_displayed_line, a->last_displayed_line,
- &eof, LINES);
+ err = draw_blame(a->window, a->commit_id, a->f, a->path, a->lines,
+ a->nlines, 0, *a->selected_line, a->first_displayed_line,
+ a->last_displayed_line, &eof, LINES);
done:
if (pthread_mutex_unlock(a->mutex) != 0)
return got_error_from_errno();
@@ -1238,7 +1259,6 @@ done:
struct tog_blame_thread_args {
const char *path;
- struct got_object_id *commit_id;
struct got_repository *repo;
void *blame_cb_args;
int *complete;
@@ -1252,7 +1272,7 @@ blame_thread(void *arg)
struct tog_blame_cb_args *a = ta->blame_cb_args;
int eof;
- err = got_blame_incremental(ta->path, ta->commit_id, ta->repo,
+ err = got_blame_incremental(ta->path, a->commit_id, ta->repo,
blame_cb, ta->blame_cb_args);
*ta->complete = 1;
if (err)
@@ -1261,8 +1281,9 @@ blame_thread(void *arg)
if (pthread_mutex_lock(a->mutex) != 0)
return (void *)got_error_from_errno();
- err = draw_blame(a->window, a->f, a->path, a->lines, a->nlines, 1,
- *a->selected_line, a->first_displayed_line, a->last_displayed_line,
+ err = draw_blame(a->window, a->commit_id, a->f, a->path, a->lines,
+ a->nlines, 1, *a->selected_line, a->first_displayed_line,
+ a->last_displayed_line,
&eof, LINES);
if (pthread_mutex_unlock(a->mutex) != 0 && err == NULL)
@@ -1378,6 +1399,7 @@ show_blame_view(const char *path, struct got_object_id *commit_id,
blame_cb_args.lines = lines;
blame_cb_args.nlines = nlines;
blame_cb_args.mutex = &mutex;
+ blame_cb_args.commit_id = commit_id;
blame_cb_args.f = f;
blame_cb_args.path = path;
blame_cb_args.window = tog_blame_view.window;
@@ -1387,7 +1409,6 @@ show_blame_view(const char *path, struct got_object_id *commit_id,
blame_cb_args.quit = &done;
blame_thread_args.path = path;
- blame_thread_args.commit_id = commit_id;
blame_thread_args.repo = blame_thread_repo;
blame_thread_args.blame_cb_args = &blame_cb_args;
blame_thread_args.complete = &blame_complete;
@@ -1403,9 +1424,9 @@ show_blame_view(const char *path, struct got_object_id *commit_id,
err = got_error_from_errno();
goto done;
}
- err = draw_blame(tog_blame_view.window, f, path, lines, nlines,
- blame_complete, selected_line, &first_displayed_line,
- &last_displayed_line, &eof, LINES);
+ err = draw_blame(tog_blame_view.window, commit_id, f, path,
+ lines, nlines, blame_complete, selected_line,
+ &first_displayed_line, &last_displayed_line, &eof, LINES);
if (pthread_mutex_unlock(&mutex) != 0) {
err = got_error_from_errno();
goto done;