{"thread":{"id":"9969","subject":"[PATCH 4/5] gitweb: Always set 'from_file' and 'to_file' in parse_difftree_raw_line","startedAt":"2007-09-21T21:39:49Z","lastAt":"2007-09-21T21:39:49Z","messageCount":1,"participants":["Jakub Narebski"],"isPatch":true,"patchVersion":1,"patchTotal":5},"messages":[{"id":"53757","messageId":"8fe92b430709211439v3c826dddw83e593d655bc6124@mail.gmail.com","threadId":"9969","inReplyTo":null,"subject":"[PATCH 4/5] gitweb: Always set 'from_file' and 'to_file' in parse_difftree_raw_line","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2007-09-21T21:39:49Z","receivedAt":"2007-09-21T21:39:49Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"Always set 'from_file' and 'to_file' keys when parsing raw diff output\nformat line, even if filename didn't change (file was not renamed).\nThis allows for less code (and no problems with file named '0'); use\nthis.\n\nSigned-off-by: Jakub Narebski <jnareb@gmail.com>\n---\nThis simplifies code a bit _and_ fortifies gitweb against filenames\nlike '0' (although it does remove _fragments_ of lines, not lines\nthemselves, so it is not visible in diffstat).\n\n gitweb/gitweb.perl |   17 ++++++++++-------\n 1 files changed, 10 insertions(+), 7 deletions(-)\n\n\nFrom 9753f8b6a67239a4ed1ad5489965db37f7cbea89 Mon Sep 17 00:00:00 2001\nFrom: Jakub Narebski <jnareb@gmail.com>\nDate: Thu, 13 Sep 2007 21:57:03 +0200\nSubject: [PATCH 4/5] gitweb: Always set 'from_file' and 'to_file' in parse_difftree_raw_line\n\nAlways set 'from_file' and 'to_file' keys when parsing raw diff output\nformat line, even if filename didn't change (file was not renamed).\nThis allows for less code (and no problems with file named '0'); use\nthis.\n\nSigned-off-by: Jakub Narebski <jnareb@gmail.com>\n---\nThis simplifies code a bit _and_ fortifies gitweb against filenames\nlike '0' (although it does remove _fragments_ of lines, not lines\nthemselves, so it is not visible in diffstat).\n\n gitweb/gitweb.perl |   17 ++++++++++-------\n 1 files changed, 10 insertions(+), 7 deletions(-)\n\ndiff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl\nindex 1b5642a..6c79a95 100755\n--- a/gitweb/gitweb.perl\n+++ b/gitweb/gitweb.perl\n@@ -1968,7 +1968,7 @@ sub parse_difftree_raw_line {\n \t\tif ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied\n \t\t\t($res{'from_file'}, $res{'to_file'}) = map { unquote($_) } split(\"\\t\", $7);\n \t\t} else {\n-\t\t\t$res{'file'} = unquote($7);\n+\t\t\t$res{'from_file'} = $res{'to_file'} = $res{'file'} = unquote($7);\n \t\t}\n \t}\n \t# '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR\tgit-gui/git-gui.sh'\n@@ -2035,7 +2035,10 @@ sub parse_from_to_diffinfo {\n \t\tfill_from_file_info($diffinfo, @parents)\n \t\t\tunless exists $diffinfo->{'from_file'};\n \t\tfor (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {\n-\t\t\t$from->{'file'}[$i] = $diffinfo->{'from_file'}[$i] || $diffinfo->{'to_file'};\n+\t\t\t$from->{'file'}[$i] = \n+\t\t\t\tdefined $diffinfo->{'from_file'}[$i] ?\n+\t\t\t\t        $diffinfo->{'from_file'}[$i] :\n+\t\t\t\t        $diffinfo->{'to_file'};\n \t\t\tif ($diffinfo->{'status'}[$i] ne \"A\") { # not new (added) file\n \t\t\t\t$from->{'href'}[$i] = href(action=>\"blob\",\n \t\t\t\t                           hash_base=>$parents[$i],\n@@ -2047,7 +2050,7 @@ sub parse_from_to_diffinfo {\n \t\t}\n \t} else {\n \t\t# ordinary (not combined) diff\n-\t\t$from->{'file'} = $diffinfo->{'from_file'} || $diffinfo->{'file'};\n+\t\t$from->{'file'} = $diffinfo->{'from_file'};\n \t\tif ($diffinfo->{'status'} ne \"A\") { # not new (added) file\n \t\t\t$from->{'href'} = href(action=>\"blob\", hash_base=>$hash_parent,\n \t\t\t                       hash=>$diffinfo->{'from_id'},\n@@ -2057,7 +2060,7 @@ sub parse_from_to_diffinfo {\n \t\t}\n \t}\n \n-\t$to->{'file'} = $diffinfo->{'to_file'} || $diffinfo->{'file'};\n+\t$to->{'file'} = $diffinfo->{'to_file'};\n \tif (!is_deleted($diffinfo)) { # file exists in result\n \t\t$to->{'href'} = href(action=>\"blob\", hash_base=>$hash,\n \t\t                     hash=>$diffinfo->{'to_id'},\n@@ -2802,7 +2805,7 @@ sub is_patch_split {\n \tmy ($diffinfo, $patchinfo) = @_;\n \n \treturn defined $diffinfo && defined $patchinfo\n-\t\t&& ($diffinfo->{'to_file'} || $diffinfo->{'file'}) eq $patchinfo->{'to_file'};\n+\t\t&& $diffinfo->{'to_file'} eq $patchinfo->{'to_file'};\n }\n \n \n@@ -4637,8 +4640,8 @@ sub git_blobdiff {\n \t\t}\n \n \t\t%diffinfo = parse_difftree_raw_line($difftree[0]);\n-\t\t$file_parent ||= $diffinfo{'from_file'} || $file_name || $diffinfo{'file'};\n-\t\t$file_name   ||= $diffinfo{'to_file'}   || $diffinfo{'file'};\n+\t\t$file_parent ||= $diffinfo{'from_file'} || $file_name;\n+\t\t$file_name   ||= $diffinfo{'to_file'};\n \n \t\t$hash_parent ||= $diffinfo{'from_id'};\n \t\t$hash        ||= $diffinfo{'to_id'};\n-- \n1.5.3\n\n"}]}