Avoid serialising twice in order to save the changes' signatures

pmeunier
Sep 21, 2021, 6:23 PM
M2C6QW2AEUCPOM7UDQHXRXVV2Z4GQMEKZZKPM6GT7DG2CPIDUWAAC

Dependencies

  • [2] E7UUQQCC Apply changes with prefixes in .pijul/changes
  • [3] FSNBD6GK Debugging information and Cargo.lock updates (attempting to measure and solve #468)
  • [4] AKARNWLH Upgrading dependencies, including zstd-seekable
  • [5] YN63NUZO Sanakirja 1.0
  • [6] F6V27C3M Fixing the "old file optimisation" in record, after the move to parallelisable records
  • [7] GUL4M5FI Cleanup and formatting
  • [8] ZSF3YFZT encoded file deletion
  • [9] SMMBFECL Converting to the new patch format "online"
  • [10] 6T5ULULM Fixing conflicts with the changes from discussion #143
  • [11] EUZFFJSO Updating Pijul with the latest changes in Libpijul
  • [12] 5DVRL6MF Hard-unrecord
  • [13] FXEDPLRI Resurrecting tests, and type cleanup (no need for Arc<RwLock<…>> anymore)
  • [14] SXEYMYF7 Fixing the bad changes in history (unfortunately, by rebooting).
  • [15] WZVCLZKY address clippy lints
  • [16] TYTQGSKZ Apply: proper error message when the change is not found
  • [17] EEBKW7VT Keys and identities
  • [18] 6F6AAHK4 Simplifying pijul::commands::log, and fixing Broken Pipe errors
  • [19] DJYHARZ7 Skipping old files when recording
  • [20] YDTN6BGI Touch the channel if no file was changed
  • [21] QJXNUQFJ Solving conflicts
  • [22] RXNT67OT Sanakirja version, and removing an unwrap
  • [23] R3H7D42U Debugging `pijul git`: proper error reporting
  • [24] I24UEJQL Various post-fire fixes
  • [25] CCLLB7OI Upgrading to Sanakirja 0.15 + version bump
  • [26] VO5OQW4W Removing anyhow in libpijul

Change contents

  • replacement in "pijul/src/commands/record.rs" at line 154
    [5.541][5.24:135](),[5.24][5.24:135](),[5.135][5.1912:2058]()
    Either::A((txn, mut change, updates, hash, oldest)) => {
    let hash = hash.unwrap();
    change.unhashed = Some(serde_json::json!({
    "signature": key.sign_raw(&hash.to_bytes())?,
    }));
    [5.541]
    [5.5950]
    Either::A((txn, mut change, updates, oldest)) => {
    let hash = repo.changes.save_change(&mut change, |change, hash| {
    change.unhashed = Some(serde_json::json!({
    "signature": key.sign_raw(&hash.to_bytes()).unwrap(),
    }));
    Ok::<_, anyhow::Error>(())
    })?;
  • edit in "pijul/src/commands/record.rs" at line 286
    [5.683][5.683:723]()
    Option<libpijul::Hash>,
  • edit in "pijul/src/commands/record.rs" at line 414
    [5.109720][5.0:50](),[5.50][5.109778:109803](),[5.109778][5.109778:109803]()
    let hash = changes.save_change(&change)?;
    debug!("saved");
  • edit in "pijul/src/commands/record.rs" at line 419
    [5.816][5.816:840]()
    Some(hash),
  • replacement in "pijul/src/commands/mod.rs" at line 113
    [5.2740][5.2740:2807]()
    let hash = repo.changes.save_change(&pending_change).unwrap();
    [5.2740]
    [5.12750]
    let hash = repo
    .changes
    .save_change(&mut pending_change, |_, _| Ok::<_, anyhow::Error>(()))
    .unwrap();
  • replacement in "pijul/src/commands/apply.rs" at line 55
    [2.1078][2.1078:1148]()
    Ok(change) => repo.changes.save_change(&change)?,
    [2.1078]
    [5.165]
    Ok(mut change) => repo
    .changes
    .save_change(&mut change, |_, _| Ok::<_, anyhow::Error>(()))?,
  • replacement in "pijul/src/commands/apply.rs" at line 72
    [5.195794][5.23542:23638](),[5.23638][5.979:1039](),[5.195886][5.979:1039]()
    let change = libpijul::change::Change::read(&mut change, &mut HashMap::default())?;
    hashes.push(repo.changes.save_change(&change)?)
    [5.195794]
    [5.1039]
    let mut change = libpijul::change::Change::read(&mut change, &mut HashMap::default())?;
    hashes.push(
    repo.changes
    .save_change(&mut change, |_, _| Ok::<_, anyhow::Error>(()))?,
    )
  • replacement in "libpijul/src/lib.rs" at line 177
    [5.724357][5.724357:724400]()
    let change = change::LocalChange {
    [5.724357]
    [5.724400]
    let mut change = change::LocalChange {
  • replacement in "libpijul/src/lib.rs" at line 198
    [5.28616][5.28616:28650]()
    .save_change(&change)
    [5.28616]
    [5.28650]
    .save_change(&mut change, |_, _| Ok(()))
  • replacement in "libpijul/src/changestore/mod.rs" at line 7
    [5.4262][5.4262:4298]()
    change::{Change, ChangeHeader},
    [5.4262]
    [5.4298]
    change::{Change, ChangeHeader, ChangeError},
  • replacement in "libpijul/src/changestore/mod.rs" at line 75
    [5.34077][5.34077:34145]()
    fn save_change(&self, p: &Change) -> Result<Hash, Self::Error>;
    [5.34077]
    [5.34145]
    fn save_change<
    E: From<Self::Error> + From<ChangeError>,
    F: FnOnce(&mut Change, &Hash) -> Result<(), E>,
    >(
    &self,
    p: &mut Change,
    f: F,
    ) -> Result<Hash, E>;
  • replacement in "libpijul/src/changestore/memory.rs" at line 95
    [5.823259][5.34874:34943]()
    fn save_change(&self, p: &Change) -> Result<Hash, Self::Error> {
    [5.823259]
    [5.823330]
    fn save_change<E: From<Self::Error> + From<ChangeError>, F: FnOnce(&mut Change, &Hash) -> Result<(), E>>(&self, p: &mut Change, f: F) -> Result<Hash, E> {
  • replacement in "libpijul/src/changestore/memory.rs" at line 97
    [5.823381][5.823381:823411]()
    let hash = p.hash()?;
    [5.823381]
    [5.823411]
    let hash = p.hash().map_err(|e| Self::Error::from(e))?;
    f(p, &hash)?;
  • replacement in "libpijul/src/changestore/filesystem.rs" at line 202
    [5.830156][5.35875:35944](),[5.35944][5.88657:88730]()
    fn save_change(&self, p: &Change) -> Result<Hash, Self::Error> {
    let mut f = tempfile::NamedTempFile::new_in(&self.changes_dir)?;
    [5.830156]
    [5.830302]
    fn save_change<E: From<Self::Error> + From<ChangeError>, F: FnOnce(&mut Change, &Hash) -> Result<(), E>>(&self, p: &mut Change, ff: F) -> Result<Hash, E> {
    let mut f = match tempfile::NamedTempFile::new_in(&self.changes_dir) {
    Ok(f) => f,
    Err(e) => return Err(E::from(Error::from(e)))
    };
  • replacement in "libpijul/src/changestore/filesystem.rs" at line 209
    [5.830376][5.830376:830404]()
    p.serialize(w)?
    [5.830376]
    [5.830404]
    p.serialize(w, ff)?
  • replacement in "libpijul/src/changestore/filesystem.rs" at line 212
    [5.830461][5.830461:830524]()
    std::fs::create_dir_all(file_name.parent().unwrap())?;
    [5.830461]
    [5.830524]
    if let Err(e) = std::fs::create_dir_all(file_name.parent().unwrap()) {
    return Err(E::from(Error::from(e)))
    }
  • replacement in "libpijul/src/changestore/filesystem.rs" at line 216
    [5.830571][5.830571:830602]()
    f.persist(file_name)?;
    [5.830571]
    [5.830602]
    if let Err(e) = f.persist(file_name) {
    return Err(E::from(Error::from(e)))
    }
  • replacement in "libpijul/src/change.rs" at line 1322
    [5.870081][5.37311:37390]()
    pub fn serialize<W: Write>(&self, mut w: W) -> Result<Hash, ChangeError> {
    [5.870081]
    [5.870244]
    pub fn serialize<W: Write, E: From<ChangeError>, F: FnOnce(&mut Self, &Hash) -> Result<(), E>>(&mut self, mut w: W, f: F) -> Result<Hash, E> {
  • replacement in "libpijul/src/change.rs" at line 1325
    [5.870305][5.870305:870366]()
    bincode::serialize_into(&mut hashed, &self.hashed)?;
    [5.870305]
    [5.870416]
    bincode::serialize_into(&mut hashed, &self.hashed).map_err(From::from)?;
  • edit in "libpijul/src/change.rs" at line 1332
    [5.6243]
    [5.870599]
    f(self, &hash)?;
  • replacement in "libpijul/src/change.rs" at line 1356
    [5.871342][3.261:323]()
    debug!("compressed contents in {:?}", now.elapsed());
    [5.871342]
    [5.6559]
    debug!("compressed {:?} bytes of contents in {:?}", self.contents.len(), now.elapsed());
  • replacement in "libpijul/src/change.rs" at line 1368
    [5.871477][5.871477:871641]()
    bincode::serialize_into(&mut w, &offsets)?;
    w.write_all(&hashed_comp)?;
    w.write_all(&unhashed_comp)?;
    w.write_all(&contents_comp)?;
    [5.871477]
    [5.871641]
    bincode::serialize_into(&mut w, &offsets).map_err(From::from)?;
    w.write_all(&hashed_comp).map_err(From::from)?;
    w.write_all(&unhashed_comp).map_err(From::from)?;
    w.write_all(&contents_comp).map_err(From::from)?;
    debug!("change serialized");
  • replacement in "Cargo.lock" at line 2637
    [5.62007][4.4234:4252]()
    version = "0.2.1"
    [5.62007]
    [5.62025]
    version = "0.2.2"
  • replacement in "Cargo.lock" at line 2639
    [5.62090][4.4253:4331]()
    checksum = "ac61cc05e3ecc29b17c85b9654271a29babcf1219f3a10ef35494c729e114f99"
    [5.62090]
    [5.62168]
    checksum = "1b8063b34aea161faa6068c9246f98fc033047af5764305ae972e0bc0bf768d4"