The iteration with an indexing variable appeared to be mostly to be able to retrieve the state of the previous change.
Change to a consuming iterator and keep track of the previous change state in a mutable variable.
5ZSJEED77SE3LHU6S6RMBNRZPDDR3TFNXOM5SI23WIHKS6LHEHAAC
KPGRBRHS3HGVO3FTJQ33GATP75TO4CE6DL567YZTXTWGLELRZYKQC
EBE4NGXWTXMGB6B7M4AWJRMVQE2QYR2GODPPRWE67RKQLFAW7KBAC
FIIUZR4LJOB5DPB4CBMPJHMO7C5Q4ZINUVM52UK6SIM5WM7R7ZLAC
OZUZ5H6DJUXJ2MEHQK6FQ7LTSPUHHGZSFZ3SPBV26A2KBE4TQKQQC
TQBJZLD7Q223IFEBR7SU4FJWPWQWVBCSRPYYYEHXNSDM6DC7UWRAC
YNZMKRJDWYOQ3R3XHA2G47YG2SDI7FT7AEXH3OLB3BJGB6ALTRQAC
R3XMFPCYGXT5CNHYRNVZDGD2TDTCK6XGQ55SPJW56UEQQNV4R64AC
for i in 0..changes.len() {
sandbox.add_change(&changes[i]).unwrap();
if !stream.already_exported(&changes[i].state) {
let files = sandbox.get_files(changes[i].hash).unwrap();
let parent = if i == 0 {
None
} else {
Some(changes[i - 1].state)
};
stream.write_commit(&changes[i], parent, &files);
let mut parent = None;
for ch in changes {
sandbox.add_change(&ch).unwrap();
if !stream.already_exported(&ch.state) {
let files = sandbox.get_files(ch.hash).unwrap();
stream.write_commit(&ch, parent, &files);