Fixing an off-by-one error in conflict resolutions, when one side of a conflict contains a "last line in file" without a \n

pmeunier
May 5, 2022, 8:56 AM
FBHUMBZTR3YD35MZWN2BAQV2KQY7A4JUAJHLAM56OXLWHAQRUGTQC

Dependencies

  • [2] SXEYMYF7 Fixing the bad changes in history (unfortunately, by rebooting).
  • [3] YN63NUZO Sanakirja 1.0
  • [4] IYJZVLET Cleaning up the literate programming bits

Change contents

  • edit in libpijul/src/diff/replace.rs at line 139
    [2.783747][2.783747:783788]()
    debug!("old_bytes {:?}", old_bytes);
  • edit in libpijul/src/diff/replace.rs at line 142
    [2.783974][2.783974:784105]()
    debug!("up_context_idx = {:?}", up_context_idx);
    debug!("{:?}", diff.marker.get(&diff.pos_a[up_context_idx].pos));
  • replacement in libpijul/src/diff/replace.rs at line 149
    [2.784476][2.784476:784608]()
    let offset = old_bytes - diff.pos_a[up_context_idx].pos;
    debug!("offset {:?} {:?}", pos.0, offset);
    [2.784476]
    [2.784608]
    let mut offset = old_bytes - diff.pos_a[up_context_idx].pos;
    // Here, in the case where one side of the conflict
    // ended with a "last line without a `\n`", the offset
    // might be off by one.
    //
    // We detect that case by testing whether the vertex
    // length is the same as the length of the "line".
    let v_end = diff.pos_a[up_context_idx].vertex.end.0.into();
    if pos.0 + offset <= v_end {
    //
    } else if pos.0 + offset == v_end + 1 {
    assert_eq!(diff.contents_a[old_bytes - 1], b'\n');
    offset -= 1
    } else {
    panic!("{:?} {:?} {:?}", pos.0, offset, v_end);
    }