mirror of
https://github.com/git/git
synced 2024-10-01 06:05:20 +00:00
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>
This commit is contained in:
parent
acd00ea049
commit
80e0385541
|
@ -1001,7 +1001,7 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
|
||||||
long bottom, top;
|
long bottom, top;
|
||||||
if (parse_range_arg(range_list.items[range_i].string,
|
if (parse_range_arg(range_list.items[range_i].string,
|
||||||
nth_line_cb, &sb, lno, anchor,
|
nth_line_cb, &sb, lno, anchor,
|
||||||
&bottom, &top, sb.path))
|
&bottom, &top, sb.path, &the_index))
|
||||||
usage(blame_usage);
|
usage(blame_usage);
|
||||||
if ((!lno && (top || bottom)) || lno < bottom)
|
if ((!lno && (top || bottom)) || lno < bottom)
|
||||||
die(Q_("file %s has only %lu line",
|
die(Q_("file %s has only %lu line",
|
||||||
|
|
|
@ -574,7 +574,7 @@ parse_lines(struct repository *r, struct commit *commit,
|
||||||
long begin = 0, end = 0;
|
long begin = 0, end = 0;
|
||||||
long anchor;
|
long anchor;
|
||||||
|
|
||||||
name_part = skip_range_arg(item->string);
|
name_part = skip_range_arg(item->string, r->index);
|
||||||
if (!name_part || *name_part != ':' || !name_part[1])
|
if (!name_part || *name_part != ':' || !name_part[1])
|
||||||
die("-L argument not 'start,end:file' or ':funcname:file': %s",
|
die("-L argument not 'start,end:file' or ':funcname:file': %s",
|
||||||
item->string);
|
item->string);
|
||||||
|
@ -599,7 +599,7 @@ parse_lines(struct repository *r, struct commit *commit,
|
||||||
|
|
||||||
if (parse_range_arg(range_part, nth_line, &cb_data,
|
if (parse_range_arg(range_part, nth_line, &cb_data,
|
||||||
lines, anchor, &begin, &end,
|
lines, anchor, &begin, &end,
|
||||||
full_name))
|
full_name, r->index))
|
||||||
die("malformed -L argument '%s'", range_part);
|
die("malformed -L argument '%s'", range_part);
|
||||||
if ((!lines && (begin || end)) || lines < begin)
|
if ((!lines && (begin || end)) || lines < begin)
|
||||||
die("file %s has only %lu lines", name_part, lines);
|
die("file %s has only %lu lines", name_part, lines);
|
||||||
|
|
22
line-range.c
22
line-range.c
|
@ -163,9 +163,10 @@ static const char *find_funcname_matching_regexp(xdemitconf_t *xecfg, const char
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char *parse_range_funcname(const char *arg, nth_line_fn_t nth_line_cb,
|
static const char *parse_range_funcname(
|
||||||
void *cb_data, long lines, long anchor, long *begin, long *end,
|
const char *arg, nth_line_fn_t nth_line_cb,
|
||||||
const char *path)
|
void *cb_data, long lines, long anchor, long *begin, long *end,
|
||||||
|
const char *path, struct index_state *istate)
|
||||||
{
|
{
|
||||||
char *pattern;
|
char *pattern;
|
||||||
const char *term;
|
const char *term;
|
||||||
|
@ -198,7 +199,7 @@ static const char *parse_range_funcname(const char *arg, nth_line_fn_t nth_line_
|
||||||
anchor--; /* input is in human terms */
|
anchor--; /* input is in human terms */
|
||||||
start = nth_line_cb(cb_data, anchor);
|
start = nth_line_cb(cb_data, anchor);
|
||||||
|
|
||||||
drv = userdiff_find_by_path(&the_index, path);
|
drv = userdiff_find_by_path(istate, path);
|
||||||
if (drv && drv->funcname.pattern) {
|
if (drv && drv->funcname.pattern) {
|
||||||
const struct userdiff_funcname *pe = &drv->funcname;
|
const struct userdiff_funcname *pe = &drv->funcname;
|
||||||
xecfg = xcalloc(1, sizeof(*xecfg));
|
xecfg = xcalloc(1, sizeof(*xecfg));
|
||||||
|
@ -244,7 +245,8 @@ static const char *parse_range_funcname(const char *arg, nth_line_fn_t nth_line_
|
||||||
|
|
||||||
int parse_range_arg(const char *arg, nth_line_fn_t nth_line_cb,
|
int parse_range_arg(const char *arg, nth_line_fn_t nth_line_cb,
|
||||||
void *cb_data, long lines, long anchor,
|
void *cb_data, long lines, long anchor,
|
||||||
long *begin, long *end, const char *path)
|
long *begin, long *end,
|
||||||
|
const char *path, struct index_state *istate)
|
||||||
{
|
{
|
||||||
*begin = *end = 0;
|
*begin = *end = 0;
|
||||||
|
|
||||||
|
@ -254,7 +256,9 @@ int parse_range_arg(const char *arg, nth_line_fn_t nth_line_cb,
|
||||||
anchor = lines + 1;
|
anchor = lines + 1;
|
||||||
|
|
||||||
if (*arg == ':' || (*arg == '^' && *(arg + 1) == ':')) {
|
if (*arg == ':' || (*arg == '^' && *(arg + 1) == ':')) {
|
||||||
arg = parse_range_funcname(arg, nth_line_cb, cb_data, lines, anchor, begin, end, path);
|
arg = parse_range_funcname(arg, nth_line_cb, cb_data,
|
||||||
|
lines, anchor, begin, end,
|
||||||
|
path, istate);
|
||||||
if (!arg || *arg)
|
if (!arg || *arg)
|
||||||
return -1;
|
return -1;
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -275,10 +279,12 @@ int parse_range_arg(const char *arg, nth_line_fn_t nth_line_cb,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *skip_range_arg(const char *arg)
|
const char *skip_range_arg(const char *arg, struct index_state *istate)
|
||||||
{
|
{
|
||||||
if (*arg == ':' || (*arg == '^' && *(arg + 1) == ':'))
|
if (*arg == ':' || (*arg == '^' && *(arg + 1) == ':'))
|
||||||
return parse_range_funcname(arg, NULL, NULL, 0, 0, NULL, NULL, NULL);
|
return parse_range_funcname(arg, NULL, NULL,
|
||||||
|
0, 0, NULL, NULL,
|
||||||
|
NULL, istate);
|
||||||
|
|
||||||
arg = parse_loc(arg, NULL, NULL, 0, -1, NULL);
|
arg = parse_loc(arg, NULL, NULL, 0, -1, NULL);
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
#ifndef LINE_RANGE_H
|
#ifndef LINE_RANGE_H
|
||||||
#define LINE_RANGE_H
|
#define LINE_RANGE_H
|
||||||
|
|
||||||
|
struct index_state;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Parse one item in an -L begin,end option w.r.t. the notional file
|
* Parse one item in an -L begin,end option w.r.t. the notional file
|
||||||
* object 'cb_data' consisting of 'lines' lines.
|
* object 'cb_data' consisting of 'lines' lines.
|
||||||
|
@ -23,7 +25,7 @@ int parse_range_arg(const char *arg,
|
||||||
nth_line_fn_t nth_line_cb,
|
nth_line_fn_t nth_line_cb,
|
||||||
void *cb_data, long lines, long anchor,
|
void *cb_data, long lines, long anchor,
|
||||||
long *begin, long *end,
|
long *begin, long *end,
|
||||||
const char *path);
|
const char *path, struct index_state *istate);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Scan past a range argument that could be parsed by
|
* Scan past a range argument that could be parsed by
|
||||||
|
@ -34,6 +36,6 @@ int parse_range_arg(const char *arg,
|
||||||
* NULL in case the argument is obviously malformed.
|
* NULL in case the argument is obviously malformed.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const char *skip_range_arg(const char *arg);
|
const char *skip_range_arg(const char *arg, struct index_state *istate);
|
||||||
|
|
||||||
#endif /* LINE_RANGE_H */
|
#endif /* LINE_RANGE_H */
|
||||||
|
|
Loading…
Reference in a new issue