mirror of
https://github.com/martinvonz/jj.git
synced 2024-10-26 08:37:49 +00:00
stacked_table: do not remove head on empty save_table()
If the head is unchanged, it shouldn't be removed. Otherwise the next reader wouldn't find the existing table.
This commit is contained in:
parent
db8fcf933a
commit
b8e0ba9872
1 changed files with 20 additions and 1 deletions
|
@ -409,8 +409,10 @@ impl TableStore {
|
||||||
let table = mut_table.save_in(self)?;
|
let table = mut_table.save_in(self)?;
|
||||||
self.add_head(&table)?;
|
self.add_head(&table)?;
|
||||||
if let Some(parent_table) = maybe_parent_table {
|
if let Some(parent_table) = maybe_parent_table {
|
||||||
|
if parent_table.name != table.name {
|
||||||
self.remove_head(&parent_table);
|
self.remove_head(&parent_table);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
{
|
{
|
||||||
let mut locked_cache = self.cached_tables.write().unwrap();
|
let mut locked_cache = self.cached_tables.write().unwrap();
|
||||||
locked_cache.insert(table.name.clone(), table.clone());
|
locked_cache.insert(table.name.clone(), table.clone());
|
||||||
|
@ -676,4 +678,21 @@ mod tests {
|
||||||
assert_eq!(merged_table.get_value(b"zzz"), Some(b"val3".as_slice()));
|
assert_eq!(merged_table.get_value(b"zzz"), Some(b"val3".as_slice()));
|
||||||
assert_eq!(merged_table.get_value(b"\xff\xff\xff"), None);
|
assert_eq!(merged_table.get_value(b"\xff\xff\xff"), None);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn stacked_table_store_save_empty() {
|
||||||
|
let temp_dir = testutils::new_temp_dir();
|
||||||
|
let store = TableStore::init(temp_dir.path().to_path_buf(), 3);
|
||||||
|
|
||||||
|
let mut mut_table = store.get_head().unwrap().start_mutation();
|
||||||
|
mut_table.add_entry(b"abc".to_vec(), b"value".to_vec());
|
||||||
|
store.save_table(mut_table).unwrap();
|
||||||
|
|
||||||
|
let mut_table = store.get_head().unwrap().start_mutation();
|
||||||
|
store.save_table(mut_table).unwrap();
|
||||||
|
|
||||||
|
// Table head shouldn't be removed on empty save
|
||||||
|
let table = store.get_head().unwrap();
|
||||||
|
assert_eq!(table.get_value(b"abc"), Some(b"value".as_slice()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue