From 7bd9641df5b7cca91b21bfdc587962c59700786c Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Tue, 7 Nov 2006 16:20:02 -0800 Subject: [PATCH] git-pickaxe: allow "-L ,+N" With this, git pickaxe -L '/--progress/,+20' v1.4.0 -- pack-objects.c gives you 20 lines starting from the first occurrence of '--progress' in pack-objects, digging from v1.4.0 version. You can also say git pickaxe -L '/--progress/,-5' v1.4.0 -- pack-objects.c Signed-off-by: Junio C Hamano --- builtin-pickaxe.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/builtin-pickaxe.c b/builtin-pickaxe.c index 673185f96..64999f357 100644 --- a/builtin-pickaxe.c +++ b/builtin-pickaxe.c @@ -1545,6 +1545,25 @@ static const char *parse_loc(const char *spec, regex_t regexp; regmatch_t match[1]; + /* Allow "-L ,+20" to mean starting at + * for 20 lines, or "-L ,-5" for 5 lines ending at + * . + */ + if (1 < begin && (spec[0] == '+' || spec[0] == '-')) { + num = strtol(spec + 1, &term, 10); + if (term != spec + 1) { + if (spec[0] == '-') + num = 0 - num; + if (0 < num) + *ret = begin + num - 2; + else if (!num) + *ret = begin; + else + *ret = begin + num; + return term; + } + return spec; + } num = strtol(spec, &term, 10); if (term != spec) { *ret = num; -- 2.30.2