{"thread":{"id":"8212","subject":"[PATCH 2/3] gitweb: Lift any characters restriction on searched strings","startedAt":"2007-05-19T00:13:29Z","lastAt":"2007-05-19T00:13:39Z","messageCount":3,"participants":["Petr Baudis"],"isPatch":true,"patchVersion":1,"patchTotal":3},"messages":[{"id":"42567","messageId":"20070519001329.28618.31334.stgit@rover","threadId":"8212","inReplyTo":null,"subject":"[PATCH 1/3] git-rev-list: Add regexp tuning options","fromName":"Petr Baudis","fromEmail":"pasky@suse.cz","sentAt":"2007-05-19T00:13:29Z","receivedAt":"2007-05-19T00:13:29Z","isPatch":true,"sender":{"key":"pasky@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/18439?v=4"},"body":"This patch introduces --extended-regexp and --regexp-ignore-case options to\ntune what kind of patterns the pattern-limiting options (--grep, --author,\n...) accept.\n\nSigned-off-by: Petr Baudis <pasky@suse.cz>\n---\n\n Documentation/git-rev-list.txt |   10 ++++++++++\n revision.c                     |   12 ++++++++++++\n 2 files changed, 22 insertions(+), 0 deletions(-)\n\ndiff --git a/Documentation/git-rev-list.txt b/Documentation/git-rev-list.txt\nindex c3c2043..0dba73f 100644\n--- a/Documentation/git-rev-list.txt\n+++ b/Documentation/git-rev-list.txt\n@@ -25,6 +25,7 @@ SYNOPSIS\n \t     [ \\--cherry-pick ]\n \t     [ \\--encoding[=<encoding>] ]\n \t     [ \\--(author|committer|grep)=<pattern> ]\n+\t     [ \\--regexp-ignore-case ] [ \\--extended-regexp ]\n \t     [ \\--date={local|relative|default} ]\n \t     [ [\\--objects | \\--objects-edge] [ \\--unpacked ] ]\n \t     [ \\--pretty | \\--header ]\n@@ -214,6 +215,15 @@ limiting may be applied.\n \tLimit the commits output to ones with log message that\n \tmatches the specified pattern (regular expression).\n \n+--regexp-ignore-case::\n+\n+\tMatch the regexp limiting patterns without regard to letters case.\n+\n+--extended-regexp::\n+\n+\tConsider the limiting patterns to be extended regular expressions\n+\tinstead of the default basic regular expressions.\n+\n --remove-empty::\n \n \tStop when a given path disappears from the tree.\ndiff --git a/revision.c b/revision.c\nindex 0125d41..0a29b53 100644\n--- a/revision.c\n+++ b/revision.c\n@@ -881,6 +881,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch\n \tconst char **unrecognized = argv + 1;\n \tint left = 1;\n \tint all_match = 0;\n+\tint regflags = 0;\n \n \t/* First, search for \"--\" */\n \tseen_dashdash = 0;\n@@ -1152,6 +1153,14 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch\n \t\t\t\tadd_message_grep(revs, arg+7);\n \t\t\t\tcontinue;\n \t\t\t}\n+\t\t\tif (!prefixcmp(arg, \"--extended-regexp\")) {\n+\t\t\t\tregflags |= REG_EXTENDED;\n+\t\t\t\tcontinue;\n+\t\t\t}\n+\t\t\tif (!prefixcmp(arg, \"--regexp-ignore-case\")) {\n+\t\t\t\tregflags |= REG_ICASE;\n+\t\t\t\tcontinue;\n+\t\t\t}\n \t\t\tif (!strcmp(arg, \"--all-match\")) {\n \t\t\t\tall_match = 1;\n \t\t\t\tcontinue;\n@@ -1200,6 +1209,9 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch\n \t\t}\n \t}\n \n+\tif (revs->grep_filter)\n+\t\trevs->grep_filter->regflags |= regflags;\n+\n \tif (show_merge)\n \t\tprepare_show_merge(revs);\n \tif (def && !revs->pending.nr) {\n"},{"id":"42566","messageId":"20070519001334.28618.30675.stgit@rover","threadId":"8212","inReplyTo":"20070519001329.28618.31334.stgit@rover","subject":"[PATCH 2/3] gitweb: Lift any characters restriction on searched strings","fromName":"Petr Baudis","fromEmail":"pasky@suse.cz","sentAt":"2007-05-19T00:13:34Z","receivedAt":"2007-05-19T00:13:34Z","isPatch":true,"sender":{"key":"pasky@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/18439?v=4"},"body":"Everything is already fully quoted along the way so I believe this to be\nunnecessary at this point. It would pose trouble for regexp searches.\n\nSigned-off-by: Petr Baudis <pasky@suse.cz>\n---\n\n gitweb/gitweb.perl |    3 ---\n 1 files changed, 0 insertions(+), 3 deletions(-)\n\ndiff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl\nindex 0143183..4ccb4e3 100755\n--- a/gitweb/gitweb.perl\n+++ b/gitweb/gitweb.perl\n@@ -404,9 +404,6 @@ if (defined $searchtype) {\n our $searchtext = $cgi->param('s');\n our $search_regexp;\n if (defined $searchtext) {\n-\tif ($searchtype ne 'grep' and $searchtype ne 'pickaxe' and $searchtext =~ m/[^a-zA-Z0-9_\\.\\/\\-\\+\\:\\@ ]/) {\n-\t\tdie_error(undef, \"Invalid search parameter\");\n-\t}\n \tif (length($searchtext) < 2) {\n \t\tdie_error(undef, \"At least two characters are required for search parameter\");\n \t}\n"},{"id":"42568","messageId":"20070519001339.28618.61624.stgit@rover","threadId":"8212","inReplyTo":"20070519001329.28618.31334.stgit@rover","subject":"[PATCH 3/3] gitweb: Clearly distinguish regexp / exact match searches","fromName":"Petr Baudis","fromEmail":"pasky@suse.cz","sentAt":"2007-05-19T00:13:39Z","receivedAt":"2007-05-19T00:13:39Z","isPatch":true,"sender":{"key":"pasky@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/18439?v=4"},"body":"This patch does a couple of things:\n\n* Makes commit/author/committer search case insensitive\n\n\tTo be consistent with the grep search; I see no convincing\n\treason for the search to be case sensitive, and you might\n\tget in trouble especially with contributors e.g. from Japan\n\tor France where they sometimes like to uppercase their last\n\tname.\n\n* Makes grep search by default grep for fixed strings\n\n\tSince we will have a checkbox.\n\n* Introduces 're' checkbox that enables POSIX extended regexp searches\n\n\tThis works for all the search types. The idea comes from Jakub.\n\nIt does not make much sense (and is not easy at all) to untangle most of\nthese changes from each other, thus they all go in a single patch.\n\nCc: Jakub Narebski <jnareb@gmail.com>\nSigned-off-by: Petr Baudis <pasky@suse.cz>\n---\n\n gitweb/gitweb.perl |   50 +++++++++++++++++++++++++++++++++-----------------\n 1 files changed, 33 insertions(+), 17 deletions(-)\n\ndiff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl\nindex 4ccb4e3..846392e 100755\n--- a/gitweb/gitweb.perl\n+++ b/gitweb/gitweb.perl\n@@ -401,13 +401,15 @@ if (defined $searchtype) {\n \t}\n }\n \n+our $search_use_regexp = $cgi->param('sr');\n+\n our $searchtext = $cgi->param('s');\n our $search_regexp;\n if (defined $searchtext) {\n \tif (length($searchtext) < 2) {\n \t\tdie_error(undef, \"At least two characters are required for search parameter\");\n \t}\n-\t$search_regexp = quotemeta $searchtext;\n+\t$search_regexp = $search_use_regexp ? $searchtext : quotemeta $searchtext;\n }\n \n # now read PATH_INFO and use it as alternative to parameters\n@@ -535,6 +537,7 @@ sub href(%) {\n \t\torder => \"o\",\n \t\tsearchtext => \"s\",\n \t\tsearchtype => \"st\",\n+\t\tsearch_use_regexp => \"sr\",\n \t);\n \tmy %mapping = @mapping;\n \n@@ -1579,7 +1582,7 @@ sub parse_commit {\n }\n \n sub parse_commits {\n-\tmy ($commit_id, $maxcount, $skip, $arg, $filename) = @_;\n+\tmy ($commit_id, $maxcount, $skip, $filename, @args) = @_;\n \tmy @cos;\n \n \t$maxcount ||= 1;\n@@ -1589,7 +1592,7 @@ sub parse_commits {\n \n \topen my $fd, \"-|\", git_cmd(), \"rev-list\",\n \t\t\"--header\",\n-\t\t($arg ? ($arg) : ()),\n+\t\t@args,\n \t\t(\"--max-count=\" . $maxcount),\n \t\t(\"--skip=\" . $skip),\n \t\t$commit_id,\n@@ -2007,6 +2010,9 @@ EOF\n \t\t      $cgi->sup($cgi->a({-href => href(action=>\"search_help\")}, \"?\")) .\n \t\t      \" search:\\n\",\n \t\t      $cgi->textfield(-name => \"s\", -value => $searchtext) . \"\\n\" .\n+\t\t      \"<span title=\\\"Extended regular expression\\\">\" .\n+\t\t      $cgi->checkbox(-name => 'sr', -value => 1, -checked => $search_use_regexp, -label => 're') .\n+\t\t      \"</span>\" .\n \t\t      \"</div>\" .\n \t\t      $cgi->end_form() . \"\\n\";\n \t}\n@@ -4655,7 +4661,7 @@ sub git_history {\n \t\t$ftype = git_get_type($hash);\n \t}\n \n-\tmy @commitlist = parse_commits($hash_base, 101, (100 * $page), \"--full-history\", $file_name);\n+\tmy @commitlist = parse_commits($hash_base, 101, (100 * $page), $file_name, \"--full-history\");\n \n \tmy $paging_nav = '';\n \tif ($page > 0) {\n@@ -4745,7 +4751,9 @@ sub git_search {\n \t\t\t$greptype = \"--committer=\";\n \t\t}\n \t\t$greptype .= $search_regexp;\n-\t\tmy @commitlist = parse_commits($hash, 101, (100 * $page), $greptype);\n+\t\tmy @commitlist = parse_commits($hash, 101, (100 * $page), undef,\n+\t\t                               $greptype, $search_use_regexp ? ('--extended-regexp') : (),\n+\t\t\t\t\t       '--regexp-ignore-case');\n \n \t\tmy $paging_nav = '';\n \t\tif ($page > 0) {\n@@ -4795,8 +4803,9 @@ sub git_search {\n \t\tmy $git_command = git_cmd_str();\n \t\tmy $searchqtext = $searchtext;\n \t\t$searchqtext =~ s/'/'\\\\''/;\n+\t\tmy $pickaxe_flags = $search_use_regexp ? '--pickaxe-regex' : '';\n \t\topen my $fd, \"-|\", \"$git_command rev-list $hash | \" .\n-\t\t\t\"$git_command diff-tree -r --stdin -S\\'$searchqtext\\'\";\n+\t\t\t\"$git_command diff-tree -r --stdin -S\\'$searchqtext\\' $pickaxe_flags\";\n \t\tundef %co;\n \t\tmy @files;\n \t\twhile (my $line = <$fd>) {\n@@ -4859,7 +4868,9 @@ sub git_search {\n \t\tmy $alternate = 1;\n \t\tmy $matches = 0;\n \t\t$/ = \"\\n\";\n-\t\topen my $fd, \"-|\", git_cmd(), 'grep', '-n', '-i', '-E', $searchtext, $co{'tree'};\n+\t\topen my $fd, \"-|\", git_cmd(), 'grep', '-n',\n+\t\t\t$search_use_regexp ? ('-E', '-i') : '-F',\n+\t\t\t$searchtext, $co{'tree'};\n \t\tmy $lastfile = '';\n \t\twhile (my $line = <$fd>) {\n \t\t\tchomp $line;\n@@ -4889,7 +4900,7 @@ sub git_search {\n \t\t\t\tprint \"<div class=\\\"binary\\\">Binary file</div>\\n\";\n \t\t\t} else {\n \t\t\t\t$ltext = untabify($ltext);\n-\t\t\t\tif ($ltext =~ m/^(.*)($searchtext)(.*)$/i) {\n+\t\t\t\tif ($ltext =~ m/^(.*)($search_regexp)(.*)$/i) {\n \t\t\t\t\t$ltext = esc_html($1, -nbsp=>1);\n \t\t\t\t\t$ltext .= '<span class=\"match\">';\n \t\t\t\t\t$ltext .= esc_html($2, -nbsp=>1);\n@@ -4924,27 +4935,31 @@ sub git_search_help {\n \tgit_header_html();\n \tgit_print_page_nav('','', $hash,$hash,$hash);\n \tprint <<EOT;\n+<p><strong>Pattern</strong> is by default a normal string that is matched precisely (but without\n+regard to case, except in the case of pickaxe). However, when you check the <em>re</em> checkbox,\n+the pattern entered is recognized as the POSIX extended\n+<a href=\"http://en.wikipedia.org/wiki/Regular_expression\">regular expression</a> (also case\n+insensitive).</p>\n <dl>\n <dt><b>commit</b></dt>\n-<dd>The commit messages and authorship information will be scanned for the given string.</dd>\n+<dd>The commit messages and authorship information will be scanned for the given pattern.</dd>\n EOT\n \tmy ($have_grep) = gitweb_check_feature('grep');\n \tif ($have_grep) {\n \t\tprint <<EOT;\n <dt><b>grep</b></dt>\n <dd>All files in the currently selected tree (HEAD unless you are explicitly browsing\n-    a different one) are searched for the given\n-<a href=\"http://en.wikipedia.org/wiki/Regular_expression\">regular expression</a>\n-(POSIX extended) and the matches are listed. On large\n-trees, this search can take a while and put some strain on the server, so please use it with\n-some consideration.</dd>\n+    a different one) are searched for the given pattern. On large trees, this search can take\n+a while and put some strain on the server, so please use it with some consideration. Note that\n+due to git-grep peculiarity, currently if regexp mode is turned off, the matches are\n+case-sensitive.</dd>\n EOT\n \t}\n \tprint <<EOT;\n <dt><b>author</b></dt>\n-<dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given string.</dd>\n+<dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given pattern.</dd>\n <dt><b>committer</b></dt>\n-<dd>Name and e-mail of the committer and date of commit will be scanned for the given string.</dd>\n+<dd>Name and e-mail of the committer and date of commit will be scanned for the given pattern.</dd>\n EOT\n \tmy ($have_pickaxe) = gitweb_check_feature('pickaxe');\n \tif ($have_pickaxe) {\n@@ -4952,7 +4967,8 @@ EOT\n <dt><b>pickaxe</b></dt>\n <dd>All commits that caused the string to appear or disappear from any file (changes that\n added, removed or \"modified\" the string) will be listed. This search can take a while and\n-takes a lot of strain on the server, so please use it wisely.</dd>\n+takes a lot of strain on the server, so please use it wisely. Note that since you may be\n+interested even in changes just changing the case as well, this search is case sensitive.</dd>\n EOT\n \t}\n \tprint \"</dl>\\n\";\n"}]}