MCPcopy Index your code
hub / github.com/deepnote/deepnote / computeBlockDiffs

Function computeBlockDiffs

packages/cli/src/commands/diff.ts:214–281  ·  view source on GitHub ↗

* Compare blocks between two notebooks.

(blocks1: DeepnoteBlock[], blocks2: DeepnoteBlock[], options: DiffOptions)

Source from the content-addressed store, hash-verified

212 * Compare blocks between two notebooks.
213 */
214function computeBlockDiffs(blocks1: DeepnoteBlock[], blocks2: DeepnoteBlock[], options: DiffOptions): BlockDiff[] {
215 const blocksMap1 = new Map(blocks1.map(b => [b.id, b]))
216 const blocksMap2 = new Map(blocks2.map(b => [b.id, b]))
217
218 const blockDiffs: BlockDiff[] = []
219
220 // Find removed and modified blocks
221 for (const [id, block1] of blocksMap1) {
222 const block2 = blocksMap2.get(id)
223 if (!block2) {
224 blockDiffs.push({
225 id,
226 type: block1.type,
227 status: 'removed',
228 ...(options.content && {
229 contentDiff: {
230 before: getBlockContent(block1),
231 after: undefined,
232 },
233 }),
234 })
235 } else {
236 const content1 = getBlockContent(block1)
237 const content2 = getBlockContent(block2)
238 const typeChanged = block1.type !== block2.type
239 const contentChanged = content1 !== content2
240
241 if (typeChanged || contentChanged) {
242 blockDiffs.push({
243 id,
244 type: block2.type,
245 status: 'modified',
246 ...(options.content && {
247 contentDiff: {
248 before: content1,
249 after: content2,
250 },
251 }),
252 })
253 } else {
254 blockDiffs.push({
255 id,
256 type: block2.type,
257 status: 'unchanged',
258 })
259 }
260 }
261 }
262
263 // Find added blocks
264 for (const [id, block2] of blocksMap2) {
265 if (!blocksMap1.has(id)) {
266 blockDiffs.push({
267 id,
268 type: block2.type,
269 status: 'added',
270 ...(options.content && {
271 contentDiff: {

Callers 1

computeDiffFunction · 0.85

Calls 1

getBlockContentFunction · 0.70

Tested by

no test coverage detected