* started by showing sline[lno] (possibly showing the lost
* lines attached to it first).
*/
- for (lno = 0, p_lno = 1; lno < cnt; lno++) {
+ for (lno = 0, p_lno = 1; lno <= cnt; lno++) {
struct lline *ll;
sline[lno].p_lno[n] = p_lno;
p_lno++; /* '-' means parent had it */
ll = ll->next;
}
- if (!(sline[lno].flag & nmask))
+ if (lno < cnt && !(sline[lno].flag & nmask))
p_lno++; /* no '+' means parent had it */
}
sline[lno].p_lno[n] = p_lno; /* trailer */
int hunk_end;
while (lno < cnt && !(sline[lno].flag & mark))
lno++;
- if (cnt <= lno)
+ if (cnt < lno)
break;
- for (hunk_end = lno + 1; hunk_end < cnt; hunk_end++)
- if (!(sline[hunk_end].flag & mark))
+ else if (cnt == lno) {
+ /* See if there is anything interesting */
+ struct lline *ll;
+ for (ll = sline[lno].lost_head; ll; ll = ll->next)
+ if (ll->parent_map)
+ break;
+ if (!ll)
break;
+ hunk_end = cnt + 1;
+ }
+ else {
+ for (hunk_end = lno + 1; hunk_end < cnt; hunk_end++)
+ if (!(sline[hunk_end].flag & mark))
+ break;
+ }
for (i = 0; i <= num_parent; i++) putchar(combine_marker);
for (i = 0; i < num_parent; i++)
show_parent_lno(sline, lno, hunk_end, cnt, i);
- printf(" +%lu,%lu ", lno+1, hunk_end-lno);
+ printf(" +%lu,%lu ", lno+1,
+ (cnt == lno) ? 0 : hunk_end - lno);
for (i = 0; i <= num_parent; i++) putchar(combine_marker);
putchar('\n');
while (lno < hunk_end) {
puts(ll->line);
ll = ll->next;
}
+ if (cnt <= lno)
+ break;
p_mask = 1;
for (j = 0; j < num_parent; j++) {
if (p_mask & sl->flag)
imask = (1UL<<i);
jmask = (1UL<<j);
- for (lno = 0; lno < cnt; lno++) {
+ for (lno = 0; lno <= cnt; lno++) {
struct lline *ll = sline->lost_head;
sline->p_lno[i] = sline->p_lno[j];
while (ll) {
if (result_size && result[result_size-1] != '\n')
cnt++; /* incomplete line */
- sline = xcalloc(cnt+1, sizeof(*sline));
+ sline = xcalloc(cnt+2, sizeof(*sline));
ep = result;
sline[0].bol = result;
- for (lno = 0; lno <= cnt; lno++) {
+ for (lno = 0; lno <= cnt + 1; lno++) {
sline[lno].lost_tail = &sline[lno].lost_head;
sline[lno].flag = 0;
}
result_file.ptr = result;
result_file.size = result_size;
- sline[0].p_lno = xcalloc((cnt+1) * num_parent, sizeof(unsigned long));
- for (lno = 0; lno < cnt; lno++)
+ /* Even p_lno[cnt+1] is valid -- that is for the end line number
+ * for deletion hunk at the end.
+ */
+ sline[0].p_lno = xcalloc((cnt+2) * num_parent, sizeof(unsigned long));
+ for (lno = 0; lno <= cnt; lno++)
sline[lno+1].p_lno = sline[lno].p_lno + num_parent;
for (i = 0; i < num_parent; i++) {