Implement line-history search (git log -L)
[gitweb.git] / line-range.c
index 5a226abdd02fb4553adf4bce47cde76bb72f83a5..7a7ca3c2bde9c7bf6b1ae29537b42389c11bd8e9 100644 (file)
@@ -21,6 +21,8 @@ static const char *parse_loc(const char *spec, nth_line_fn_t nth_line,
        if (1 < begin && (spec[0] == '+' || spec[0] == '-')) {
                num = strtol(spec + 1, &term, 10);
                if (term != spec + 1) {
+                       if (!ret)
+                               return term;
                        if (spec[0] == '-')
                                num = 0 - num;
                        if (0 < num)
@@ -35,7 +37,8 @@ static const char *parse_loc(const char *spec, nth_line_fn_t nth_line,
        }
        num = strtol(spec, &term, 10);
        if (term != spec) {
-               *ret = num;
+               if (ret)
+                       *ret = num;
                return term;
        }
        if (spec[0] != '/')
@@ -49,6 +52,10 @@ static const char *parse_loc(const char *spec, nth_line_fn_t nth_line,
        if (*term != '/')
                return spec;
 
+       /* in the scan-only case we are not interested in the regex */
+       if (!ret)
+               return term+1;
+
        /* try [spec+1 .. term-1] as regexp */
        *term = 0;
        begin--; /* input is in human terms */
@@ -90,3 +97,13 @@ int parse_range_arg(const char *arg, nth_line_fn_t nth_line_cb,
 
        return 0;
 }
+
+const char *skip_range_arg(const char *arg)
+{
+       arg = parse_loc(arg, NULL, NULL, 0, -1, NULL);
+
+       if (*arg == ',')
+               arg = parse_loc(arg+1, NULL, NULL, 0, 0, NULL);
+
+       return arg;
+}