Skip to content

Commit 9d30145

Browse files
jnarebgitster
authored andcommitted
gitweb: Always set 'from_file' and 'to_file' in parse_difftree_raw_line
Always set 'from_file' and 'to_file' keys when parsing raw diff output format line, even if filename didn't change (file was not renamed). This allows for simpler code. Previously, you would have written: $diffinfo->{'from_file'} || $diffinfo->{'file'} but now you can just use $diffinfo->{'from_file'} as 'from_file' is always defined. While at it, replace (for merge commits) $diffinfo->{'from_file'}[$i] || $diffinfo->{'to_file'} by defined $diffinfo->{'from_file'}[$i] ? $diffinfo->{'from_file'}[$i] : $diffinfo->{'to_file'}; to have no problems with file named '0'. Signed-off-by: Jakub Narebski <jnareb@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 3e4bb08 commit 9d30145

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

gitweb/gitweb.perl

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1995,7 +1995,7 @@ sub parse_difftree_raw_line {
19951995
if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
19961996
($res{'from_file'}, $res{'to_file'}) = map { unquote($_) } split("\t", $7);
19971997
} else {
1998-
$res{'file'} = unquote($7);
1998+
$res{'from_file'} = $res{'to_file'} = $res{'file'} = unquote($7);
19991999
}
20002000
}
20012001
# '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'
@@ -2062,7 +2062,10 @@ sub parse_from_to_diffinfo {
20622062
fill_from_file_info($diffinfo, @parents)
20632063
unless exists $diffinfo->{'from_file'};
20642064
for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
2065-
$from->{'file'}[$i] = $diffinfo->{'from_file'}[$i] || $diffinfo->{'to_file'};
2065+
$from->{'file'}[$i] =
2066+
defined $diffinfo->{'from_file'}[$i] ?
2067+
$diffinfo->{'from_file'}[$i] :
2068+
$diffinfo->{'to_file'};
20662069
if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file
20672070
$from->{'href'}[$i] = href(action=>"blob",
20682071
hash_base=>$parents[$i],
@@ -2074,7 +2077,7 @@ sub parse_from_to_diffinfo {
20742077
}
20752078
} else {
20762079
# ordinary (not combined) diff
2077-
$from->{'file'} = $diffinfo->{'from_file'} || $diffinfo->{'file'};
2080+
$from->{'file'} = $diffinfo->{'from_file'};
20782081
if ($diffinfo->{'status'} ne "A") { # not new (added) file
20792082
$from->{'href'} = href(action=>"blob", hash_base=>$hash_parent,
20802083
hash=>$diffinfo->{'from_id'},
@@ -2084,7 +2087,7 @@ sub parse_from_to_diffinfo {
20842087
}
20852088
}
20862089

2087-
$to->{'file'} = $diffinfo->{'to_file'} || $diffinfo->{'file'};
2090+
$to->{'file'} = $diffinfo->{'to_file'};
20882091
if (!is_deleted($diffinfo)) { # file exists in result
20892092
$to->{'href'} = href(action=>"blob", hash_base=>$hash,
20902093
hash=>$diffinfo->{'to_id'},
@@ -2829,7 +2832,7 @@ sub is_patch_split {
28292832
my ($diffinfo, $patchinfo) = @_;
28302833

28312834
return defined $diffinfo && defined $patchinfo
2832-
&& ($diffinfo->{'to_file'} || $diffinfo->{'file'}) eq $patchinfo->{'to_file'};
2835+
&& $diffinfo->{'to_file'} eq $patchinfo->{'to_file'};
28332836
}
28342837

28352838

@@ -4667,8 +4670,8 @@ sub git_blobdiff {
46674670
}
46684671

46694672
%diffinfo = parse_difftree_raw_line($difftree[0]);
4670-
$file_parent ||= $diffinfo{'from_file'} || $file_name || $diffinfo{'file'};
4671-
$file_name ||= $diffinfo{'to_file'} || $diffinfo{'file'};
4673+
$file_parent ||= $diffinfo{'from_file'} || $file_name;
4674+
$file_name ||= $diffinfo{'to_file'};
46724675

46734676
$hash_parent ||= $diffinfo{'from_id'};
46744677
$hash ||= $diffinfo{'to_id'};

0 commit comments

Comments
 (0)