Skip to content

Commit

Permalink
Bugfixes and make nbmerge actually work for the first time!
Browse files Browse the repository at this point in the history
Try it on the files nbdime/tests/files/multilevel-test-*.ipynb

Merry christmas!
  • Loading branch information
Martin Sandve Alnæs committed Dec 23, 2015
1 parent 4b5522d commit 555c7b2
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
8 changes: 2 additions & 6 deletions nbdime/diffing/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,7 @@ def diff(a, b, compare=operator.__eq__):
return d


def diff_lists(a, b, compare=operator.__eq__, shallow_diff=None, subdiffs=None):
if subdiffs is None:
subdiffs = {}

def diff_lists(a, b, compare=operator.__eq__, shallow_diff=None):
# First make the one-level list diff with custom compare,
# unless it's provided for us
if shallow_diff is None:
Expand Down Expand Up @@ -82,8 +79,7 @@ def diff_lists(a, b, compare=operator.__eq__, shallow_diff=None, subdiffs=None):
aval = a[acons+i]
bval = b[bcons+i]
if not is_atomic(aval):
diffit = subdiffs.get(key, diff)
d = diffit(aval, bval, compare=compare)
d = diff(aval, bval, compare=compare)
if d:
pdi.append([PATCH, acons+i, d])

Expand Down
6 changes: 3 additions & 3 deletions nbdime/merging/notebooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@

from ..diffing import diff
from ..dformat import PATCH, INSERT, DELETE, REPLACE, SEQINSERT, SEQDELETE

from .generic import merge

def merge_notebooks(base, local, remote):
"""Merge changes introduced by notebooks local and remote from a shared ancestor base.
Return new (partially) merged notebook and unapplied diffs from the local and remote side.
"""
# FIXME: Implement notebook aware merge
merged, conflicts = merge(base, local, remote)
return nbformat.from_dict(merged), conflicts
merged, local_conflict_diffs, remote_conflict_diffs = merge(base, local, remote)
return nbformat.from_dict(merged), local_conflict_diffs, remote_conflict_diffs
7 changes: 5 additions & 2 deletions nbdime/nbmergeapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,16 @@ def main_merge(bfn, lfn, rfn, mfn):
l = nbformat.read(lfn, as_version=4)
r = nbformat.read(rfn, as_version=4)

m = merge_notebooks(b, l, r)
m, lc, rc = merge_notebooks(b, l, r)

verbose = True
if verbose:
print(m)
print(lc)
print(rc)

nbformat.write(mfn, m)
with open(mfn, "w") as mf:
nbformat.write(m, mf)
return 0


Expand Down

0 comments on commit 555c7b2

Please sign in to comment.