{"thread":{"id":"10555","subject":"[PATCH 1/2] gitweb: Always set 'from_file' and 'to_file' in parse_difftree_raw_line","startedAt":"2007-11-01T11:38:07Z","lastAt":"2007-11-01T23:46:25Z","messageCount":5,"participants":["Jakub Narebski","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"57801","messageId":"1193917089-15920-1-git-send-email-jnareb@gmail.com","threadId":"10555","inReplyTo":null,"subject":"[PATCH 0/2] gitweb: Simplify dealing with raw diff output","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2007-11-01T11:38:07Z","receivedAt":"2007-11-01T11:38:07Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"This series of patches simplifies (and improves) gitweb code dealing\nwith (parsed) raw diff output format.\n\nSee individual patches for more detail.\n\n\nTable of contents:\n [PATCH 1/2] gitweb: Always set 'from_file' and 'to_file'\n             in parse_difftree_raw_line \n [PATCH 2/2] gitweb: Add 'status_str' to parse_difftree_raw_line output\n\nDiffstat:\n gitweb/gitweb.perl |   22 +++++++++++++---------\n 1 files changed, 13 insertions(+), 9 deletions(-)\n\n-- \nJakub Narebski\nPoland\n"},{"id":"57800","messageId":"1193917089-15920-2-git-send-email-jnareb@gmail.com","threadId":"10555","inReplyTo":"1193917089-15920-1-git-send-email-jnareb@gmail.com","subject":"[PATCH 1/2] gitweb: Always set 'from_file' and 'to_file' in parse_difftree_raw_line","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2007-11-01T11:38:08Z","receivedAt":"2007-11-01T11:38:08Z","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 simpler code (and no problems with file named '0').\n\nUse\n  $diffinfo->{'from_file'}\ninstead of\n  $diffinfo->{'from_file'} || $diffinfo->{'file'}\nfrom now on.\n\nWhile at it, replace (for merge commits)\n  $diffinfo->{'from_file'}[$i] || $diffinfo->{'to_file'}\nby\n  defined $diffinfo->{'from_file'}[$i] ?\n          $diffinfo->{'from_file'}[$i] :\n          $diffinfo->{'to_file'};\nto have no problems woth file named '0'.\n\nSigned-off-by: Jakub Narebski <jnareb@gmail.com>\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 2e00756..79ea7ec 100755\n--- a/gitweb/gitweb.perl\n+++ b/gitweb/gitweb.perl\n@@ -1995,7 +1995,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@@ -2062,7 +2062,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@@ -2074,7 +2077,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@@ -2084,7 +2087,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@@ -2829,7 +2832,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@@ -4667,8 +4670,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.4\n"},{"id":"57802","messageId":"1193917089-15920-3-git-send-email-jnareb@gmail.com","threadId":"10555","inReplyTo":"1193917089-15920-1-git-send-email-jnareb@gmail.com","subject":"[PATCH 2/2] gitweb: Add 'status_str' to parse_difftree_raw_line output","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2007-11-01T11:38:09Z","receivedAt":"2007-11-01T11:38:09Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"Add 'status_str' to diffinfo output, which stores status (also for\nmerge commit) as a string.  This allows for easy checking if there is\ngiven status among all for merge commit, e.g.\n  $diffinfo->{'status_str'} =~ /D/;\n\nSigned-off-by: Jakub Narebski <jnareb@gmail.com>\n---\n gitweb/gitweb.perl |    5 +++--\n 1 files changed, 3 insertions(+), 2 deletions(-)\n\ndiff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl\nindex 79ea7ec..e36dec1 100755\n--- a/gitweb/gitweb.perl\n+++ b/gitweb/gitweb.perl\n@@ -1990,7 +1990,7 @@ sub parse_difftree_raw_line {\n \t\t$res{'to_mode'} = $2;\n \t\t$res{'from_id'} = $3;\n \t\t$res{'to_id'} = $4;\n-\t\t$res{'status'} = $5;\n+\t\t$res{'status'} = $res{'status_str'} = $5;\n \t\t$res{'similarity'} = $6;\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@@ -2006,6 +2006,7 @@ sub parse_difftree_raw_line {\n \t\t$res{'to_mode'} = pop @{$res{'from_mode'}};\n \t\t$res{'from_id'} = [ split(' ', $3) ];\n \t\t$res{'to_id'} = pop @{$res{'from_id'}};\n+\t\t$res{'status_str'} = $4;\n \t\t$res{'status'} = [ split('', $4) ];\n \t\t$res{'to_file'} = unquote($5);\n \t}\n@@ -2821,7 +2822,7 @@ sub fill_from_file_info {\n sub is_deleted {\n \tmy $diffinfo = shift;\n \n-\treturn $diffinfo->{'to_id'} eq ('0' x 40);\n+\treturn $diffinfo->{'status_str'} =~ /D/;\n }\n \n # does patch correspond to [previous] difftree raw line\n-- \n1.5.3.4\n"},{"id":"57893","messageId":"7v7il18twn.fsf@gitster.siamese.dyndns.org","threadId":"10555","inReplyTo":"1193917089-15920-2-git-send-email-jnareb@gmail.com","subject":"Re: [PATCH 1/2] gitweb: Always set 'from_file' and 'to_file' in parse_difftree_raw_line","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-11-01T22:47:52Z","receivedAt":"2007-11-01T22:47:52Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jakub Narebski <jnareb@gmail.com> writes:\n\n> Always set 'from_file' and 'to_file' keys when parsing raw diff output\n> format line, even if filename didn't change (file was not renamed).\n> This allows for simpler code (and no problems with file named '0').\n>\n> Use\n>   $diffinfo->{'from_file'}\n> instead of\n>   $diffinfo->{'from_file'} || $diffinfo->{'file'}\n> from now on.\n\nIsn't this description the other way around?\n"},{"id":"57899","messageId":"200711020046.26083.jnareb@gmail.com","threadId":"10555","inReplyTo":"7v7il18twn.fsf@gitster.siamese.dyndns.org","subject":"Re: [PATCH 1/2] gitweb: Always set 'from_file' and 'to_file' in parse_difftree_raw_line","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2007-11-01T23:46:25Z","receivedAt":"2007-11-01T23:46:25Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"Junio C Hamano wrote:\n> Jakub Narebski <jnareb@gmail.com> writes:\n> \n>> Always set 'from_file' and 'to_file' keys when parsing raw diff output\n>> format line, even if filename didn't change (file was not renamed).\n>> This allows for simpler code (and no problems with file named '0').\n>>\n>> Use\n>>   $diffinfo->{'from_file'}\n>> instead of\n>>   $diffinfo->{'from_file'} || $diffinfo->{'file'}\n>> from now on.\n> \n> Isn't this description the other way around?\n\nDescription is in good direction, although I agree that it is\na bit awkward. Perhaps it should read:\n\nInstead of\n  $diffinfo->{'from_file'} || $diffinfo->{'file'}\nit is now enough to use\n  $diffinfo->{'from_file'}\n\n(because $diffinfo->{'from_file'} is now _always_ set, not only for\nrenames and copies, when from_name and to_name differ).\n\n-- \nJakub Narebski\nPoland\n"}]}