From 012afeda62a250abeb597ba073ea784e8e1807cb Mon Sep 17 00:00:00 2001 From: Shafkath Shuhan Date: Sat, 28 Jan 2023 12:05:36 -0500 Subject: [PATCH] wip --- helix-core/.DS_Store | Bin 8196 -> 0 bytes helix-core/src/history.rs | 11 ++++------- helix-core/src/parse.rs | 8 +++++--- 3 files changed, 9 insertions(+), 10 deletions(-) delete mode 100644 helix-core/.DS_Store diff --git a/helix-core/.DS_Store b/helix-core/.DS_Store deleted file mode 100644 index a116e7215c8c51421a4a266f572302777f7dda3d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 8196 zcmeHMO>h)N6n<~=*E1n9$&e7FmaGIUj0waf{0nS;0Fh{b%`bn;?9NC=W@p0A>@E;v z<%AYmrIv+%SAV&1uu2QPfH$q;q7_lJ%8MShe+vkRrl-n`n~RX zufI3FJqrNXlQ$j#XaoR8l~c8vn!6M}&g&gT3MG|9k?g^nNZW3jxJ&7YJG3J~6oDuL zQ3Rq0L=lK0a4$rF&TL-TJm%5#aBKI8{y)A)OX9cy&+{TmgudlQ<~U zS9ynMJfw+`P76vSR8W`_6{Z+oF;JM3JRa&LLOLy|Fb51T9~iET;SB|Y)oK2CpbnT2 zG-{&=L=m_%0{re?1|H-flP=zVf442qZ*RYbQdxOLWfiMp)$B-e+$|=3-OqbHdhQVC z23^-qm->2o*fNVLbxE)5_`2noxxm0OOj0>KVmXFe>~Zss;RUuyF~DRdr_{#D$&U4# zTH~GTJEvOXlbbu*TjO1w8>XgYR^PmC>w(k>JL|aTgaa791fXV)LoeL&#`X%m;%h`% zZF)j@^KHo+S*g~BhLzD#E8{vz>x`LF7klK+9%A?9%mTSFl5y>P*6~tmZAP~-bCq6Tam--msbTh&CtM#Y4*% z7uCmBKKO9^`YqdgckdmTskv{lT3e?n2PrO&Z#`w1xuK$E_~T=`moXi~a*mG_EYC{Y z=Affz&01__@=Q&`(#B=?YubFOqxrOTGH>~()n>+K)cY3KC{5Y}vicD_Y|ukK;Tn7; zBN)+|wAG9q;_}{{Nv#koYqSakE)+(i5_T*2C1#*-^f5zwY@16Q)yoq=dGMv4h^Yo-+rE z1gVn6#+fwu@&2JEpEYH?89BS8~bqxhjA3g@F*U~aeNw2;7L4#lQ@OX z;#qtNU&dGPEqoi_!T0ce{1`9e75ogZ;@5Z$zrkPdH@ty=;$Kpg#3V(kmR3kj(i*8v zS}Qz|N@+4S+aqZQ@nOQe@65F{;dF)?Jlk1DZ#8^_lqIpeQ$A+ytZo)^P ztpu>!fg50T7QzFp20J_#XF&!nS7Jj1X7kj1iKJFh!pUrgYd6J}m|8(_7woFl#8wj2 z1^ZA-ET&47VS-(|E~cnuls|G{+u1@ahRnuIilUZNCdo6)mNqsh%VXPRrb3{Y=%#6S zUa)_T&b_-;DtE|+%p@2 z_~|VK7Lqx~cAeuS;dre8A51!seDMAw2hwdG&GB`1P!^mk6Dv0I`~S}QzyB}zb43eA z5r`tNa1p@rzGPnytylWJFn4Kw*N#&?MwJ(?H!WyjLd~oX0mR?@!;t!MQsp*@kWLFq Y5-JP+As}l;=YMqmFW`mr-aP;R22DqRq5uE@ diff --git a/helix-core/src/history.rs b/helix-core/src/history.rs index 3e253a3c8f96b..175027efb960b 100644 --- a/helix-core/src/history.rs +++ b/helix-core/src/history.rs @@ -2,7 +2,6 @@ use crate::parse::*; use crate::{Assoc, ChangeSet, Range, Rope, Selection, Transaction}; use once_cell::sync::Lazy; use regex::Regex; -use std::fs::File; use std::io::{Read, Write}; use std::num::NonZeroUsize; use std::time::{Duration, Instant}; @@ -68,25 +67,23 @@ struct Revision { timestamp: Instant, } -const HEADER_TAG: &str = "Helix Undofile"; -const CURRENT_VERSION: u8 = 1; +const HEADER_TAG: &str = "Helix Undofile 0.1\n"; pub fn serialize_history(writer: &mut W, history: &History) -> std::io::Result<()> { write_string(writer, HEADER_TAG)?; - write_byte(writer, CURRENT_VERSION)?; write_usize(writer, history.current)?; write_vec(writer, &history.revisions, serialize_revision)?; Ok(()) } pub fn deserialize_history(reader: &mut R) -> std::io::Result { - if HEADER_TAG != read_string(reader)? { + let header = read_string(reader)?; + if HEADER_TAG != header { Err(std::io::Error::new( std::io::ErrorKind::Other, - "missing undofile header", + format!("missing undofile header"), )) } else { - let _version = read_byte(reader)?; let timestamp = Instant::now(); let current = read_usize(reader)?; let revisions = read_vec(reader, |reader| deserialize_revision(reader, timestamp))?; diff --git a/helix-core/src/parse.rs b/helix-core/src/parse.rs index ce8ef6665c042..f97700c19e31b 100644 --- a/helix-core/src/parse.rs +++ b/helix-core/src/parse.rs @@ -88,9 +88,11 @@ pub fn read_usize(reader: &mut R) -> Result { pub fn read_string(reader: &mut R) -> Result { let len = read_usize(reader)?; - let mut buf = String::with_capacity(len); - reader.read_to_string(&mut buf)?; - Ok(buf) + let mut buf = vec![0; len]; + reader.read_exact(&mut buf)?; + + let res = String::from_utf8(buf).map_err(|e| Error::new(ErrorKind::InvalidData, e))?; + Ok(res) } pub fn read_vec(reader: &mut R, f: impl Fn(&mut R) -> Result) -> Result> {