From 9b4310b10f410fa12c13bbfb3631395fbacfae68 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sat, 19 Nov 2016 22:39:58 -0800 Subject: [PATCH] Ensure we clear first_unwritten_new_item_index after history::merge Prevents an issue where we think we've written out history items, but we haven't, and so they get lost. Fixes #3496 --- src/fish_tests.cpp | 18 ++++++++++++++++++ src/history.cpp | 1 + 2 files changed, 19 insertions(+) diff --git a/src/fish_tests.cpp b/src/fish_tests.cpp index 9419ce0da..a438e9e95 100644 --- a/src/fish_tests.cpp +++ b/src/fish_tests.cpp @@ -2820,6 +2820,24 @@ void history_tests_t::test_history_merge(void) { } } + // Make sure incorporate_external_changes doesn't drop items! (#3496) + history_t * const writer = hists[0]; + history_t * const reader = hists[1]; + const wcstring more_texts[] = { + L"Item_#3496_1", L"Item_#3496_2", L"Item_#3496_3", L"Item_#3496_4", + L"Item_#3496_5", L"Item_#3496_6" + }; + for (size_t i=0; i < sizeof more_texts / sizeof *more_texts; i++) { + // time_barrier because merging will ignore items that may be newer + if (i > 0) time_barrier(); + writer->add(more_texts[i]); + writer->incorporate_external_changes(); + reader->incorporate_external_changes(); + for (size_t j=0; j < i; j++) { + do_test(history_contains(reader, more_texts[j])); + } + } + // Clean up. for (size_t i = 0; i < 3; i++) { delete hists[i]; diff --git a/src/history.cpp b/src/history.cpp index 9b2d0dd85..11fb59d5b 100644 --- a/src/history.cpp +++ b/src/history.cpp @@ -1652,6 +1652,7 @@ void history_t::incorporate_external_changes() { // We'll pick them up from the file (#2312) this->save_internal(false); this->new_items.clear(); + this->first_unwritten_new_item_index = 0; } }