diff options
author | Přemysl Janouch <p.janouch@gmail.com> | 2015-06-21 21:50:47 +0200 |
---|---|---|
committer | Přemysl Janouch <p.janouch@gmail.com> | 2015-06-21 21:50:47 +0200 |
commit | e85c98f31588f2a8a5ad0aebf0e6e4840b8f3441 (patch) | |
tree | 263299cb12b12c666a56ac047bc20157af938f3f /degesch.c | |
parent | ce96be2d5edd516934d7f5d151effe22539b476c (diff) | |
download | xK-e85c98f31588f2a8a5ad0aebf0e6e4840b8f3441.tar.gz xK-e85c98f31588f2a8a5ad0aebf0e6e4840b8f3441.tar.xz xK-e85c98f31588f2a8a5ad0aebf0e6e4840b8f3441.zip |
degesch: implement the rest of buffer merging
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); |