Skip to content

Commit

Permalink
Mark all paths underneath a not in cache or delete parent with the sa…
Browse files Browse the repository at this point in the history
…me status (#1783)
  • Loading branch information
mattseddon authored May 31, 2022
1 parent 39e0b95 commit 8de768e
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 9 deletions.
30 changes: 30 additions & 0 deletions extension/src/repository/model/collect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,33 @@ export const collectTrackedPaths = async (
}
return acc
}

const isUncollectedChild = (
deleted: Set<string>,
deletedPath: string,
trackedPath: string
): boolean => {
return !deleted.has(trackedPath) && isSameOrChild(deletedPath, trackedPath)
}

const collectIfDeletedChild = (
deleted: Set<string>,
deletedPath: string,
trackedPath: string
): void => {
if (isUncollectedChild(deleted, deletedPath, trackedPath)) {
deleted.add(trackedPath)
}
}

export const collectDeleted = (
deleted: Set<string>,
tracked: Set<string>
): Set<string> => {
for (const trackedPath of tracked) {
for (const deletedPath of deleted) {
collectIfDeletedChild(deleted, deletedPath, trackedPath)
}
}
return deleted
}
62 changes: 61 additions & 1 deletion extension/src/repository/model/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,67 @@ describe('RepositoryState', () => {
resolve(dvcDemoPath, 'predictions.json'),
resolve(dvcDemoPath, 'training_metrics'),
resolve(dvcDemoPath, 'training_metrics.json'),
resolve(dvcDemoPath, 'data', 'MNIST', 'raw')
resolve(dvcDemoPath, 'data', 'MNIST', 'raw'),
resolve(
dvcDemoPath,
'data',
'MNIST',
'raw',
't10k-images-idx3-ubyte'
),
resolve(
dvcDemoPath,
'data',
'MNIST',
'raw',
't10k-images-idx3-ubyte.gz'
),
resolve(
dvcDemoPath,
'data',
'MNIST',
'raw',
't10k-labels-idx1-ubyte'
),
resolve(
dvcDemoPath,
'data',
'MNIST',
'raw',
't10k-labels-idx1-ubyte.gz'
),
resolve(
dvcDemoPath,
'data',
'MNIST',
'raw',
'train-images-idx3-ubyte'
),
resolve(
dvcDemoPath,
'data',
'MNIST',
'raw',
'train-images-idx3-ubyte.gz'
),
resolve(
dvcDemoPath,
'data',
'MNIST',
'raw',
'train-labels-idx1-ubyte'
),
resolve(
dvcDemoPath,
'data',
'MNIST',
'raw',
'train-labels-idx1-ubyte.gz'
),
resolve(dvcDemoPath, 'training_metrics', 'scalars'),
resolve(dvcDemoPath, 'training_metrics', 'report.html'),
resolve(dvcDemoPath, 'training_metrics', 'scalars', 'acc.tsv'),
resolve(dvcDemoPath, 'training_metrics', 'scalars', 'loss.tsv')
]),
renamed: emptySet,
tracked: new Set([
Expand Down
15 changes: 8 additions & 7 deletions extension/src/repository/model/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { dirname, join, resolve } from 'path'
import omit from 'lodash.omit'
import {
collectDeleted,
collectModifiedAgainstHead,
collectTrackedNonLeafs,
collectTrackedOuts,
Expand Down Expand Up @@ -220,21 +221,21 @@ export class RepositoryModel
modifiedAgainstCache
)

const deletedWithChildren = collectDeleted(
this.getStateFromDiff(diffOutput[Status.DELETED]),
this.getTracked()
)

this.state.notInCache = new Set([
...this.getStateFromDiff(diffOutput[Status.NOT_IN_CACHE]),
...this.filterStatuses(
[
...this.getStateFromDiff(diffOutput[Status.DELETED]),
...modifiedAgainstHead
],
[...deletedWithChildren, ...modifiedAgainstHead],
path => this.pathInSet(path, notInCache)
)
])

this.state.deleted = new Set(
this.mapToTrackedPaths(diffOutput.deleted || []).filter(
path => !this.state.notInCache.has(path)
)
[...deletedWithChildren].filter(path => !this.state.notInCache.has(path))
)
}

Expand Down
4 changes: 3 additions & 1 deletion extension/src/test/suite/repository/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,9 @@ suite('Repository Test Suite', () => {

const deleted = new Set([
join(dvcDemoPath, model),
join(dvcDemoPath, dataDir)
join(dvcDemoPath, dataDir),
join(dvcDemoPath, compressedDataset),
join(dvcDemoPath, dataset)
])

const tracked = new Set([
Expand Down

0 comments on commit 8de768e

Please sign in to comment.