line-range.c: remove implicit dependency on the_index
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Nguyễn Thái Ngọc Duy committed
Sep 21, 2018 at 17:57 UTC
80e03855413c7ac3727df572d44131656e467426
4 files changed
+21
-13
builtin/blame.c
+1
-1
@@ -1001,7 +1001,7 @@ parse_done:
1001
long bottom, top;
1002
if (parse_range_arg(range_list.items[range_i].string,
1003
nth_line_cb, &sb, lno, anchor,
1004
- &bottom, &top, sb.path))
1004
+ &bottom, &top, sb.path, &the_index))
1005
usage(blame_usage);
1006
if ((!lno && (top || bottom)) || lno < bottom)
1007
die(Q_("file %s has only %lu line",
line-log.c
+2
-2
@@ -574,7 +574,7 @@ parse_lines(struct repository *r, struct commit *commit,
574
long begin = 0, end = 0;
575
long anchor;
576
577
- name_part = skip_range_arg(item->string);
577
+ name_part = skip_range_arg(item->string, r->index);
578
if (!name_part || *name_part != ':' || !name_part[1])
579
die("-L argument not 'start,end:file' or ':funcname:file': %s",
580
item->string);
@@ -599,7 +599,7 @@ parse_lines(struct repository *r, struct commit *commit,
599
600
if (parse_range_arg(range_part, nth_line, &cb_data,
601
lines, anchor, &begin, &end,
602
- full_name))
602
+ full_name, r->index))
603
die("malformed -L argument '%s'", range_part);
604
if ((!lines && (begin || end)) || lines < begin)
605
die("file %s has only %lu lines", name_part, lines);
line-range.c
+14
-8
@@ -163,9 +163,10 @@ static const char *find_funcname_matching_regexp(xdemitconf_t *xecfg, const char
163
}
164
}
165
166
-static const char *parse_range_funcname(const char *arg, nth_line_fn_t nth_line_cb,
167
- void *cb_data, long lines, long anchor, long *begin, long *end,
168
- const char *path)
166
+static const char *parse_range_funcname(
167
+ const char *arg, nth_line_fn_t nth_line_cb,
168
+ void *cb_data, long lines, long anchor, long *begin, long *end,
169
+ const char *path, struct index_state *istate)
170
{
171
char *pattern;
172
const char *term;
@@ -198,7 +199,7 @@ static const char *parse_range_funcname(const char *arg, nth_line_fn_t nth_line_
199
anchor--; /* input is in human terms */
200
start = nth_line_cb(cb_data, anchor);
201
201
- drv = userdiff_find_by_path(&the_index, path);
202
+ drv = userdiff_find_by_path(istate, path);
203
if (drv && drv->funcname.pattern) {
204
const struct userdiff_funcname *pe = &drv->funcname;
205
xecfg = xcalloc(1, sizeof(*xecfg));
@@ -244,7 +245,8 @@ static const char *parse_range_funcname(const char *arg, nth_line_fn_t nth_line_
245
246
int parse_range_arg(const char *arg, nth_line_fn_t nth_line_cb,
247
void *cb_data, long lines, long anchor,
247
- long *begin, long *end, const char *path)
248
+ long *begin, long *end,
249
+ const char *path, struct index_state *istate)
250
{
251
*begin = *end = 0;
252
@@ -254,7 +256,9 @@ int parse_range_arg(const char *arg, nth_line_fn_t nth_line_cb,
256
anchor = lines + 1;
257
258
if (*arg == ':' || (*arg == '^' && *(arg + 1) == ':')) {
257
- arg = parse_range_funcname(arg, nth_line_cb, cb_data, lines, anchor, begin, end, path);
259
+ arg = parse_range_funcname(arg, nth_line_cb, cb_data,
260
+ lines, anchor, begin, end,
261
+ path, istate);
262
if (!arg || *arg)
263
return -1;
264
return 0;
@@ -275,10 +279,12 @@ int parse_range_arg(const char *arg, nth_line_fn_t nth_line_cb,
279
return 0;
280
}
281
278
-const char *skip_range_arg(const char *arg)
282
+const char *skip_range_arg(const char *arg, struct index_state *istate)
283
{
284
if (*arg == ':' || (*arg == '^' && *(arg + 1) == ':'))
281
- return parse_range_funcname(arg, NULL, NULL, 0, 0, NULL, NULL, NULL);
285
+ return parse_range_funcname(arg, NULL, NULL,
286
+ 0, 0, NULL, NULL,
287
+ NULL, istate);
288
289
arg = parse_loc(arg, NULL, NULL, 0, -1, NULL);
290
line-range.h
+4
-2
@@ -1,6 +1,8 @@
1
#ifndef LINE_RANGE_H
2
#define LINE_RANGE_H
3
4
+struct index_state;
5
+
6
/*
7
* Parse one item in an -L begin,end option w.r.t. the notional file
8
* object 'cb_data' consisting of 'lines' lines.
@@ -23,7 +25,7 @@ int parse_range_arg(const char *arg,
25
nth_line_fn_t nth_line_cb,
26
void *cb_data, long lines, long anchor,
27
long *begin, long *end,
26
- const char *path);
28
+ const char *path, struct index_state *istate);
29
30
/*
31
* Scan past a range argument that could be parsed by
@@ -34,6 +36,6 @@ int parse_range_arg(const char *arg,
36
* NULL in case the argument is obviously malformed.
37
*/
38
37
-const char *skip_range_arg(const char *arg);
39
+const char *skip_range_arg(const char *arg, struct index_state *istate);
40
41
#endif /* LINE_RANGE_H */