Skip to content

Commit 80e0385

Browse files
pcloudsgitster
authored andcommitted
line-range.c: remove implicit dependency on the_index
Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent acd00ea commit 80e0385

File tree

4 files changed

+21
-13
lines changed

4 files changed

+21
-13
lines changed

builtin/blame.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1001,7 +1001,7 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
10011001
long bottom, top;
10021002
if (parse_range_arg(range_list.items[range_i].string,
10031003
nth_line_cb, &sb, lno, anchor,
1004-
&bottom, &top, sb.path))
1004+
&bottom, &top, sb.path, &the_index))
10051005
usage(blame_usage);
10061006
if ((!lno && (top || bottom)) || lno < bottom)
10071007
die(Q_("file %s has only %lu line",

line-log.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ parse_lines(struct repository *r, struct commit *commit,
574574
long begin = 0, end = 0;
575575
long anchor;
576576

577-
name_part = skip_range_arg(item->string);
577+
name_part = skip_range_arg(item->string, r->index);
578578
if (!name_part || *name_part != ':' || !name_part[1])
579579
die("-L argument not 'start,end:file' or ':funcname:file': %s",
580580
item->string);
@@ -599,7 +599,7 @@ parse_lines(struct repository *r, struct commit *commit,
599599

600600
if (parse_range_arg(range_part, nth_line, &cb_data,
601601
lines, anchor, &begin, &end,
602-
full_name))
602+
full_name, r->index))
603603
die("malformed -L argument '%s'", range_part);
604604
if ((!lines && (begin || end)) || lines < begin)
605605
die("file %s has only %lu lines", name_part, lines);

line-range.c

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,10 @@ static const char *find_funcname_matching_regexp(xdemitconf_t *xecfg, const char
163163
}
164164
}
165165

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)
169170
{
170171
char *pattern;
171172
const char *term;
@@ -198,7 +199,7 @@ static const char *parse_range_funcname(const char *arg, nth_line_fn_t nth_line_
198199
anchor--; /* input is in human terms */
199200
start = nth_line_cb(cb_data, anchor);
200201

201-
drv = userdiff_find_by_path(&the_index, path);
202+
drv = userdiff_find_by_path(istate, path);
202203
if (drv && drv->funcname.pattern) {
203204
const struct userdiff_funcname *pe = &drv->funcname;
204205
xecfg = xcalloc(1, sizeof(*xecfg));
@@ -244,7 +245,8 @@ static const char *parse_range_funcname(const char *arg, nth_line_fn_t nth_line_
244245

245246
int parse_range_arg(const char *arg, nth_line_fn_t nth_line_cb,
246247
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)
248250
{
249251
*begin = *end = 0;
250252

@@ -254,7 +256,9 @@ int parse_range_arg(const char *arg, nth_line_fn_t nth_line_cb,
254256
anchor = lines + 1;
255257

256258
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);
258262
if (!arg || *arg)
259263
return -1;
260264
return 0;
@@ -275,10 +279,12 @@ int parse_range_arg(const char *arg, nth_line_fn_t nth_line_cb,
275279
return 0;
276280
}
277281

278-
const char *skip_range_arg(const char *arg)
282+
const char *skip_range_arg(const char *arg, struct index_state *istate)
279283
{
280284
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);
282288

283289
arg = parse_loc(arg, NULL, NULL, 0, -1, NULL);
284290

line-range.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#ifndef LINE_RANGE_H
22
#define LINE_RANGE_H
33

4+
struct index_state;
5+
46
/*
57
* Parse one item in an -L begin,end option w.r.t. the notional file
68
* object 'cb_data' consisting of 'lines' lines.
@@ -23,7 +25,7 @@ int parse_range_arg(const char *arg,
2325
nth_line_fn_t nth_line_cb,
2426
void *cb_data, long lines, long anchor,
2527
long *begin, long *end,
26-
const char *path);
28+
const char *path, struct index_state *istate);
2729

2830
/*
2931
* Scan past a range argument that could be parsed by
@@ -34,6 +36,6 @@ int parse_range_arg(const char *arg,
3436
* NULL in case the argument is obviously malformed.
3537
*/
3638

37-
const char *skip_range_arg(const char *arg);
39+
const char *skip_range_arg(const char *arg, struct index_state *istate);
3840

3941
#endif /* LINE_RANGE_H */

0 commit comments

Comments
 (0)