{"thread":{"id":"23182","subject":"[PATCH 0/2] Teach 'git grep' about --open-files-in-pager=[<pager>]","startedAt":"2010-03-26T10:48:41Z","lastAt":"2010-03-29T18:17:12Z","messageCount":20,"participants":["Johannes Schindelin","Bert Wesarg","Jeff King","Junio C Hamano","Jon Seymour","Francis Moreau","Jonathan Nieder"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"137835","messageId":"alpine.DEB.1.00.1003261145500.7596@pacific.mpi-cbg.de","threadId":"23182","inReplyTo":null,"subject":"[PATCH 0/2] Teach 'git grep' about --open-files-in-pager=[<pager>]","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2010-03-26T10:48:41Z","receivedAt":"2010-03-26T10:48:41Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"\nThis supports opening the results of a 'git grep' directly in a pager \n(where the pager can be 'vi', too).\n\nThis series is purely about convenience, everything the option does can\nbe done with a regular script or command line.\n\nBut I saw so many people doing their own scripts for that, and in many\ncases, they are subtly broken (e.g.\n\n\tgit grep -z <expr> | xargs -0r vi +/<expr>\n\nwould work as long as you do not have to check the exit status of git\ngrep from another script) that I finally decided to go for it and send\nthis patch pair.\n\nMy most common use case for this is to do something like\n\n\tgit grep -Ovi SomeJustRenamedFile\n\nto edit all files I might have forgotten to change after a git mv.\n\n(Actually, to be honest, my use case involves -Pvi, but I will have to\nretrain my hands.)\n\nJohannes Schindelin (2):\n  grep: Add the option '--open-files-in-pager'\n  grep -P: allow optional argument specifying the pager (or editor)\n\n Documentation/git-grep.txt |    8 +++++\n builtin-grep.c             |   74 ++++++++++++++++++++++++++++++++++++++++++++\n git.c                      |    2 +-\n 3 files changed, 83 insertions(+), 1 deletions(-)\n"},{"id":"137836","messageId":"alpine.DEB.1.00.1003261149040.7596@pacific.mpi-cbg.de","threadId":"23182","inReplyTo":"alpine.DEB.1.00.1003261145500.7596@pacific.mpi-cbg.de","subject":"[PATCH 1/2] grep: Add the option '--open-files-in-pager'","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2010-03-26T10:49:17Z","receivedAt":"2010-03-26T10:49:17Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"\nThis adds an option to open the matching files in the pager, and if the\npager happens to be \"less\" (or \"vi\") and there is only one grep pattern,\nit also jumps to the first match right away.\n\nThe short option was chose as '-O' to avoid clashes with GNU grep's\noptions (as suggested by Junio).\n\nSo, 'git grep -O abc' is a short form for 'less +/abc $(grep -l abc)'\nexcept that it works also with spaces in file names, and it does not\nstart the pager if there was no matching file.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n Documentation/git-grep.txt |    8 +++++\n builtin-grep.c             |   71 ++++++++++++++++++++++++++++++++++++++++++++\n git.c                      |    2 +-\n 3 files changed, 80 insertions(+), 1 deletions(-)\n\ndiff --git a/Documentation/git-grep.txt b/Documentation/git-grep.txt\nindex e019e76..ab3bb77 100644\n--- a/Documentation/git-grep.txt\n+++ b/Documentation/git-grep.txt\n@@ -15,6 +15,7 @@ SYNOPSIS\n \t   [-E | --extended-regexp] [-G | --basic-regexp]\n \t   [-F | --fixed-strings] [-n]\n \t   [-l | --files-with-matches] [-L | --files-without-match]\n+\t   [-O | --open-files-in-pager]\n \t   [-z | --null]\n \t   [-c | --count] [--all-match] [-q | --quiet]\n \t   [--max-depth <depth>]\n@@ -101,6 +102,13 @@ OPTIONS\n \tFor better compatibility with 'git diff', --name-only is a\n \tsynonym for --files-with-matches.\n \n+-O::\n+--open-files-in-pager::\n+\tOpen the matching files in the pager (not the output of 'grep').\n+\tIf the pager happens to be \"less\" or \"vi\", and the user\n+\tspecified only one pattern, the first file is positioned at\n+\tthe first match automatically.\n+\n -z::\n --null::\n \tOutput \\0 instead of the character that normally follows a\ndiff --git a/builtin-grep.c b/builtin-grep.c\nindex 5d83d9b..233c772 100644\n--- a/builtin-grep.c\n+++ b/builtin-grep.c\n@@ -14,6 +14,7 @@\n #include \"userdiff.h\"\n #include \"grep.h\"\n #include \"quote.h\"\n+#include \"string-list.h\"\n \n #ifndef NO_PTHREADS\n #include \"thread-utils.h\"\n@@ -517,6 +518,31 @@ static int grep_file(struct grep_opt *opt, const char *filename)\n \t}\n }\n \n+static void append_path(struct grep_opt *opt, const void *data, size_t len)\n+{\n+\tstruct string_list *path_list = opt->output_priv;\n+\n+\tif (len == 1 && *(char *)data == '\\0')\n+\t\treturn;\n+\tstring_list_append(xstrndup(data, len), path_list);\n+}\n+\n+static void run_pager(struct grep_opt *opt, const char *prefix)\n+{\n+\tstruct string_list *path_list = opt->output_priv;\n+\tchar **argv = xmalloc(sizeof(const char *) * (path_list->nr + 1));\n+\tint i;\n+\n+\tfor (i = 0; i < path_list->nr; i++)\n+\t\targv[i] = path_list->items[i].string;\n+\targv[path_list->nr] = NULL;\n+\n+\tif (prefix)\n+\t\tchdir(prefix);\n+\texecvp(argv[0], argv);\n+\terror(\"Could not run pager %s: %s\", argv[0], strerror(errno));\n+}\n+\n static int grep_cache(struct grep_opt *opt, const char **paths, int cached)\n {\n \tint hit = 0;\n@@ -727,9 +753,11 @@ int cmd_grep(int argc, const char **argv, const char *prefix)\n \tint cached = 0;\n \tint seen_dashdash = 0;\n \tint external_grep_allowed__ignored;\n+\tint show_in_pager = 0;\n \tstruct grep_opt opt;\n \tstruct object_array list = { 0, 0, NULL };\n \tconst char **paths = NULL;\n+\tstruct string_list path_list = { NULL, 0, 0, 0 };\n \tint i;\n \tint dummy;\n \tstruct option options[] = {\n@@ -810,6 +838,8 @@ int cmd_grep(int argc, const char **argv, const char *prefix)\n \t\tOPT_BOOLEAN(0, \"all-match\", &opt.all_match,\n \t\t\t\"show only matches from files that match all patterns\"),\n \t\tOPT_GROUP(\"\"),\n+\t\tOPT_BOOLEAN('O', \"open-files-in-pager\", &show_in_pager,\n+\t\t\t\"show matching files in the pager\"),\n \t\tOPT_BOOLEAN(0, \"ext-grep\", &external_grep_allowed__ignored,\n \t\t\t    \"allow calling of grep(1) (ignored by this build)\"),\n \t\t{ OPTION_CALLBACK, 0, \"help-all\", &options, NULL, \"show usage\",\n@@ -862,6 +892,20 @@ int cmd_grep(int argc, const char **argv, const char *prefix)\n \t\targc--;\n \t}\n \n+\tif (show_in_pager) {\n+\t\tconst char *pager = getenv(\"GIT_PAGER\");\n+\t\tif (!pager)\n+\t\t\tpager = getenv(\"PAGER\");\n+\t\tif (!pager)\n+\t\t\tpager = \"less\";\n+\t\topt.name_only = 1;\n+\t\topt.null_following_name = 1;\n+\t\topt.output_priv = &path_list;\n+\t\topt.output = append_path;\n+\t\tstring_list_append(pager, &path_list);\n+\t\tuse_threads = 0;\n+\t}\n+\n \tif (!opt.pattern_list)\n \t\tdie(\"no pattern given.\");\n \tif (!opt.fixed && opt.ignore_case)\n@@ -921,6 +965,29 @@ int cmd_grep(int argc, const char **argv, const char *prefix)\n \t\tpaths[1] = NULL;\n \t}\n \n+\tif (show_in_pager && (cached || list.nr))\n+\t\tdie (\"--open-files-in-pager only works on the worktree\");\n+\n+\tif (show_in_pager && opt.pattern_list && !opt.pattern_list->next) {\n+\t\tconst char *pager = path_list.items[0].string;\n+\t\tint len = strlen(pager);\n+\n+\t\tif (len > 4 && is_dir_sep(pager[len - 5]))\n+\t\t\tpager += len - 4;\n+\n+\t\tif (!strcmp(\"less\", pager) || !strcmp(\"vi\", pager)) {\n+\t\t\tstruct strbuf buf = STRBUF_INIT;\n+\t\t\tstrbuf_addf(&buf, \"+/%s%s\",\n+\t\t\t\t\tstrcmp(\"less\", pager) ? \"\" : \"*\",\n+\t\t\t\t\topt.pattern_list->pattern);\n+\t\t\tstring_list_append(buf.buf, &path_list);\n+\t\t\tstrbuf_detach(&buf, NULL);\n+\t\t}\n+\t}\n+\n+\tif (!show_in_pager)\n+\t\tsetup_pager();\n+\n \tif (!list.nr) {\n \t\tif (!cached)\n \t\t\tsetup_work_tree();\n@@ -943,6 +1010,10 @@ int cmd_grep(int argc, const char **argv, const char *prefix)\n \n \tif (use_threads)\n \t\thit |= wait_all();\n+\n+\tif (hit && show_in_pager)\n+\t\trun_pager(&opt, prefix);\n+\n \tfree_grep_patterns(&opt);\n \treturn !hit;\n }\ndiff --git a/git.c b/git.c\nindex 4c3028c..4def718 100644\n--- a/git.c\n+++ b/git.c\n@@ -317,7 +317,7 @@ static void handle_internal_command(int argc, const char **argv)\n \t\t{ \"fsck-objects\", cmd_fsck, RUN_SETUP },\n \t\t{ \"gc\", cmd_gc, RUN_SETUP },\n \t\t{ \"get-tar-commit-id\", cmd_get_tar_commit_id },\n-\t\t{ \"grep\", cmd_grep, RUN_SETUP | USE_PAGER },\n+\t\t{ \"grep\", cmd_grep, RUN_SETUP },\n \t\t{ \"hash-object\", cmd_hash_object },\n \t\t{ \"help\", cmd_help },\n \t\t{ \"index-pack\", cmd_index_pack },\n-- \n1.6.4.313.g3d9e3\n"},{"id":"137837","messageId":"alpine.DEB.1.00.1003261149270.7596@pacific.mpi-cbg.de","threadId":"23182","inReplyTo":"alpine.DEB.1.00.1003261145500.7596@pacific.mpi-cbg.de","subject":"[PATCH 2/2] grep -P: allow optional argument specifying the pager (or editor)","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2010-03-26T10:49:44Z","receivedAt":"2010-03-26T10:49:44Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"\nSuppose you want to edit all files that contain a specific search term.\nOf course, you can do something totally trivial such as\n\n\tgit grep -z -e <term> | xargs -0r vi +/<term>\n\nbut maybe you are happy that the same will be achieved by\n\n\tgit grep -Ovi <term>\n\nnow.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n Documentation/git-grep.txt |    6 +++---\n builtin-grep.c             |   21 ++++++++++++---------\n 2 files changed, 15 insertions(+), 12 deletions(-)\n\ndiff --git a/Documentation/git-grep.txt b/Documentation/git-grep.txt\nindex ab3bb77..1b7e32d 100644\n--- a/Documentation/git-grep.txt\n+++ b/Documentation/git-grep.txt\n@@ -15,7 +15,7 @@ SYNOPSIS\n \t   [-E | --extended-regexp] [-G | --basic-regexp]\n \t   [-F | --fixed-strings] [-n]\n \t   [-l | --files-with-matches] [-L | --files-without-match]\n-\t   [-O | --open-files-in-pager]\n+\t   [(-O | --open-files-in-pager) [<pager>]]\n \t   [-z | --null]\n \t   [-c | --count] [--all-match] [-q | --quiet]\n \t   [--max-depth <depth>]\n@@ -102,8 +102,8 @@ OPTIONS\n \tFor better compatibility with 'git diff', --name-only is a\n \tsynonym for --files-with-matches.\n \n--O::\n---open-files-in-pager::\n+-O [<pager>]::\n+--open-files-in-pager [<pager>]::\n \tOpen the matching files in the pager (not the output of 'grep').\n \tIf the pager happens to be \"less\" or \"vi\", and the user\n \tspecified only one pattern, the first file is positioned at\ndiff --git a/builtin-grep.c b/builtin-grep.c\nindex 233c772..a23f0dc 100644\n--- a/builtin-grep.c\n+++ b/builtin-grep.c\n@@ -753,7 +753,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)\n \tint cached = 0;\n \tint seen_dashdash = 0;\n \tint external_grep_allowed__ignored;\n-\tint show_in_pager = 0;\n+\tconst char *show_in_pager = NULL, *default_pager = \"dummy\";\n \tstruct grep_opt opt;\n \tstruct object_array list = { 0, 0, NULL };\n \tconst char **paths = NULL;\n@@ -838,8 +838,9 @@ int cmd_grep(int argc, const char **argv, const char *prefix)\n \t\tOPT_BOOLEAN(0, \"all-match\", &opt.all_match,\n \t\t\t\"show only matches from files that match all patterns\"),\n \t\tOPT_GROUP(\"\"),\n-\t\tOPT_BOOLEAN('O', \"open-files-in-pager\", &show_in_pager,\n-\t\t\t\"show matching files in the pager\"),\n+\t\t{ OPTION_STRING, 'O', \"open-files-in-pager\", &show_in_pager,\n+\t\t\t\"pager\", \"show matching files in the pager\",\n+\t\t\tPARSE_OPT_OPTARG, NULL, (intptr_t)default_pager },\n \t\tOPT_BOOLEAN(0, \"ext-grep\", &external_grep_allowed__ignored,\n \t\t\t    \"allow calling of grep(1) (ignored by this build)\"),\n \t\t{ OPTION_CALLBACK, 0, \"help-all\", &options, NULL, \"show usage\",\n@@ -893,16 +894,18 @@ int cmd_grep(int argc, const char **argv, const char *prefix)\n \t}\n \n \tif (show_in_pager) {\n-\t\tconst char *pager = getenv(\"GIT_PAGER\");\n-\t\tif (!pager)\n-\t\t\tpager = getenv(\"PAGER\");\n-\t\tif (!pager)\n-\t\t\tpager = \"less\";\n+\t\tif (show_in_pager == default_pager) {\n+\t\t\tshow_in_pager = getenv(\"GIT_PAGER\");\n+\t\t\tif (!show_in_pager)\n+\t\t\t\tshow_in_pager = getenv(\"PAGER\");\n+\t\t\tif (!show_in_pager)\n+\t\t\t\tshow_in_pager = \"less\";\n+\t\t}\n \t\topt.name_only = 1;\n \t\topt.null_following_name = 1;\n \t\topt.output_priv = &path_list;\n \t\topt.output = append_path;\n-\t\tstring_list_append(pager, &path_list);\n+\t\tstring_list_append(show_in_pager, &path_list);\n \t\tuse_threads = 0;\n \t}\n \n-- \n1.6.4.313.g3d9e3\n"},{"id":"137838","messageId":"alpine.DEB.1.00.1003261149580.7596@pacific.mpi-cbg.de","threadId":"23182","inReplyTo":"alpine.DEB.1.00.1003261149270.7596@pacific.mpi-cbg.de","subject":"Re: [PATCH 2/2] grep -P: allow optional argument specifying the pager (or editor)","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2010-03-26T10:50:19Z","receivedAt":"2010-03-26T10:50:19Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nthe subject should read \"grep -O...\", of course.\n\nSorry,\nDscho\n"},{"id":"137840","messageId":"36ca99e91003260439x3d60b851g15b8652d50f61c06@mail.gmail.com","threadId":"23182","inReplyTo":"alpine.DEB.1.00.1003261145500.7596@pacific.mpi-cbg.de","subject":"Re: [PATCH 0/2] Teach 'git grep' about --open-files-in-pager=[<pager>]","fromName":"Bert Wesarg","fromEmail":"bert.wesarg@googlemail.com","sentAt":"2010-03-26T11:39:39Z","receivedAt":"2010-03-26T11:39:39Z","isPatch":true,"sender":{"key":"bert.wesarg@googlemail.com","avatar":"https://avatars.githubusercontent.com/u/111934?v=4"},"body":"On Fri, Mar 26, 2010 at 11:48, Johannes Schindelin\n<Johannes.Schindelin@gmx.de> wrote:\n>\n> This supports opening the results of a 'git grep' directly in a pager\n> (where the pager can be 'vi', too).\n>\n> This series is purely about convenience, everything the option does can\n> be done with a regular script or command line.\n>\n> But I saw so many people doing their own scripts for that, and in many\n> cases, they are subtly broken (e.g.\n>\n>        git grep -z <expr> | xargs -0r vi +/<expr>\n>\n> would work as long as you do not have to check the exit status of git\n> grep from another script) that I finally decided to go for it and send\n> this patch pair.\n>\n> My most common use case for this is to do something like\n>\n>        git grep -Ovi SomeJustRenamedFile\n>\n> to edit all files I might have forgotten to change after a git mv.\n>\n> (Actually, to be honest, my use case involves -Pvi, but I will have to\n> retrain my hands.)\n>\n> Johannes Schindelin (2):\n>  grep: Add the option '--open-files-in-pager'\n>  grep -P: allow optional argument specifying the pager (or editor)\n\nYour re-training failed miserable ;-)\n\nI like the idea. But could it make sense to get the line number of the\nfirst match to the filename. In the same syntax as on the console\n(i.e. <file>:<line>:)?\n\nI have also the feeling that -O potion does not like pager with\narguments, be it from GIT_PAGER, PAGER, or from the command line.\n\nRegards,\nBert\n"},{"id":"137843","messageId":"20100326124650.GA12215@coredump.intra.peff.net","threadId":"23182","inReplyTo":"alpine.DEB.1.00.1003261145500.7596@pacific.mpi-cbg.de","subject":"Re: [PATCH 0/2] Teach 'git grep' about --open-files-in-pager=[<pager>]","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2010-03-26T12:46:50Z","receivedAt":"2010-03-26T12:46:50Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Fri, Mar 26, 2010 at 11:48:41AM +0100, Johannes Schindelin wrote:\n\n> This supports opening the results of a 'git grep' directly in a pager \n> (where the pager can be 'vi', too).\n\nThis is not an argument against your patch, but you may be interested in\nan alternate method:\n\n  git grep -n $pattern >grep.out\n  vim -q grep.out\n\nThe advantage is that the editor understands the output as a \"quickfix\"\nlist and lets you cycle through the hits (just like you might with\ncompiler errors). The disadvantage is that quickfix is a vim extension,\nso \"less\" and stock \"vi\" can't do this (I imagine emacs has a similar\nfeature). It's also obviously a little more typing, but you can hide it\ninside an alias quite easily.\n\nI use the same trick to look for \"^<<<<<<<\", and have vim cycle through\nmerge conflicts (you can also make it quicker by restricitng the grep\nonly to unmerged files).\n\n-Peff\n"},{"id":"137872","messageId":"alpine.DEB.1.00.1003261712100.7596@pacific.mpi-cbg.de","threadId":"23182","inReplyTo":"20100326124650.GA12215@coredump.intra.peff.net","subject":"Re: [PATCH 0/2] Teach 'git grep' about --open-files-in-pager=[<pager>]","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2010-03-26T16:14:46Z","receivedAt":"2010-03-26T16:14:46Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Fri, 26 Mar 2010, Jeff King wrote:\n\n> On Fri, Mar 26, 2010 at 11:48:41AM +0100, Johannes Schindelin wrote:\n> \n> > This supports opening the results of a 'git grep' directly in a pager \n> > (where the pager can be 'vi', too).\n> \n> This is not an argument against your patch, but you may be interested in \n> an alternate method:\n> \n>   git grep -n $pattern >grep.out vim -q grep.out\n> \n> The advantage is that the editor understands the output as a \"quickfix\" \n> list and lets you cycle through the hits (just like you might with \n> compiler errors). The disadvantage is that quickfix is a vim extension, \n> so \"less\" and stock \"vi\" can't do this (I imagine emacs has a similar \n> feature). It's also obviously a little more typing, but you can hide it \n> inside an alias quite easily.\n\nIn addition to the disadvantages you are listing, it does not jump \ndirectly to the word I am looking for. As you know, I am working \nwith LaTeX files heavily, where convention dictates that a paragraph is \nrepresented by a single line in the source code.\n\nSo yes, I really need -O, and if a colleague would not have asked me why \nthis useful feature is not in upstream Git, I would not even have \nsubmitted the patch pair.\n\nCiao,\nDscho\n"},{"id":"137873","messageId":"alpine.DEB.1.00.1003261714550.7596@pacific.mpi-cbg.de","threadId":"23182","inReplyTo":"36ca99e91003260439x3d60b851g15b8652d50f61c06@mail.gmail.com","subject":"Re: [PATCH 0/2] Teach 'git grep' about --open-files-in-pager=[<pager>]","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2010-03-26T16:18:06Z","receivedAt":"2010-03-26T16:18:06Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Fri, 26 Mar 2010, Bert Wesarg wrote:\n\n> On Fri, Mar 26, 2010 at 11:48, Johannes Schindelin\n> <Johannes.Schindelin@gmx.de> wrote:\n> >\n> > This supports opening the results of a 'git grep' directly in a pager\n> > (where the pager can be 'vi', too).\n> >\n> > This series is purely about convenience, everything the option does can\n> > be done with a regular script or command line.\n> >\n> > But I saw so many people doing their own scripts for that, and in many\n> > cases, they are subtly broken (e.g.\n> >\n> >        git grep -z <expr> | xargs -0r vi +/<expr>\n> >\n> > would work as long as you do not have to check the exit status of git\n> > grep from another script) that I finally decided to go for it and send\n> > this patch pair.\n> >\n> > My most common use case for this is to do something like\n> >\n> >        git grep -Ovi SomeJustRenamedFile\n> >\n> > to edit all files I might have forgotten to change after a git mv.\n> >\n> > (Actually, to be honest, my use case involves -Pvi, but I will have to\n> > retrain my hands.)\n> >\n> > Johannes Schindelin (2):\n> >  grep: Add the option '--open-files-in-pager'\n> >  grep -P: allow optional argument specifying the pager (or editor)\n> \n> Your re-training failed miserable ;-)\n\nIt would have if I said that it is finished.\n\n> I like the idea. But could it make sense to get the line number of the \n> first match to the filename. In the same syntax as on the console (i.e. \n> <file>:<line>:)?\n\nSee Peff's mail, and my answer to it for an explanation why it would \nactively _not_ help me that way.\n\n> I have also the feeling that -O potion does not like pager with\n> arguments, be it from GIT_PAGER, PAGER, or from the command line.\n\nYou are correct. That's why I said \"-O[<pager>]\" and not \n\"-O[<pager-with-arguments-that-cause-whitespace-problems-especially-with-spaces-in-directory-names-so-you-need-to-make-a-script-wrapper-anyway>]\" \n\nOf course, if you would find that useful, nobody stops you from making a \npatch on top of my patch pair.\n\nCiao,\nDscho\n"},{"id":"137888","messageId":"7vwrwykhee.fsf@alter.siamese.dyndns.org","threadId":"23182","inReplyTo":"20100326124650.GA12215@coredump.intra.peff.net","subject":"Re: [PATCH 0/2] Teach 'git grep' about --open-files-in-pager=[<pager>]","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2010-03-26T19:32:57Z","receivedAt":"2010-03-26T19:32:57Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jeff King <peff@peff.net> writes:\n\n> On Fri, Mar 26, 2010 at 11:48:41AM +0100, Johannes Schindelin wrote:\n>\n>> This supports opening the results of a 'git grep' directly in a pager \n>> (where the pager can be 'vi', too).\n>\n> This is not an argument against your patch, but you may be interested in\n> an alternate method:\n>\n>   git grep -n $pattern >grep.out\n>   vim -q grep.out\n>\n> The advantage is that the editor understands the output as a \"quickfix\"\n> list and lets you cycle through the hits (just like you might with\n> compiler errors). The disadvantage is that quickfix is a vim extension,\n> so \"less\" and stock \"vi\" can't do this (I imagine emacs has a similar\n> feature). It's also obviously a little more typing, but you can hide it\n> inside an alias quite easily.\n\n\"M-x grep-find\" mode is designed for this, and I often run \"git grep -n\"\nin that mode..  The output is dumped into a sbuffer that is used as a\n\"quickfix list\" to bring in files with hits and jump around.\n"},{"id":"137890","messageId":"2cfc40321003261249g32ba4472x9786a86830ec9813@mail.gmail.com","threadId":"23182","inReplyTo":"20100326124650.GA12215@coredump.intra.peff.net","subject":"Re: [PATCH 0/2] Teach 'git grep' about --open-files-in-pager=[<pager>]","fromName":"Jon Seymour","fromEmail":"jon.seymour@gmail.com","sentAt":"2010-03-26T19:49:06Z","receivedAt":"2010-03-26T19:49:06Z","isPatch":true,"sender":{"key":"jon.seymour@gmail.com","avatar":"https://avatars.githubusercontent.com/u/207131?v=4"},"body":"On Fri, Mar 26, 2010 at 11:46 PM, Jeff King <peff@peff.net> wrote:\n> On Fri, Mar 26, 2010 at 11:48:41AM +0100, Johannes Schindelin wrote:\n>\n>> This supports opening the results of a 'git grep' directly in a pager\n>> (where the pager can be 'vi', too).\n>\n> This is not an argument against your patch, but you may be interested in\n> an alternate method:\n>\n>  git grep -n $pattern >grep.out\n>  vim -q grep.out\n\nOr, in bash:\n\n    vim -q <(git grep -n $pattern)\n\nthough, of course you don't get the exit code from git.\n\njon.\n"},{"id":"137892","messageId":"36ca99e91003261307m68cb7238u8a5cbbb350c71c97@mail.gmail.com","threadId":"23182","inReplyTo":"alpine.DEB.1.00.1003261714550.7596@pacific.mpi-cbg.de","subject":"Re: [PATCH 0/2] Teach 'git grep' about --open-files-in-pager=[<pager>]","fromName":"Bert Wesarg","fromEmail":"bert.wesarg@googlemail.com","sentAt":"2010-03-26T20:07:28Z","receivedAt":"2010-03-26T20:07:28Z","isPatch":true,"sender":{"key":"bert.wesarg@googlemail.com","avatar":"https://avatars.githubusercontent.com/u/111934?v=4"},"body":"Hi,\n\nOn Fri, Mar 26, 2010 at 17:18, Johannes Schindelin\n<Johannes.Schindelin@gmx.de> wrote:\n>> I have also the feeling that -O potion does not like pager with\n>> arguments, be it from GIT_PAGER, PAGER, or from the command line.\n>\n> You are correct. That's why I said \"-O[<pager>]\" and not\n> \"-O[<pager-with-arguments-that-cause-whitespace-problems-especially-with-spaces-in-directory-names-so-you-need-to-make-a-script-wrapper-anyway>]\"\n\nI don't know how common it is to have arguments for the pager in\nGIT_PAGER or PAGER or whether git actually support this, but your\nfirst patch definitely does not work with this, regardless of your\n-O[<pager>] addition of the second patch.\n\nBert\n"},{"id":"137899","messageId":"20100326203303.GB22900@coredump.intra.peff.net","threadId":"23182","inReplyTo":"alpine.DEB.1.00.1003261712100.7596@pacific.mpi-cbg.de","subject":"Re: [PATCH 0/2] Teach 'git grep' about --open-files-in-pager=[<pager>]","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2010-03-26T20:33:03Z","receivedAt":"2010-03-26T20:33:03Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Fri, Mar 26, 2010 at 05:14:46PM +0100, Johannes Schindelin wrote:\n\n> In addition to the disadvantages you are listing, it does not jump \n> directly to the word I am looking for. As you know, I am working \n> with LaTeX files heavily, where convention dictates that a paragraph is \n> represented by a single line in the source code.\n\nSure, that is a reasonable feature to want that my solution did not have\n(though I have never seen LaTeX code with that requirement; I wrap my\nlines at a reasonable width and separate paragraphs with a blank line).\n\n> So yes, I really need -O, and if a colleague would not have asked me why \n> this useful feature is not in upstream Git, I would not even have \n> submitted the patch pair.\n\nYep. That is why I started my mail with \"this is not an argument against\nyour patch\". I was just trying to be helpful and offer a possible\nalternative.\n\n-Peff\n"},{"id":"137900","messageId":"m239zmdcz5.fsf@gmail.com","threadId":"23182","inReplyTo":"7vwrwykhee.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH 0/2] Teach 'git grep' about --open-files-in-pager=[<pager>]","fromName":"Francis Moreau","fromEmail":"francis.moro@gmail.com","sentAt":"2010-03-26T20:50:22Z","receivedAt":"2010-03-26T20:50:22Z","isPatch":true,"sender":{"key":"francis.moro@gmail.com","avatar":null},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> Jeff King <peff@peff.net> writes:\n>\n>> On Fri, Mar 26, 2010 at 11:48:41AM +0100, Johannes Schindelin wrote:\n>>\n>>> This supports opening the results of a 'git grep' directly in a pager \n>>> (where the pager can be 'vi', too).\n>>\n>> This is not an argument against your patch, but you may be interested in\n>> an alternate method:\n>>\n>>   git grep -n $pattern >grep.out\n>>   vim -q grep.out\n>>\n>> The advantage is that the editor understands the output as a \"quickfix\"\n>> list and lets you cycle through the hits (just like you might with\n>> compiler errors). The disadvantage is that quickfix is a vim extension,\n>> so \"less\" and stock \"vi\" can't do this (I imagine emacs has a similar\n>> feature). It's also obviously a little more typing, but you can hide it\n>> inside an alias quite easily.\n>\n> \"M-x grep-find\" mode is designed for this,\n\nDo you mean \"M-x grep\" ? I don't see the point to use \"M-x grep-find\".\n\n> and I often run \"git grep -n\" in that mode..\n\nI always need to pass the '--no-pager' switch: \"git --no-pager grep -n\"\nsince git doesn't detect that its output is sent to a 'dumb' terminal.\n\n-- \nFrancis\n"},{"id":"137923","messageId":"7v39zm7epf.fsf@alter.siamese.dyndns.org","threadId":"23182","inReplyTo":"m239zmdcz5.fsf@gmail.com","subject":"Re: [PATCH 0/2] Teach 'git grep' about --open-files-in-pager=[<pager>]","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2010-03-27T01:09:32Z","receivedAt":"2010-03-27T01:09:32Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Francis Moreau <francis.moro@gmail.com> writes:\n\n>> and I often run \"git grep -n\" in that mode..\n>\n> I always need to pass the '--no-pager' switch: \"git --no-pager grep -n\"\n> since git doesn't detect that its output is sent to a 'dumb' terminal.\n\nSorry, but as any self-respecting Emacs user would have PAGER set to cat\n(and EDITOR set to emacsclient), I thought nobody would need --no-pager\n;-)\n"},{"id":"137954","messageId":"m2r5n5vlld.fsf@gmail.com","threadId":"23182","inReplyTo":"7v39zm7epf.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH 0/2] Teach 'git grep' about --open-files-in-pager=[<pager>]","fromName":"Francis Moreau","fromEmail":"francis.moro@gmail.com","sentAt":"2010-03-27T15:19:10Z","receivedAt":"2010-03-27T15:19:10Z","isPatch":true,"sender":{"key":"francis.moro@gmail.com","avatar":null},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> Francis Moreau <francis.moro@gmail.com> writes:\n>\n>>> and I often run \"git grep -n\" in that mode..\n>>\n>> I always need to pass the '--no-pager' switch: \"git --no-pager grep -n\"\n>> since git doesn't detect that its output is sent to a 'dumb' terminal.\n>\n> Sorry, but as any self-respecting Emacs user would have PAGER set to cat\n\nWell I do, but only for \"M-x shell\", probably because I usually start\nall commands from that shell.\n\n> (and EDITOR set to emacsclient), I thought nobody would need\n> --no-pager ;-)\n\nIndeed, I'll setup PAGER to cat when starting emacs.\n\nThat makes me think to one common operation I do which is not really\nconvenient when PAGER is set to cat: git-log. Piping the output of\ngit-log to a pager such as less(1) makes git-log to suspend when the\npipe is full. OTOH setting PAGER to cat, git-log never blocks and for\nprojects with a (very) long history such as git or the linux kernel,\ngit-log can show a lot of commits making the cpu really busy and the\nemacs buffer really huge.\n\nOne way to workaround this is to pass -n10 for example to git-log, but\nit's rather ugly.\n\nDo you have any tricks for this case ?\n\nThanks\n-- \nFrancis\n"},{"id":"137957","messageId":"7vbpe9u19g.fsf@alter.siamese.dyndns.org","threadId":"23182","inReplyTo":"m2r5n5vlld.fsf@gmail.com","subject":"Re: [PATCH 0/2] Teach 'git grep' about --open-files-in-pager=[<pager>]","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2010-03-27T17:23:39Z","receivedAt":"2010-03-27T17:23:39Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Francis Moreau <francis.moro@gmail.com> writes:\n\n> Do you have any tricks for this case ?\n\nI use PAGER=cat only inside Emacs, so I don't see how \"log\" can be a\nproblem.  Perhaps that is because I don't use \"M-x shell\" (I used to but\nnot anymore).  Of course you have to limit the extent of \"log\" in \"M-x\ncompile\" mode, but that goes without saying.\n\nI may have used some hooks when entering shell mode to tweak the\nenvironment further only under \"M-x shell\".\n"},{"id":"137973","messageId":"m2iq8hh5jl.fsf@gmail.com","threadId":"23182","inReplyTo":"7vbpe9u19g.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH 0/2] Teach 'git grep' about --open-files-in-pager=[<pager>]","fromName":"Francis Moreau","fromEmail":"francis.moro@gmail.com","sentAt":"2010-03-27T20:29:34Z","receivedAt":"2010-03-27T20:29:34Z","isPatch":true,"sender":{"key":"francis.moro@gmail.com","avatar":null},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> Francis Moreau <francis.moro@gmail.com> writes:\n>\n>> Do you have any tricks for this case ?\n>\n> I use PAGER=cat only inside Emacs, so I don't see how \"log\" can be a\n> problem.\n\nwhat do you mean by this ? Do you mean that you run git-log outside\nemacs ?\n\n> Of course you have to limit the extent of \"log\" in \"M-x compile\" mode,\n> but that goes without saying.\n\nYes but in this case (log inside emacs) I was actually wondering if you\nwere using any tricks to avoid limiting _manually_ the extent of\ngit-log. With PAGER=less for example, the extent is _automatically_\nlimited by the pipe, which I found convenient.\n\n-- \nFrancis\n"},{"id":"137992","messageId":"20100328040938.GA2017@progeny.tock","threadId":"23182","inReplyTo":"alpine.DEB.1.00.1003261149040.7596@pacific.mpi-cbg.de","subject":"Re: [PATCH 1/2] grep: Add the option '--open-files-in-pager'","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2010-03-28T04:09:38Z","receivedAt":"2010-03-28T04:09:38Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Hi,\n\nJohannes Schindelin wrote:\n\n> This adds an option to open the matching files in the pager, and if the\n> pager happens to be \"less\" (or \"vi\") and there is only one grep pattern,\n> it also jumps to the first match right away.\n\nSounds interesting.\n\n> diff --git a/builtin-grep.c b/builtin-grep.c\n> index 5d83d9b..233c772 100644\n\nI couldn’t get this to apply to current master or maint, and searching for\nblob 5d83d9b to find a more suitable merge base revealed that I don’t\nactually have that object in my repo.  Is this patch available already\napplied in a public git repo somewhere?\n\nHopeful,\nJonathan\n"},{"id":"138115","messageId":"alpine.DEB.1.00.1003291912281.7596@pacific.mpi-cbg.de","threadId":"23182","inReplyTo":"20100328040938.GA2017@progeny.tock","subject":"Re: [PATCH 1/2] grep: Add the option '--open-files-in-pager'","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2010-03-29T17:13:08Z","receivedAt":"2010-03-29T17:13:08Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Sat, 27 Mar 2010, Jonathan Nieder wrote:\n\n> Johannes Schindelin wrote:\n> \n> > diff --git a/builtin-grep.c b/builtin-grep.c\n> > index 5d83d9b..233c772 100644\n> \n> I couldn’t get this to apply to current master or maint, and searching \n> for blob 5d83d9b to find a more suitable merge base revealed that I \n> don’t actually have that object in my repo.  Is this patch available \n> already applied in a public git repo somewhere?\n\nYes, it is in 4msysgit.git's \"grep-P\" branch (still misnamed).\n\nCiao,\nDscho\n"},{"id":"138119","messageId":"7veij356xj.fsf@alter.siamese.dyndns.org","threadId":"23182","inReplyTo":"20100328040938.GA2017@progeny.tock","subject":"Re: [PATCH 1/2] grep: Add the option '--open-files-in-pager'","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2010-03-29T18:17:12Z","receivedAt":"2010-03-29T18:17:12Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jonathan Nieder <jrnieder@gmail.com> writes:\n\n> I couldn’t get this to apply to current master or maint, and searching for\n> blob 5d83d9b to find a more suitable merge base revealed that I don’t\n> actually have that object in my repo.  Is this patch available already\n> applied in a public git repo somewhere?\n\nThis seems to be based on a fork with a not-very-recent forkpoint.  I\nmanaged to create a topic branch and merged it to 'pu'.\n\nIt probably wants to be adjusted to --no-index mode, as that is also about\nfinding strings in files in the filesystem, but I chose not to do that\nmyself.  For this topic to go forward I think it needs a rebase to a more\nrecent 'master'.\n"}]}