@matheusbsbs / matheus-bagliano / commits / 740659519e
Fork 0

combine-diff: fix hunks at the end (take #2).

The previous round showed the delete-only hunks at the end, but forgot to mark them interesting when they were. Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Apr 11, 2006 at 14:31 UTC 740659519e0b30bc6b64f00ba69825294c40db07
1 file changed +21 -28
combine-diff.c
+21 -28
@@ -301,14 +301,14 @@ static unsigned long find_next(struct sline *sline,
301 * lines that are not interesting to interesting() function
302 * that are surrounded by interesting() ones.
303 */
304 - while (i < cnt)
304 + while (i <= cnt)
305 if (uninteresting
306 ? !(sline[i].flag & mark)
307 : (sline[i].flag & mark))
308 return i;
309 else
310 i++;
311 - return cnt;
311 + return i;
312 }
313
314 static int give_context(struct sline *sline, unsigned long cnt, int num_parent)
@@ -327,10 +327,10 @@ static int give_context(struct sline *sline, unsigned long cnt, int num_parent)
327 * lines but they are treated as "interesting" in the end.
328 */
329 i = find_next(sline, mark, 0, cnt, 0);
330 - if (cnt <= i)
330 + if (cnt < i)
331 return 0;
332
333 - while (i < cnt) {
333 + while (i <= cnt) {
334 unsigned long j = (context < i) ? (i - context) : 0;
335 unsigned long k;
336
@@ -343,7 +343,7 @@ static int give_context(struct sline *sline, unsigned long cnt, int num_parent)
343 * next uninteresting one start?
344 */
345 j = find_next(sline, mark, i, cnt, 1);
346 - if (cnt <= j)
346 + if (cnt < j)
347 break; /* the rest are all interesting */
348
349 /* lookahead context lines */
@@ -365,7 +365,7 @@ static int give_context(struct sline *sline, unsigned long cnt, int num_parent)
365 * the trailing edge a bit.
366 */
367 i = k;
368 - k = (j + context < cnt) ? j + context : cnt;
368 + k = (j + context < cnt+1) ? j + context : cnt+1;
369 while (j < k)
370 sline[j++].flag |= mark;
371 }
@@ -380,7 +380,7 @@ static int make_hunks(struct sline *sline, unsigned long cnt,
380 unsigned long i;
381 int has_interesting = 0;
382
383 - for (i = 0; i < cnt; i++) {
383 + for (i = 0; i <= cnt; i++) {
384 if (interesting(&sline[i], all_mask))
385 sline[i].flag |= mark;
386 else
@@ -394,15 +394,15 @@ static int make_hunks(struct sline *sline, unsigned long cnt,
394 * parent, mark that uninteresting.
395 */
396 i = 0;
397 - while (i < cnt) {
397 + while (i <= cnt) {
398 unsigned long j, hunk_begin, hunk_end;
399 unsigned long same_diff;
400 - while (i < cnt && !(sline[i].flag & mark))
400 + while (i <= cnt && !(sline[i].flag & mark))
401 i++;
402 - if (cnt <= i)
402 + if (cnt < i)
403 break; /* No more interesting hunks */
404 hunk_begin = i;
405 - for (j = i + 1; j < cnt; j++) {
405 + for (j = i + 1; j <= cnt; j++) {
406 if (!(sline[j].flag & mark)) {
407 /* Look beyond the end to see if there
408 * is an interesting line after this
@@ -412,8 +412,8 @@ static int make_hunks(struct sline *sline, unsigned long cnt,
412 int contin = 0;
413 la = adjust_hunk_tail(sline, all_mask,
414 hunk_begin, j);
415 - la = (la + context < cnt) ?
416 - (la + context) : cnt;
415 + la = (la + context < cnt + 1) ?
416 + (la + context) : cnt + 1;
417 while (j <= --la) {
418 if (sline[la].flag & mark) {
419 contin = 1;
@@ -507,30 +507,23 @@ static void dump_sline(struct sline *sline, unsigned long cnt, int num_parent)
507 while (1) {
508 struct sline *sl = &sline[lno];
509 int hunk_end;
510 - while (lno < cnt && !(sline[lno].flag & mark))
510 + int rlines;
511 + while (lno <= cnt && !(sline[lno].flag & mark))
512 lno++;
513 if (cnt < lno)
514 break;
514 - else if (cnt == lno) {
515 - /* See if there is anything interesting */
516 - struct lline *ll;
517 - for (ll = sline[lno].lost_head; ll; ll = ll->next)
518 - if (ll->parent_map)
519 - break;
520 - if (!ll)
521 - break;
522 - hunk_end = cnt + 1;
523 - }
515 else {
525 - for (hunk_end = lno + 1; hunk_end < cnt; hunk_end++)
516 + for (hunk_end = lno + 1; hunk_end <= cnt; hunk_end++)
517 if (!(sline[hunk_end].flag & mark))
518 break;
519 }
520 + rlines = hunk_end - lno;
521 + if (cnt < hunk_end)
522 + rlines--; /* pointing at the last delete hunk */
523 for (i = 0; i <= num_parent; i++) putchar(combine_marker);
524 for (i = 0; i < num_parent; i++)
525 show_parent_lno(sline, lno, hunk_end, cnt, i);
532 - printf(" +%lu,%lu ", lno+1,
533 - (cnt == lno) ? 0 : hunk_end - lno);
526 + printf(" +%lu,%lu ", lno+1, rlines);
527 for (i = 0; i <= num_parent; i++) putchar(combine_marker);
528 putchar('\n');
529 while (lno < hunk_end) {
@@ -549,7 +542,7 @@ static void dump_sline(struct sline *sline, unsigned long cnt, int num_parent)
542 puts(ll->line);
543 ll = ll->next;
544 }
552 - if (cnt <= lno)
545 + if (cnt < lno)
546 break;
547 p_mask = 1;
548 for (j = 0; j < num_parent; j++) {