Skip to content

Commit 6073bf6

Browse files
wincentgitster
authored andcommitted
git-jump: make diff work with filenames containing spaces
In diff.c, we output a trailing "\t" at the end of any filename that contains a space: case DIFF_SYMBOL_FILEPAIR_PLUS: meta = diff_get_color_opt(o, DIFF_METAINFO); reset = diff_get_color_opt(o, DIFF_RESET); fprintf(o->file, "%s%s+++ %s%s%s\n", diff_line_prefix(o), meta, line, reset, strchr(line, ' ') ? "\t" : ""); break; That is, for a file "foo.txt" we'll emit: +++ a/foo.txt but for "foo bar.txt" we'll emit: +++ a/foo bar.txt\t This in turn leads us to produce a quickfix format like this: foo bar.txt\t:1:1:contents Because no "foo bar.txt\t" file actually exists on disk, opening it in Vim will just land the user in an empty buffer. This commit takes the simple approach of unconditionally stripping any trailing tab. Consider the following three examples: 1. For file "foo bar", Git will emit "foo bar\t". 2. For file "foo\t", Git will emit "foo\t". 3. For file "foo bar\t", Git will emit "foo bar\t\t". Before this commit, `git-jump` correctly handled only case "2". After this commit, `git-jump` correctly handles cases "1" and "3". In reality, "1" is the only case people are going to run into with any regularity, and the other two are extreme edge cases. The argument here is that stripping the "\t" unconditionally gives us a minimal change, and it addresses the common case without bringing in complexity for the uncommon ones. If anybody ever complains about case "2" no longer working for them, we can do the more complicated thing and only strip the "\t" if the filename contains a space. Signed-off-by: Greg Hurrell <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent fbe8d30 commit 6073bf6

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

contrib/git-jump/git-jump

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ open_editor() {
4444
mode_diff() {
4545
git diff --no-prefix --relative "$@" |
4646
perl -ne '
47-
if (m{^\+\+\+ (.*)}) { $file = $1 eq "/dev/null" ? undef : $1; next }
47+
if (m{^\+\+\+ (.*?)\t?$}) { $file = $1 eq "/dev/null" ? undef : $1; next }
4848
defined($file) or next;
4949
if (m/^@@ .*?\+(\d+)/) { $line = $1; next }
5050
defined($line) or next;

0 commit comments

Comments
 (0)