MCPcopy
hub / github.com/borgbackup/borg / do_diff

Method do_diff

src/borg/archiver/diff_cmd.py:21–171  ·  view source on GitHub ↗

Finds differences between two archives.

(self, args, repository, manifest)

Source from the content-addressed store, hash-verified

19class DiffMixIn:
20 @with_repository(compatibility=(Manifest.Operation.READ,))
21 def do_diff(self, args, repository, manifest):
22 """Finds differences between two archives."""
23
24 def actual_change(j):
25 j = j.to_dict()
26 if j["type"] == "modified":
27 # Added/removed keys will not exist if chunker params differ
28 # between the two archives. Err on the side of caution and assume
29 # a real modification in this case (short-circuiting retrieving
30 # non-existent keys).
31 return not {"added", "removed"} <= j.keys() or not (j["added"] == 0 and j["removed"] == 0)
32 else:
33 # All other change types are indeed changes.
34 return True
35
36 def print_json_output(diff):
37 print(
38 json.dumps(
39 {
40 "path": diff.path,
41 "changes": [
42 change.to_dict()
43 for name, change in diff.changes().items()
44 if actual_change(change) and (not args.content_only or (name not in DiffFormatter.METADATA))
45 ],
46 },
47 sort_keys=True,
48 cls=BorgJsonEncoder,
49 )
50 )
51
52 def print_text_output(diff, formatter):
53 actual_changes = {
54 name: change
55 for name, change in diff.changes().items()
56 if actual_change(change) and (not args.content_only or (name not in DiffFormatter.METADATA))
57 }
58 diff._changes = actual_changes
59 res: str = formatter.format_item(diff)
60 if res.strip():
61 sys.stdout.write(res)
62
63 if args.format is not None:
64 format = args.format
65 elif args.content_only:
66 format = "{content}{link}{directory}{blkdev}{chrdev}{fifo} {path}{NL}"
67 else:
68 format = os.environ.get("BORG_DIFF_FORMAT", "{change} {path}{NL}")
69
70 archive1_info = manifest.archives.get_one([args.name])
71 archive2_info = manifest.archives.get_one([args.other_name])
72 archive1 = Archive(manifest, archive1_info.id)
73 archive2 = Archive(manifest, archive2_info.id)
74
75 can_compare_chunk_ids = (
76 archive1.metadata.get("chunker_params", False) == archive2.metadata.get("chunker_params", True)
77 or args.same_chunker_params
78 )

Callers

nothing calls this directly

Calls 10

ArchiveClass · 0.85
build_matcherFunction · 0.85
DiffFormatterClass · 0.85
get_oneMethod · 0.80
print_warningMethod · 0.80
compare_archives_iterMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected