Diff options
| author | Bryce Kwon <bryce@brycekwon.com> | |
|---|---|---|
| committer | Bryce Kwon <bryce@brycekwon.com> | |
| commit | ||
| parent | ||
| tree | ||
| download | ||
Keep a followed diff to the path it names
A followed diff kept every path that started with the requested one,
so following small.c took small.cpp in as well. A path now has to be
the requested one or lie below it, as the pathspec of an unfollowed
diff matches.
Diffstat (limited to 'source')
| -rw-r--r-- | source/ui-diff.c | 15 |
1 file changed, 13 insertions, 2 deletions
diff --git a/source/ui-diff.c b/source/ui-diff.c index c696ab1..2974744 100644 --- a/source/ui-diff.c +++ b/source/ui-diff.c @@ -178,12 +178,23 @@ static void count_diff_lines(char *line, int len) render_line_fn(line, len); } +/* + * A path is kept when it is the prefix itself or lies below it, as the + * pathspec of a diff that does not follow would match it. + */ +static int path_in_prefix(const char *path, const char *prefix) +{ + const char *rest; + + return skip_prefix(path, prefix, &rest) && (!*rest || *rest == '/'); +} + static int show_filepair(struct diff_filepair *pair) { if (!current_prefix) return 1; - return starts_with(pair->one->path, current_prefix) || - starts_with(pair->two->path, current_prefix); + return path_in_prefix(pair->one->path, current_prefix) || + path_in_prefix(pair->two->path, current_prefix); } static void print_line(char *line, int len) |
