MCPcopy
hub / github.com/treeverse/dvc / _diff

Function _diff

dvc/repo/data.py:104–209  ·  view source on GitHub ↗
(
    old: "BaseDataIndex",
    new: "BaseDataIndex",
    *,
    filter_keys: Optional[Iterable["DataIndexKey"]] = None,
    granular: bool = False,
    not_in_cache: bool = False,
    batch_size: Optional[int] = None,
    callback: "Callback" = DEFAULT_CALLBACK,
    with_renames: bool = False,
)

Source from the content-addressed store, hash-verified

102
103
104def _diff(
105 old: "BaseDataIndex",
106 new: "BaseDataIndex",
107 *,
108 filter_keys: Optional[Iterable["DataIndexKey"]] = None,
109 granular: bool = False,
110 not_in_cache: bool = False,
111 batch_size: Optional[int] = None,
112 callback: "Callback" = DEFAULT_CALLBACK,
113 with_renames: bool = False,
114) -> DiffResult:
115 from dvc_data.index.diff import (
116 ADD,
117 DELETE,
118 MODIFY,
119 RENAME,
120 UNCHANGED,
121 UNKNOWN,
122 diff,
123 )
124
125 ret: DiffResult = defaultdict(list) # type: ignore[assignment]
126 change_types = {
127 MODIFY: "modified",
128 ADD: "added",
129 DELETE: "deleted",
130 RENAME: "renamed",
131 }
132
133 to_check: dict[FileSystem, dict[str, list[DataIndexEntry]]] = defaultdict(
134 lambda: defaultdict(list)
135 )
136
137 for change in diff(
138 old,
139 new,
140 with_unchanged=True,
141 shallow=not granular,
142 hash_only=True,
143 with_unknown=True,
144 with_renames=with_renames,
145 callback=callback,
146 ):
147 typ = change.typ
148
149 # The index is a trie, so even when we filter by a specific path
150 # like `dir/file`, all parent nodes leading to that path (e.g., `dir/`)
151 # still appear in the view. As a result, keys like `dir/` will be present
152 # even if only `dir/file` matches the filter.
153 # We need to skip such entries to avoid showing root of tracked directories.
154 if filter_keys:
155 # RENAME does not have a `change.key`
156 if typ == RENAME:
157 assert change.new
158 key = change.new.key
159 # match with "new" key only
160 assert key
161 else:

Callers 2

_diff_index_to_wtreeFunction · 0.70
_diff_head_to_indexFunction · 0.70

Calls 9

diffFunction · 0.90
TqdmCallbackClass · 0.90
_adapt_path_from_entryFunction · 0.85
_adapt_pathFunction · 0.85
_get_missing_pathsFunction · 0.85
StorageCallbackClass · 0.85
dictClass · 0.85
appendMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected