mirror of
https://github.com/vrtmrz/obsidian-livesync.git
synced 2024-12-12 09:04:06 +02:00
Fixed:
- Now we can merge JSON files even if they have entries which cannot be compared.
This commit is contained in:
parent
2fdc7669f3
commit
bc568ff479
34
src/main.ts
34
src/main.ts
@ -2297,24 +2297,24 @@ export default class ObsidianLiveSyncPlugin extends Plugin {
|
||||
}
|
||||
|
||||
async mergeObject(path: string, baseRev: string, currentRev: string, conflictedRev: string): Promise<string | false> {
|
||||
const baseLeaf = await this.getConflictedDoc(path, baseRev);
|
||||
const leftLeaf = await this.getConflictedDoc(path, currentRev);
|
||||
const rightLeaf = await this.getConflictedDoc(path, conflictedRev);
|
||||
if (baseLeaf == false || leftLeaf == false || rightLeaf == false) {
|
||||
return false;
|
||||
}
|
||||
const baseObj = { data: tryParseJSON(baseLeaf.data, {}) } as Record<string | number | symbol, any>;
|
||||
const leftObj = { data: tryParseJSON(leftLeaf.data, {}) } as Record<string | number | symbol, any>;
|
||||
const rightObj = { data: tryParseJSON(rightLeaf.data, {}) } as Record<string | number | symbol, any>;
|
||||
|
||||
const diffLeft = generatePatchObj(baseObj, leftObj);
|
||||
const diffRight = generatePatchObj(baseObj, rightObj);
|
||||
const patches = [
|
||||
{ mtime: leftLeaf.mtime, patch: diffLeft },
|
||||
{ mtime: rightLeaf.mtime, patch: diffRight }
|
||||
].sort((a, b) => a.mtime - b.mtime);
|
||||
let newObj = { ...baseObj };
|
||||
try {
|
||||
const baseLeaf = await this.getConflictedDoc(path, baseRev);
|
||||
const leftLeaf = await this.getConflictedDoc(path, currentRev);
|
||||
const rightLeaf = await this.getConflictedDoc(path, conflictedRev);
|
||||
if (baseLeaf == false || leftLeaf == false || rightLeaf == false) {
|
||||
return false;
|
||||
}
|
||||
const baseObj = { data: tryParseJSON(baseLeaf.data, {}) } as Record<string | number | symbol, any>;
|
||||
const leftObj = { data: tryParseJSON(leftLeaf.data, {}) } as Record<string | number | symbol, any>;
|
||||
const rightObj = { data: tryParseJSON(rightLeaf.data, {}) } as Record<string | number | symbol, any>;
|
||||
|
||||
const diffLeft = generatePatchObj(baseObj, leftObj);
|
||||
const diffRight = generatePatchObj(baseObj, rightObj);
|
||||
const patches = [
|
||||
{ mtime: leftLeaf.mtime, patch: diffLeft },
|
||||
{ mtime: rightLeaf.mtime, patch: diffRight }
|
||||
].sort((a, b) => a.mtime - b.mtime);
|
||||
let newObj = { ...baseObj };
|
||||
for (const patch of patches) {
|
||||
newObj = applyPatch(newObj, patch.patch);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user