Skip to content

Commit

Permalink
gitweb: Always set 'from_file' and 'to_file' in parse_difftree_raw_line
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Jakub Narebski authored and Junio C Hamano committed Nov 2, 2007
1 parent 3e4bb08 commit 9d30145
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions gitweb/gitweb.perl
Original file line number Diff line number Diff line change
Expand Up @@ -1995,7 +1995,7 @@ sub parse_difftree_raw_line {
if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
($res{'from_file'}, $res{'to_file'}) = map { unquote($_) } split("\t", $7);
} else {
$res{'file'} = unquote($7);
$res{'from_file'} = $res{'to_file'} = $res{'file'} = unquote($7);
}
}
# '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'
Expand Down Expand Up @@ -2062,7 +2062,10 @@ sub parse_from_to_diffinfo {
fill_from_file_info($diffinfo, @parents)
unless exists $diffinfo->{'from_file'};
for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
$from->{'file'}[$i] = $diffinfo->{'from_file'}[$i] || $diffinfo->{'to_file'};
$from->{'file'}[$i] =
defined $diffinfo->{'from_file'}[$i] ?
$diffinfo->{'from_file'}[$i] :
$diffinfo->{'to_file'};
if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file
$from->{'href'}[$i] = href(action=>"blob",
hash_base=>$parents[$i],
Expand All @@ -2074,7 +2077,7 @@ sub parse_from_to_diffinfo {
}
} else {
# ordinary (not combined) diff
$from->{'file'} = $diffinfo->{'from_file'} || $diffinfo->{'file'};
$from->{'file'} = $diffinfo->{'from_file'};
if ($diffinfo->{'status'} ne "A") { # not new (added) file
$from->{'href'} = href(action=>"blob", hash_base=>$hash_parent,
hash=>$diffinfo->{'from_id'},
Expand All @@ -2084,7 +2087,7 @@ sub parse_from_to_diffinfo {
}
}

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

return defined $diffinfo && defined $patchinfo
&& ($diffinfo->{'to_file'} || $diffinfo->{'file'}) eq $patchinfo->{'to_file'};
&& $diffinfo->{'to_file'} eq $patchinfo->{'to_file'};
}


Expand Down Expand Up @@ -4667,8 +4670,8 @@ sub git_blobdiff {
}

%diffinfo = parse_difftree_raw_line($difftree[0]);
$file_parent ||= $diffinfo{'from_file'} || $file_name || $diffinfo{'file'};
$file_name ||= $diffinfo{'to_file'} || $diffinfo{'file'};
$file_parent ||= $diffinfo{'from_file'} || $file_name;
$file_name ||= $diffinfo{'to_file'};

$hash_parent ||= $diffinfo{'from_id'};
$hash ||= $diffinfo{'to_id'};
Expand Down

0 comments on commit 9d30145

Please sign in to comment.