Commit 2246482eaf5f2c63df9af5b3436312be16907a56

Stefan Sperling 2019-06-25T12:27:42

make search actually work in 'tog blame'

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;
 	}