{"thread":{"id":"23644","subject":"[PATCH] blame: add a range option to -L","startedAt":"2010-04-30T21:29:49Z","lastAt":"2010-05-03T13:22:57Z","messageCount":6,"participants":["Bill Pemberton","Jonathan Nieder","Michael Witten","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"140660","messageId":"1272662989-563-1-git-send-email-wfp5p@virginia.edu","threadId":"23644","inReplyTo":null,"subject":"[PATCH] blame: add a range option to -L","fromName":"Bill Pemberton","fromEmail":"wfp5p@virginia.edu","sentAt":"2010-04-30T21:29:49Z","receivedAt":"2010-04-30T21:29:49Z","isPatch":true,"sender":{"key":"wfp5p@virginia.edu","avatar":null},"body":"In addition to + and - you can now use r to specify how many lines\naround <start> that you want to see.  For example: -L 20,r5 would show\nlines 15 through 25\n\nSigned-off-by: Bill Pemberton <wfp5p@virginia.edu>\n---\n\nI've been using a perl wrapper script to get this functionality.\nIn case others may find this a useful feature, I went ahead and\nadded it to blame.c\n\n\n Documentation/blame-options.txt |    6 ++++++\n Documentation/git-blame.txt     |    6 ++++++\n builtin/blame.c                 |   19 +++++++++++++++++--\n 3 files changed, 29 insertions(+), 2 deletions(-)\n\ndiff --git a/Documentation/blame-options.txt b/Documentation/blame-options.txt\nindex d820569..acbbc91 100644\n--- a/Documentation/blame-options.txt\n+++ b/Documentation/blame-options.txt\n@@ -32,6 +32,12 @@ This is only valid for <end> and will specify a number\n of lines before or after the line given by <start>.\n +\n \n+- rrange\n++\n+This is only valid for <end> and will specify a number\n+of lines before and after the line given by <start>.\n++\n+\n -l::\n \tShow long rev (Default: off).\n \ndiff --git a/Documentation/git-blame.txt b/Documentation/git-blame.txt\nindex a27f439..7a9b99a 100644\n--- a/Documentation/git-blame.txt\n+++ b/Documentation/git-blame.txt\n@@ -110,6 +110,12 @@ line 40):\n \tgit blame -L 40,60 foo\n \tgit blame -L 40,+21 foo\n \n+A range of lines around a particular line can be shown by using 'r'\n+before the second number.  If you wanted to see line 20 along with the\n+5 lines around it:\n+\n+  \tgit blame -L 20,r5 foo\n+\n Also you can use a regular expression to specify the line range:\n \n \tgit blame -L '/^sub hello {/,/^}$/' foo\ndiff --git a/builtin/blame.c b/builtin/blame.c\nindex fc15863..03a8948 100644\n--- a/builtin/blame.c\n+++ b/builtin/blame.c\n@@ -1887,13 +1887,18 @@ static const char *parse_loc(const char *spec,\n \t/* Allow \"-L <something>,+20\" to mean starting at <something>\n \t * for 20 lines, or \"-L <something>,-5\" for 5 lines ending at\n \t * <something>.\n+\t * In addition \"-L <something>,r5\" means starting at\n+\t * <something>-5 and ending at <something>+5\n \t */\n-\tif (1 < begin && (spec[0] == '+' || spec[0] == '-')) {\n+\tif (1 < begin &&\n+\t    (spec[0] == '+' || spec[0] == '-' || spec[0] == 'r')) {\n \t\tnum = strtol(spec + 1, &term, 10);\n \t\tif (term != spec + 1) {\n \t\t\tif (spec[0] == '-')\n \t\t\t\tnum = 0 - num;\n-\t\t\tif (0 < num)\n+\t\t\tif (spec[0] == 'r')\n+\t\t\t\t*ret = 0 - num;\n+\t\t\telse if (0 < num)\n \t\t\t\t*ret = begin + num - 2;\n \t\t\telse if (!num)\n \t\t\t\t*ret = begin;\n@@ -1960,6 +1965,16 @@ static void prepare_blame_range(struct scoreboard *sb,\n \tterm = parse_loc(bottomtop, sb, lno, 1, bottom);\n \tif (*term == ',') {\n \t\tterm = parse_loc(term + 1, sb, lno, *bottom + 1, top);\n+\n+\t\t/* if top is negative then top is actually a range\n+\t\t   that was specified with the r option */\n+\t\tif (*top < 1) {\n+\t\t    long x = *top;\n+\t\t    *top = *bottom - x;\n+\t\t    *bottom += x;\n+\t\t    if (*bottom < 1)\n+\t\t\t*bottom = 1;\n+\t\t}\n \t\tif (*term)\n \t\t\tusage(blame_usage);\n \t}\n-- \n1.7.0.6\n"},{"id":"140744","messageId":"20100502091433.GA1854@progeny.tock","threadId":"23644","inReplyTo":"1272662989-563-1-git-send-email-wfp5p@virginia.edu","subject":"Re: [PATCH] blame: add a range option to -L","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2010-05-02T09:14:34Z","receivedAt":"2010-05-02T09:14:34Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Bill Pemberton wrote:\n\n> In addition to + and - you can now use r to specify how many lines\n> around <start> that you want to see.  For example: -L 20,r5 would show\n> lines 15 through 25\n\nFrom too much exposure to subversion, the r suggests “revision”.\nBut ± is too hard to type, so I guess r will have to do.\n\n> +++ b/Documentation/blame-options.txt\n> @@ -32,6 +32,12 @@ This is only valid for <end> and will specify a number\n>  of lines before or after the line given by <start>.\n>  +\n>  \n> +- rrange\n\nMaybe -rradius?  “range” sounds like an interval with specified endpoints.\n\n> +\t\t/* if top is negative then top is actually a range\n> +\t\t   that was specified with the r option */\n> +\t\tif (*top < 1) {\n> +\t\t    long x = *top;\n> +\t\t    *top = *bottom - x;\n> +\t\t    *bottom += x;\n> +\t\t    if (*bottom < 1)\n> +\t\t\t*bottom = 1;\n> +\t\t}\n\nHow does this treat -L 5,-10?\n\nJonathan\n"},{"id":"140763","messageId":"y2mb4087cc51005020544i7dd5c922y15aab5f64797193d@mail.gmail.com","threadId":"23644","inReplyTo":"20100502091433.GA1854@progeny.tock","subject":"Re: [PATCH] blame: add a range option to -L","fromName":"Michael Witten","fromEmail":"mfwitten@gmail.com","sentAt":"2010-05-02T12:44:09Z","receivedAt":"2010-05-02T12:44:09Z","isPatch":true,"sender":{"key":"mfwitten@gmail.com","avatar":"https://avatars.githubusercontent.com/u/597101?v=4"},"body":"On Sun, May 2, 2010 at 04:14, Jonathan Nieder <jrnieder@gmail.com> wrote:\n>\n> From too much exposure to subversion, the r suggests “revision”.\n> But ± is too hard to type, so I guess r will have to do.\n\nHow about '=' ?\n\nHow about '%' (for above and below)?\n"},{"id":"140778","messageId":"7vvdb6uy2w.fsf@alter.siamese.dyndns.org","threadId":"23644","inReplyTo":"20100502091433.GA1854@progeny.tock","subject":"Re: [PATCH] blame: add a range option to -L","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2010-05-02T15:23:35Z","receivedAt":"2010-05-02T15:23:35Z","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> Bill Pemberton wrote:\n>\n>> In addition to + and - you can now use r to specify how many lines\n>> around <start> that you want to see.  For example: -L 20,r5 would show\n>> lines 15 through 25\n>\n>>From too much exposure to subversion, the r suggests “revision”.\n> But ± is too hard to type, so I guess r will have to do.\n\nI am not interested in this patch very much myself, and after thinking\nabout it, I think my dislike largely comes from this syntax, and not from\nthe feature itself.  Any non-punctuation letter there looks like a sore\nthumb.  Either \"-L 20±5\" or even \"-L 20+/-5\" would have looked a _lot_\nsaner.\n\n>> +++ b/Documentation/blame-options.txt\n>> @@ -32,6 +32,12 @@ This is only valid for <end> and will specify a number\n>>  of lines before or after the line given by <start>.\n>>  +\n>>  \n>> +- rrange\n>\n> Maybe -rradius?  “range” sounds like an interval with specified endpoints.\n\nYes, radius sounds more sensible.  Another alternative would be to call it\n\"context\", as in \"grep -C <n>\".\n"},{"id":"140824","messageId":"20100503124610.DB96C41205@viridian.itc.virginia.edu","threadId":"23644","inReplyTo":"20100502091433.GA1854@progeny.tock","subject":"Re: [PATCH] blame: add a range option to -L","fromName":"Bill Pemberton","fromEmail":"wfp5p@viridian.itc.virginia.edu","sentAt":"2010-05-03T12:46:10Z","receivedAt":"2010-05-03T12:46:10Z","isPatch":true,"sender":{"key":"wfp5p@viridian.itc.virginia.edu","avatar":null},"body":"> > In addition to + and - you can now use r to specify how many lines\n> > around <start> that you want to see.  For example: -L 20,r5 would show\n> > lines 15 through 25\n> \n> >From too much exposure to subversion, the r suggests ârevisionâ.\n> But Â± is too hard to type, so I guess r will have to do.\n> \n\nI wasn't too thrilled with using r either, but I couldn't think of\nanything better.\n\n\n> > +\t\t/* if top is negative then top is actually a range\n> > +\t\t   that was specified with the r option */\n> > +\t\tif (*top < 1) {\n> > +\t\t    long x = *top;\n> > +\t\t    *top = *bottom - x;\n> > +\t\t    *bottom += x;\n> > +\t\t    if (*bottom < 1)\n> > +\t\t\t*bottom = 1;\n> > +\t\t}\n> \n> How does this treat -L 5,-10?\n> \n\nYes, you're correct, my code will mess that up.  I thought I had\nverified that parse_loc() would never return a number less than 1 as\n*top, but looking again I see I didn't do that.  So my patch is no\ngood.  Sorry folks.\n\n-- \nBill Pemberton                                 wfp5p@virginia.edu\nITC/Unix Systems                               flash@virginia.edu\nUniversity of Virginia\n"},{"id":"140829","messageId":"20100503132257.CE99641205@viridian.itc.virginia.edu","threadId":"23644","inReplyTo":"7vvdb6uy2w.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH] blame: add a range option to -L","fromName":"Bill Pemberton","fromEmail":"wfp5p@viridian.itc.virginia.edu","sentAt":"2010-05-03T13:22:57Z","receivedAt":"2010-05-03T13:22:57Z","isPatch":true,"sender":{"key":"wfp5p@viridian.itc.virginia.edu","avatar":null},"body":"Junio C Hamano writes:\n> \n \n> I am not interested in this patch very much myself, and after thinking\n> about it, I think my dislike largely comes from this syntax, and not from\n> the feature itself.  Any non-punctuation letter there looks like a sore\n> thumb.  Either \"-L 20??15\" or even \"-L 20+/-5\" would have looked a _lo=\n> t_\n> saner.\n> \n\nOk, I've never been thrilled with the r either, but I couldn't come up\nwith anything better and I had assumed that you'd want to stick with\nthe <start>,<end> syntax.\n\n-- \nBill\n"}]}