git-pickaxe: allow "-L <something>,+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 <junkio@cox.net>
Junio C Hamano committed
Nov 7, 2006 at 16:20 UTC
7bd9641df5b7cca91b21bfdc587962c59700786c
1 file changed
+19
builtin-pickaxe.c
+19
@@ -1545,6 +1545,25 @@ static const char *parse_loc(const char *spec,
1545
regex_t regexp;
1546
regmatch_t match[1];
1547
1548
+ /* Allow "-L <something>,+20" to mean starting at <something>
1549
+ * for 20 lines, or "-L <something>,-5" for 5 lines ending at
1550
+ * <something>.
1551
+ */
1552
+ if (1 < begin && (spec[0] == '+' || spec[0] == '-')) {
1553
+ num = strtol(spec + 1, &term, 10);
1554
+ if (term != spec + 1) {
1555
+ if (spec[0] == '-')
1556
+ num = 0 - num;
1557
+ if (0 < num)
1558
+ *ret = begin + num - 2;
1559
+ else if (!num)
1560
+ *ret = begin;
1561
+ else
1562
+ *ret = begin + num;
1563
+ return term;
1564
+ }
1565
+ return spec;
1566
+ }
1567
num = strtol(spec, &term, 10);
1568
if (term != spec) {
1569
*ret = num;