Clarify FakeGitRepository reset with truncate+pop instead of loop

Richard Feldman created

Replace the obscure pop loop with truncate+pop to make the
intent explicit: keep entries up to the target, then pop the
target to use its contents. Identical behavior, clearer code.

Change summary

crates/fs/src/fake_git_repo.rs | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)

Detailed changes

crates/fs/src/fake_git_repo.rs 🔗

@@ -254,11 +254,12 @@ impl GitRepository for FakeGitRepository {
                 );
             }
 
-            let mut snapshot = None;
-            for _ in 0..pop_count {
-                snapshot = state.commit_history.pop();
-            }
-            let snapshot = snapshot.expect("pop_count validated above");
+            let target_index = state.commit_history.len() - pop_count;
+            state.commit_history.truncate(target_index + 1);
+            let snapshot = state
+                .commit_history
+                .pop()
+                .expect("pop_count validated above");
 
             match mode {
                 ResetMode::Soft => {