Skip to content

Commit

Permalink
Merge branch 'tr/line-log'
Browse files Browse the repository at this point in the history
Fix "log -L" command line parsing bugs.

* tr/line-log:
  t4211: fix incorrect rebase at f8395ed (range-set: satisfy non-empty ranges invariant)
  line-log: fix "log -LN" crash when N is last line of file
  range-set: satisfy non-empty ranges invariant
  t4211: demonstrate crash when first -L encountered is empty range
  t4211: demonstrate empty -L range crash
  range-set: fix sort_and_merge_range_set() corner case bug
  • Loading branch information
Junio C Hamano committed Jul 25, 2013
2 parents 6a90778 + d3a486c commit 1762224
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
9 changes: 6 additions & 3 deletions line-log.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,14 @@ static void range_set_check_invariants(struct range_set *rs)
static void sort_and_merge_range_set(struct range_set *rs)
{
int i;
int o = 1; /* output cursor */
int o = 0; /* output cursor */

qsort(rs->ranges, rs->nr, sizeof(struct range), range_cmp);

for (i = 1; i < rs->nr; i++) {
if (rs->ranges[i].start <= rs->ranges[o-1].end) {
for (i = 0; i < rs->nr; i++) {
if (rs->ranges[i].start == rs->ranges[i].end)
continue;
if (o > 0 && rs->ranges[i].start <= rs->ranges[o-1].end) {
if (rs->ranges[o-1].end < rs->ranges[i].end)
rs->ranges[o-1].end = rs->ranges[i].end;
} else {
Expand Down Expand Up @@ -297,6 +299,7 @@ static void line_log_data_insert(struct line_log_data **list,
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
13 changes: 13 additions & 0 deletions t/t4211-line-log.sh
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,17 @@ test_bad_opts "-L 1,1000:b.c" "has only.*lines"
test_bad_opts "-L :b.c" "argument.*not of the form"
test_bad_opts "-L :foo:b.c" "no match"

# There is a separate bug when an empty -L range is the first -L encountered,
# thus to demonstrate this particular bug, the empty -L range must follow a
# non-empty -L range.
test_expect_success '-L {empty-range} (any -L)' '
n=$(expr $(wc -l <b.c) + 1) &&
git log -L1,1:b.c -L$n:b.c
'

test_expect_success '-L {empty-range} (first -L)' '
n=$(expr $(wc -l <b.c) + 1) &&
git log -L$n:b.c
'

test_done

0 comments on commit 1762224

Please sign in to comment.