diff options
Diffstat (limited to 'degesch.c')
-rw-r--r-- | degesch.c | 35 |
1 files changed, 33 insertions, 2 deletions
@@ -2652,7 +2652,39 @@ static void buffer_merge (struct app_context *ctx, struct buffer *buffer, struct buffer *merged) { - // TODO: try to merge the buffers as best as we can + // XXX: anything better to do? This situation is arguably rare and I'm + // not entirely sure what action to take. + buffer_send_status (ctx, buffer, + "Buffer %s was merged into this buffer", merged->name); + + // Find all lines from "merged" newer than the newest line in "buffer" + struct buffer_line *start = merged->lines; + if (buffer->lines_tail) + while (start && start->when < buffer->lines_tail->when) + start = start->next; + if (!start) + return; + + // Count how many of them we have + size_t n = 0; + for (struct buffer_line *iter = start; iter; iter = iter->next) + n++; + + // Append the merged part to current lines in the buffer + buffer->lines_tail->next = start; + start->prev = buffer->lines_tail; + + buffer->lines_tail = merged->lines_tail; + buffer->lines_count += n; + + // And remove it from the original buffer + if (start == merged->lines_tail) + if (!(merged->lines_tail = start->prev)) + merged->lines = NULL; + merged->lines_count -= n; + + // XXX: we don't want to log this entry to a file + buffer_send_status (ctx, buffer, "End of merged content"); } static void @@ -2672,7 +2704,6 @@ buffer_rename (struct app_context *ctx, // When there's a collision, there's not much else we can do // other than somehow trying to merge them buffer_merge (ctx, collision, buffer); - // TODO: log a status message about the merge if (ctx->current_buffer == buffer) buffer_activate (ctx, collision); buffer_remove (ctx, buffer); |