make search actually work in 'tog blame'
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
diff --git a/lib/object.c b/lib/object.c
index 1a425fa..691ab91 100644
--- a/lib/object.c
+++ b/lib/object.c
@@ -1160,7 +1160,7 @@ got_object_blob_dump_to_file(size_t *total_len, int *nlines,
if (len == 0)
break;
buf = got_object_blob_get_read_buf(blob);
- for (i = 0; i < len; i++) {
+ for (i = hdrlen; i < len; i++) {
if (buf[i] != '\n')
continue;
if (nlines)
@@ -1179,7 +1179,7 @@ got_object_blob_dump_to_file(size_t *total_len, int *nlines,
}
if (line_offsets && nlines && total_len) {
(*line_offsets)[*nlines - 1] = off;
- off = *total_len + i + 1;
+ off = *total_len + i + 1 - got_object_blob_get_hdrlen(blob);
}
}
if (total_len)
diff --git a/tog/tog.c b/tog/tog.c
index 8268cae..77aba92 100644
--- a/tog/tog.c
+++ b/tog/tog.c
@@ -3246,7 +3246,6 @@ match_line(const char *line, regex_t *regex)
static const struct got_error *
search_next_blame_view(struct tog_view *view)
{
- const struct got_error *err = NULL;
struct tog_blame_view_state *s = &view->state.blame;
int lineno;
@@ -3257,9 +3256,9 @@ search_next_blame_view(struct tog_view *view)
if (s->matched_line) {
if (view->searching == TOG_SEARCH_FORWARD)
- lineno = s->first_displayed_line - 1 + s->selected_line + 1;
+ lineno = s->matched_line + 1;
else
- lineno = s->first_displayed_line - 1 + s->selected_line - 1;
+ lineno = s->matched_line - 1;
} else {
if (view->searching == TOG_SEARCH_FORWARD)
lineno = 1;
@@ -3278,6 +3277,7 @@ search_next_blame_view(struct tog_view *view)
free(line);
break;
}
+
if (view->searching == TOG_SEARCH_FORWARD)
lineno = 1;
else
@@ -3291,16 +3291,13 @@ search_next_blame_view(struct tog_view *view)
}
free(line);
line = parse_next_line(s->blame.f, &len);
- if (line == NULL)
- break;
- if (match_line(line, &view->regex)) {
+ if (line && match_line(line, &view->regex)) {
view->search_next_done = 1;
s->matched_line = lineno;
free(line);
break;
}
free(line);
- line = NULL;
if (view->searching == TOG_SEARCH_FORWARD)
lineno++;
else
@@ -3308,19 +3305,6 @@ search_next_blame_view(struct tog_view *view)
}
if (s->matched_line) {
- int cur = s->first_displayed_line - 1 + s->selected_line;
- while (cur < s->matched_line) {
- err = input_blame_view(NULL, NULL, NULL, view, KEY_DOWN);
- if (err)
- return err;
- cur++;
- }
- while (cur > s->matched_line) {
- err = input_blame_view(NULL, NULL, NULL, view, KEY_UP);
- if (err)
- return err;
- cur--;
- }
s->first_displayed_line = s->matched_line;
s->selected_line = 1;
}