Skip to content

Commit

Permalink
log: teach -L/RE/ to search from end of previous -L range
Browse files Browse the repository at this point in the history
This is complicated slightly by having to remember the previous -L range
for each file specified via -L<range>:file.

The existing implementation coalesces ranges for each file as each -L is
parsed which makes it impossible to refer back to the previous -L range
for any particular file. Re-implement to instead store each file's set
of -L ranges verbatim, and then coalesce the ranges in a post-processing
step.

Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Eric Sunshine authored and Junio C Hamano committed Aug 6, 2013
1 parent 52f4d12 commit 3e0d79d
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions line-log.c
Original file line number Diff line number Diff line change
Expand Up @@ -291,15 +291,13 @@ static void line_log_data_insert(struct line_log_data **list,

if (p) {
range_set_append_unsafe(&p->ranges, begin, end);
sort_and_merge_range_set(&p->ranges);
free(path);
return;
}

p = xcalloc(1, sizeof(struct line_log_data));
p->path = path;
range_set_append(&p->ranges, begin, end);
sort_and_merge_range_set(&p->ranges);
if (ip) {
p->next = ip->next;
ip->next = p;
Expand Down Expand Up @@ -566,12 +564,14 @@ parse_lines(struct commit *commit, const char *prefix, struct string_list *args)
struct nth_line_cb cb_data;
struct string_list_item *item;
struct line_log_data *ranges = NULL;
struct line_log_data *p;

for_each_string_list_item(item, args) {
const char *name_part, *range_part;
char *full_name;
struct diff_filespec *spec;
long begin = 0, end = 0;
long anchor;

name_part = skip_range_arg(item->string);
if (!name_part || *name_part != ':' || !name_part[1])
Expand All @@ -590,8 +590,14 @@ parse_lines(struct commit *commit, const char *prefix, struct string_list *args)
cb_data.lines = lines;
cb_data.line_ends = ends;

p = search_line_log_data(ranges, full_name, NULL);
if (p && p->ranges.nr)
anchor = p->ranges.ranges[p->ranges.nr - 1].end + 1;
else
anchor = 1;

if (parse_range_arg(range_part, nth_line, &cb_data,
lines, 1, &begin, &end,
lines, anchor, &begin, &end,
full_name))
die("malformed -L argument '%s'", range_part);
if (lines < end || ((lines || begin) && lines < begin))
Expand All @@ -608,6 +614,9 @@ parse_lines(struct commit *commit, const char *prefix, struct string_list *args)
ends = NULL;
}

for (p = ranges; p; p = p->next)
sort_and_merge_range_set(&p->ranges);

return ranges;
}

Expand Down

0 comments on commit 3e0d79d

Please sign in to comment.