From 2c837090d2cdd963b16e867d11cbcc414d3d81a5 Mon Sep 17 00:00:00 2001 From: Roland Walker Date: Sat, 22 Jul 2017 12:58:18 -0400 Subject: [PATCH] improve context-sensitivity of view-blob --- src/diff.c | 16 ++-- test/diff/diff-view-blob-test | 139 ++++++++++++++++++++++++++++++++++ 2 files changed, 147 insertions(+), 8 deletions(-) create mode 100755 test/diff/diff-view-blob-test diff --git a/src/diff.c b/src/diff.c index 583f1e0e0..29e002691 100644 --- a/src/diff.c +++ b/src/diff.c @@ -624,16 +624,16 @@ diff_get_pathname(struct view *view, struct line *line) int i; header = find_prev_line_by_type(view, line, LINE_DIFF_HEADER); - if (!header) - return NULL; - for (i = 0; i < ARRAY_SIZE(prefixes); i++) { - dst = strstr(box_text(header), prefixes[i]); - if (dst) - return dst + strlen(prefixes[i]); - } + if (header) + for (i = 0; i < ARRAY_SIZE(prefixes); i++) { + dst = strstr(box_text(header), prefixes[i]); + if (dst) + return dst + strlen(prefixes[i]); + } + + header = find_next_line_by_type(view, header ? header : line, LINE_DIFF_ADD_FILE); - header = find_next_line_by_type(view, header, LINE_DIFF_ADD_FILE); if (!header) return NULL; diff --git a/test/diff/diff-view-blob-test b/test/diff/diff-view-blob-test new file mode 100755 index 000000000..95b42ec34 --- /dev/null +++ b/test/diff/diff-view-blob-test @@ -0,0 +1,139 @@ +#!/bin/sh + +. libtest.sh +. libgit.sh + +export LINES=10 + +in_work_dir create_repo_from_tgz "$base_dir/files/scala-js-benchmarks.tgz" + +# content window scrolled to avoid trailing backslash and single quote +first_file_blob=' +# Run a benchmark against a JavaScript VM. + +# set -x + +RUN_DIR="$(dirname "$0")" +ROOT_DIR="./$(git rev-parse --show-cdup)" +ENGINES="d8 node" +[blob] common/benchmark-runner.sh - line 9 of 143 11%' + +last_file_blob='// The ray tracer code in this file is written by Adam Burmister. It +// is available in its original form from: +// +// http://labs.flog.co.nz/raytracer/ +// +// Ported from the v8 benchmark suite by Google 2012. +// Ported from the Dart benchmark_harness to Scala.js by Jonas Fonseca 2013 + +[blob] tracer/src/main/scala/org/scalajs/benchmark/tracer/Tracer.scala - line38%' + +test_case view-blob-goto-line-1 \ + --args='show ee912870202200a0b9cf4fd86ba57243212d341e' \ + --script=' + :1 + :view-blob + :scroll-page-down + ' \ + <