Skip to content

Commit 012afed

Browse files
committed
wip
1 parent 884a131 commit 012afed

File tree

3 files changed

+9
-10
lines changed

3 files changed

+9
-10
lines changed

helix-core/.DS_Store

-8 KB
Binary file not shown.

helix-core/src/history.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use crate::parse::*;
22
use crate::{Assoc, ChangeSet, Range, Rope, Selection, Transaction};
33
use once_cell::sync::Lazy;
44
use regex::Regex;
5-
use std::fs::File;
65
use std::io::{Read, Write};
76
use std::num::NonZeroUsize;
87
use std::time::{Duration, Instant};
@@ -68,25 +67,23 @@ struct Revision {
6867
timestamp: Instant,
6968
}
7069

71-
const HEADER_TAG: &str = "Helix Undofile";
72-
const CURRENT_VERSION: u8 = 1;
70+
const HEADER_TAG: &str = "Helix Undofile 0.1\n";
7371

7472
pub fn serialize_history<W: Write>(writer: &mut W, history: &History) -> std::io::Result<()> {
7573
write_string(writer, HEADER_TAG)?;
76-
write_byte(writer, CURRENT_VERSION)?;
7774
write_usize(writer, history.current)?;
7875
write_vec(writer, &history.revisions, serialize_revision)?;
7976
Ok(())
8077
}
8178

8279
pub fn deserialize_history<R: Read>(reader: &mut R) -> std::io::Result<History> {
83-
if HEADER_TAG != read_string(reader)? {
80+
let header = read_string(reader)?;
81+
if HEADER_TAG != header {
8482
Err(std::io::Error::new(
8583
std::io::ErrorKind::Other,
86-
"missing undofile header",
84+
format!("missing undofile header"),
8785
))
8886
} else {
89-
let _version = read_byte(reader)?;
9087
let timestamp = Instant::now();
9188
let current = read_usize(reader)?;
9289
let revisions = read_vec(reader, |reader| deserialize_revision(reader, timestamp))?;

helix-core/src/parse.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,11 @@ pub fn read_usize<R: Read>(reader: &mut R) -> Result<usize> {
8888

8989
pub fn read_string<R: Read>(reader: &mut R) -> Result<String> {
9090
let len = read_usize(reader)?;
91-
let mut buf = String::with_capacity(len);
92-
reader.read_to_string(&mut buf)?;
93-
Ok(buf)
91+
let mut buf = vec![0; len];
92+
reader.read_exact(&mut buf)?;
93+
94+
let res = String::from_utf8(buf).map_err(|e| Error::new(ErrorKind::InvalidData, e))?;
95+
Ok(res)
9496
}
9597

9698
pub fn read_vec<R: Read, T>(reader: &mut R, f: impl Fn(&mut R) -> Result<T>) -> Result<Vec<T>> {

0 commit comments

Comments
 (0)