Example #1
0
File: util.ts Project: DrXyzzy/smc
export function three_way_merge(opts: {
  base: string;
  local: string;
  remote: string;
}): string {
  if (opts.base === opts.remote) {
    // trivial special case...
    return opts.local;
  }
  return dmp.patch_apply(dmp.patch_make(opts.base, opts.remote), opts.local)[0];
}
Example #2
0
File: util.ts Project: DrXyzzy/smc
export function apply_patch(
  patch: CompressedPatch,
  s: string
): [string, boolean] {
  let x;
  try {
    x = dmp.patch_apply(decompress_patch(patch), s);
    //console.log('patch_apply ', misc.to_json(decompress_patch(patch)), x)
  } catch (err) {
    // If a patch is so corrupted it can't be parsed -- e.g., due to a bug in SMC -- we at least
    // want to make application the identity map (i.e., "best effort"), so
    // the document isn't completely unreadable!
    console.warn(`apply_patch -- ${err}, ${JSON.stringify(patch)}`);
    return [s, false];
  }
  let clean = true;
  for (let a of x[1]) {
    if (!a) {
      clean = false;
      break;
    }
  }
  return [x[0], clean];
}
Example #3
0
File: util.ts Project: DrXyzzy/smc
export function make_patch(s0: string, s1: string): CompressedPatch {
  return compress_patch(dmp.patch_make(s0, s1));
}