From d45a25b1ee1161ab5c261013d51a3632b00057f2 Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Sat, 26 Mar 2022 10:32:49 -0700 Subject: [PATCH] op_heads_store: return operations sorted by timestamp (#111) It's cheap to sort them, so let's have them always sorted, so all callers can rely on that order. --- lib/src/op_heads_store.rs | 1 + lib/src/repo.rs | 3 +-- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/src/op_heads_store.rs b/lib/src/op_heads_store.rs index 0eddc71fb..78dfcf5b7 100644 --- a/lib/src/op_heads_store.rs +++ b/lib/src/op_heads_store.rs @@ -184,6 +184,7 @@ impl OpHeadsStore { return Ok(OpHeads::Single(op_heads.pop().unwrap())); } + op_heads.sort_by_key(|op| op.store_operation().metadata.end_time.timestamp.clone()); Ok(OpHeads::Unresolved { locked_op_heads, op_heads, diff --git a/lib/src/repo.rs b/lib/src/repo.rs index d3cf7736f..6fc272263 100644 --- a/lib/src/repo.rs +++ b/lib/src/repo.rs @@ -387,9 +387,8 @@ impl RepoLoader { fn merge_op_heads( &self, user_settings: &UserSettings, - mut op_heads: Vec, + op_heads: Vec, ) -> UnpublishedOperation { - op_heads.sort_by_key(|op| op.store_operation().metadata.end_time.timestamp.clone()); let base_repo = self.load_at(&op_heads[0]); let mut tx = base_repo.start_transaction("resolve concurrent operations"); for other_op_head in op_heads.into_iter().skip(1) {