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>
Jakub Narebski committed
Nov 1, 2007 at 12:38 UTC
9d3014566302ad0d3d378b0a1653959b3118066d
1 file changed
+10
-7
gitweb/gitweb.perl
+10
-7
@@ -1995,7 +1995,7 @@ sub parse_difftree_raw_line {
1995
if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
1996
($res{'from_file'}, $res{'to_file'}) = map { unquote($_) } split("\t", $7);
1997
} else {
1998
- $res{'file'} = unquote($7);
1998
+ $res{'from_file'} = $res{'to_file'} = $res{'file'} = unquote($7);
1999
}
2000
}
2001
# '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'
@@ -2062,7 +2062,10 @@ sub parse_from_to_diffinfo {
2062
fill_from_file_info($diffinfo, @parents)
2063
unless exists $diffinfo->{'from_file'};
2064
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'};
2069
if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file
2070
$from->{'href'}[$i] = href(action=>"blob",
2071
hash_base=>$parents[$i],
@@ -2074,7 +2077,7 @@ sub parse_from_to_diffinfo {
2077
}
2078
} else {
2079
# ordinary (not combined) diff
2077
- $from->{'file'} = $diffinfo->{'from_file'} || $diffinfo->{'file'};
2080
+ $from->{'file'} = $diffinfo->{'from_file'};
2081
if ($diffinfo->{'status'} ne "A") { # not new (added) file
2082
$from->{'href'} = href(action=>"blob", hash_base=>$hash_parent,
2083
hash=>$diffinfo->{'from_id'},
@@ -2084,7 +2087,7 @@ sub parse_from_to_diffinfo {
2087
}
2088
}
2089
2087
- $to->{'file'} = $diffinfo->{'to_file'} || $diffinfo->{'file'};
2090
+ $to->{'file'} = $diffinfo->{'to_file'};
2091
if (!is_deleted($diffinfo)) { # file exists in result
2092
$to->{'href'} = href(action=>"blob", hash_base=>$hash,
2093
hash=>$diffinfo->{'to_id'},
@@ -2829,7 +2832,7 @@ sub is_patch_split {
2832
my ($diffinfo, $patchinfo) = @_;
2833
2834
return defined $diffinfo && defined $patchinfo
2832
- && ($diffinfo->{'to_file'} || $diffinfo->{'file'}) eq $patchinfo->{'to_file'};
2835
+ && $diffinfo->{'to_file'} eq $patchinfo->{'to_file'};
2836
}
2837
2838
@@ -4667,8 +4670,8 @@ sub git_blobdiff {
4670
}
4671
4672
%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'};
4675
4676
$hash_parent ||= $diffinfo{'from_id'};
4677
$hash ||= $diffinfo{'to_id'};