{"thread":{"id":"34697","subject":"[PATCH 1/2] gitweb: add filename search function","startedAt":"2013-08-15T03:02:38Z","lastAt":"2013-09-03T20:07:48Z","messageCount":2,"participants":["Christopher Durkin","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"225243","messageId":"CANzJMBWDgtjbNwPLjoKniwy5xCGKyz0yBFiMBfdGJMi5Q=W4+Q@mail.gmail.com","threadId":"34697","inReplyTo":null,"subject":"[PATCH 1/2] gitweb: add filename search function","fromName":"Christopher Durkin","fromEmail":"cjdurkin@gmail.com","sentAt":"2013-08-15T03:02:38Z","receivedAt":"2013-08-15T03:02:38Z","isPatch":true,"sender":{"key":"cjdurkin@gmail.com","avatar":"https://gravatar.com/avatar/32f0587f5e156c4ed56a0eece797261355fcccfda463b83d63bf88a59121d039?d=mp&s=160"},"body":"Add another item to the search drop-down (author/committer/etc)\nto search for file names instead of file content. Output is similar\nto the grep contents output, with each entry linking to the file.\n---\n gitweb/gitweb.perl | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++\n 1 file changed, 59 insertions(+)\n\ndiff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl\nindex f429f75..4a7b0a5 100755\n--- a/gitweb/gitweb.perl\n+++ b/gitweb/gitweb.perl\n@@ -6360,6 +6360,65 @@ sub git_search_grep_body {\n  print \"</table>\\n\";\n }\n\n+sub git_search_filenames {\n+    my %co = @_;\n+    local $/ = \"\\n\";\n+    my $match_limit = 1000;\n+\n+    open my $fd, \"-|\", git_cmd(), 'ls-tree', '--name-only',\n'--full-name', '-r',\n+      $co{'tree'} or die_error(500, \"Open git-ls-tree failed\");\n+\n+    git_header_html();\n+\n+    git_print_page_nav('','', $hash,$co{'tree'},$hash);\n+    git_print_header_div('commit', esc_html($co{'title'}), $hash);\n+\n+    print \"<table class=\\\"filename_search\\\">\\n\";\n+    my $matches = 0;\n+    my $alternate = 1;\n+    my $file_href;\n+\n+    while (my $filename = <$fd>) {\n+        chomp $filename;\n+\n+        if ($matches > $match_limit) {\n+            print \"<div class=\\\"diff nodifferences\\\">Too many\nmatches, listing trimmed</div>\\n\";\n+            last;\n+        }\n+\n+        if ($search_use_regexp) {\n+            next unless ($filename =~ /$searchtext/);\n+        } else {\n+            next unless index($filename,$searchtext) >= 0;\n+        }\n+\n+        $matches++;\n+        $file_href = href(action=>\"blob\", hash_base=>$co{'id'},\n+                          file_name=>$filename);\n+\n+ if ($alternate) {\n+    print \"<tr class=\\\"dark\\\">\\n\";\n+ } else {\n+    print \"<tr class=\\\"light\\\">\\n\";\n+ }\n+ $alternate ^= 1;\n+\n+        print \"<td class=\\\"list\\\">\".\n+            $cgi->a({-href => $file_href, -class => \"list\"},\nesc_path($filename));\n+ print \"</td>\\n\";\n+ print \"</tr>\\n\";\n+    }\n+\n+    if ($matches == 0) {\n+        print \"<div class=\\\"diff nodifferences\\\">No matches found</div>\\n\";\n+    }\n+    close $fd;\n+\n+    print \"</table>\\n\";\n+\n+    git_footer_html();\n+}\n+\n ## ======================================================================\n ## ======================================================================\n ## actions\n-- \n1.8.3.msysgit.0\n"},{"id":"226668","messageId":"xmqqbo49r7mz.fsf@gitster.dls.corp.google.com","threadId":"34697","inReplyTo":"CANzJMBWDgtjbNwPLjoKniwy5xCGKyz0yBFiMBfdGJMi5Q=W4+Q@mail.gmail.com","subject":"Re: [PATCH 1/2] gitweb: add filename search function","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2013-09-03T20:07:48Z","receivedAt":"2013-09-03T20:07:48Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Christopher Durkin <cjdurkin@gmail.com> writes:\n\n> Add another item to the search drop-down (author/committer/etc)\n> to search for file names instead of file content. Output is similar\n> to the grep contents output, with each entry linking to the file.\n> ---\n\nMissing sign-off.\n\n>  gitweb/gitweb.perl | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++\n>  1 file changed, 59 insertions(+)\n>\n> diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl\n> index f429f75..4a7b0a5 100755\n> --- a/gitweb/gitweb.perl\n> +++ b/gitweb/gitweb.perl\n> @@ -6360,6 +6360,65 @@ sub git_search_grep_body {\n>   print \"</table>\\n\";\n\nI think this file is indented with HT, not a single SP.\n\n>  }\n>\n> +sub git_search_filenames {\n> +    my %co = @_;\n\n... nor four SP.  One level of indent is a single HT.\n\n> +    local $/ = \"\\n\";\n> +    my $match_limit = 1000;\n> +\n> +    open my $fd, \"-|\", git_cmd(), 'ls-tree', '--name-only',\n> '--full-name', '-r',\n\nLine-wrapped broken patch that cannot be applied (I see there are a\nfew more similar ones below).\n\n> +      $co{'tree'} or die_error(500, \"Open git-ls-tree failed\");\n> +\n> +    git_header_html();\n> +\n> +    git_print_page_nav('','', $hash,$co{'tree'},$hash);\n> +    git_print_header_div('commit', esc_html($co{'title'}), $hash);\n> +\n> +    print \"<table class=\\\"filename_search\\\">\\n\";\n> +    my $matches = 0;\n> +    my $alternate = 1;\n> +    my $file_href;\n> +\n> +    while (my $filename = <$fd>) {\n> +        chomp $filename;\n> +\n> +        if ($matches > $match_limit) {\n> +            print \"<div class=\\\"diff nodifferences\\\">Too many\n> matches, listing trimmed</div>\\n\";\n> +            last;\n> +        }\n> +\n> +        if ($search_use_regexp) {\n> +            next unless ($filename =~ /$searchtext/);\n> +        } else {\n> +            next unless index($filename,$searchtext) >= 0;\n> +        }\n> +\n> +        $matches++;\n> +        $file_href = href(action=>\"blob\", hash_base=>$co{'id'},\n> +                          file_name=>$filename);\n> +\n> + if ($alternate) {\n> +    print \"<tr class=\\\"dark\\\">\\n\";\n> + } else {\n> +    print \"<tr class=\\\"light\\\">\\n\";\n> + }\n> + $alternate ^= 1;\n> +\n> +        print \"<td class=\\\"list\\\">\".\n> +            $cgi->a({-href => $file_href, -class => \"list\"},\n> esc_path($filename));\n> + print \"</td>\\n\";\n> + print \"</tr>\\n\";\n> +    }\n> +\n> +    if ($matches == 0) {\n> +        print \"<div class=\\\"diff nodifferences\\\">No matches found</div>\\n\";\n> +    }\n> +    close $fd;\n> +\n> +    print \"</table>\\n\";\n> +\n> +    git_footer_html();\n> +}\n> +\n>  ## ======================================================================\n>  ## ======================================================================\n>  ## actions\n"}]}