Solving an old conflict

pmeunier
Jul 11, 2021, 11:06 AM
JPIEFGYBQCKAQ4VPWWVQR2GU6UAHVKEEEA5OMNYW6LZT2YTPLIJQC

Dependencies

  • [2] TVVW53HZ Conflict resolution
  • [3] VMOYG7MK text file decoding for new files
  • [4] 6HNRL5RT detect non-utf8 text files
  • [5] HDGRZISM Version updates
  • [6] Q3GU26WD merge with changes from sanakirja v1.1.2
  • [7] NO2QPRFL Adding rollback test
  • [8] YTQS4ES3 Fixing a parsing problem (related to permissions), and the associated permissions
  • [9] QQZNSB26 Permission update (after #X243)
  • [10] UM5DLRPB store new non-UTF-8 files raw and decode to deplay the contents
  • [11] XSEODPNE Fixing conflicts
  • [12] FXEDPLRI Resurrecting tests, and type cleanup (no need for Arc<RwLock<…>> anymore)
  • [13] ZSF3YFZT encoded file deletion
  • [14] NYOF5766 track file encoding in the record, including change text for file adds
  • [15] TIPZ7UXN Started fixing the tests for parallel record/output
  • [16] X243Z3Y5 Recording only the required metadata (can even be changed later!)
  • [17] SXEYMYF7 Fixing the bad changes in history (unfortunately, by rebooting).

Change contents

  • file deletion: text.rs (-xw-x--x--)text.rs (----------)text.rs (-xw-x--x--)text.rs.XSEODPNEN2Y2S (----------)text.rs (-xwrx-rx-r)
    [3.248792][3.0:9](),[3.9][3.10:10](),[3.248792][3.0:9](),[3.9][3.10:10](),[3.248792][3.366:375](),[3.375][3.10:10](),[3.248792][2.618:641](),[2.641][3.10:10](),[3.248792][3.2008:2017](),[3.2017][3.10:10]()
    use super::*;
    use crate::working_copy::WorkingCopy;
    #[test]
    fn add_non_utf8_file_test() -> Result<(), anyhow::Error> {
    env_logger::try_init().unwrap_or(());
    let mut buf = Vec::new();
    use std::io::Read;
    let mut fh = std::fs::File::open("src/tests/data/1252.1")?;
    fh.read_to_end(&mut buf)?;
    let mut repo = working_copy::memory::Memory::new();
    repo.add_file("file", buf);
    let env = pristine::sanakirja::Pristine::new_anon()?;
    let mut txn = env.mut_txn_begin();
    let mut channel = txn.open_or_create_channel("main")?;
    txn.add_file("file")?;
    let store = changestore::memory::Memory::new();
    let (h, change) = record_all_change(&mut repo, &store, &mut txn, &mut channel, "")?;
    let mut v = Vec::new();
    change
    .write(
    &store,
    Some(h),
    |l, _p| format!("{}:{}", l.path, l.line),
    true,
    &mut v,
    )
    .unwrap();
    let lines: Vec<&str> = std::str::from_utf8(&v)
    .unwrap()
    .lines()
    .filter(|l| l.starts_with("+"))
    .collect();
    assert_eq!(
    vec!["+ French / Français (Windows CP 1252)", "+ €‚ƒ„…†‡, Salut"],
    lines
    );
    Ok(())
    }
    #[test]
    fn change_non_utf8_file_test() -> Result<(), anyhow::Error> {
    env_logger::try_init().unwrap_or(());
    let mut buf = Vec::new();
    use std::io::Read;
    let mut fh = std::fs::File::open("src/tests/data/8859-1.1")?;
    fh.read_to_end(&mut buf)?;
    let mut repo = working_copy::memory::Memory::new();
    repo.add_file("file", buf);
    let env = pristine::sanakirja::Pristine::new_anon()?;
    let mut txn = env.mut_txn_begin();
    let mut channel = txn.open_or_create_channel("main")?;
    txn.add_file("file")?;
    let store = changestore::memory::Memory::new();
    record_all(&mut repo, &store, &mut txn, &mut channel, "")?;
    let mut buf = Vec::new();
    {
    use std::io::Read;
    let mut fh = std::fs::File::open("src/tests/data/8859-1.2")?;
    fh.read_to_end(&mut buf)?;
    }
    repo.write_file::<_, std::io::Error, _>("file", |w| {
    w.write_all(&buf).unwrap();
    Ok(())
    })?;
    let (h1, change1) = record_all_change(&mut repo, &store, &mut txn, &mut channel, "")?;
    // only one line was changed
    let mut v = Vec::new();
    change1
    .write(
    &store,
    Some(h1),
    |l, _p| format!("{}:{}", l.path, l.line),
    true,
    &mut v,
    )
    .unwrap();
    let lines: Vec<&str> = std::str::from_utf8(&v)
    .unwrap()
    .lines()
    .filter(|l| l.starts_with(|c| c == '-' || c == '+'))
    .collect();
    assert_eq!(
    vec![
    "- French / Français (ISO Latin-1 / ISO 8859-1)",
    "+ Français / French (ISO Latin-1 / ISO 8859-1)"
    ],
    lines
    );
    Ok(())
    }
    #[test]
    fn delete_non_utf8_file_test() -> Result<(), anyhow::Error> {
    env_logger::try_init().unwrap_or(());
    let mut buf = Vec::new();
    use std::io::Read;
    let mut fh = std::fs::File::open("src/tests/data/gb.1")?;
    fh.read_to_end(&mut buf)?;
    let mut repo = working_copy::memory::Memory::new();
    repo.add_file("file", buf);
    let env = pristine::sanakirja::Pristine::new_anon()?;
    let mut txn = env.mut_txn_begin();
    let mut channel = txn.open_or_create_channel("main")?;
    txn.add_file("file")?;
    let store = changestore::memory::Memory::new();
    record_all(&mut repo, &store, &mut txn, &mut channel, "")?;
    let mut buf = Vec::new();
    {
    use std::io::Read;
    let mut fh = std::fs::File::open("src/tests/data/8859-1.2")?;
    fh.read_to_end(&mut buf)?;
    }
    repo.remove_path("file")?;
    let (h1, change1) = record_all_change(&mut repo, &store, &mut txn, &mut channel, "")?;
    let mut v = Vec::new();
    change1
    .write(
    &store,
    Some(h1),
    |l, _p| format!("{}:{}", l.path, l.line),
    true,
    &mut v,
    )
    .unwrap();
    let lines: Vec<&str> = std::str::from_utf8(&v)
    .unwrap()
    .lines()
    .filter(|l| l.starts_with(|c| c == '-'))
    .collect();
    assert_eq!(
    vec![
    " -Chinese / 中文,普通话,汉语 (GB 2312 / GB-encoding)",
    "- 你好"
    ],
    lines
    );
    Ok(())
    }