MCPcopy Index your code
hub / github.com/aptly-dev/aptly / aptlySnapshotDiff

Function aptlySnapshotDiff

cmd/snapshot_diff.go:10–90  ·  view source on GitHub ↗
(cmd *commander.Command, args []string)

Source from the content-addressed store, hash-verified

8)
9
10func aptlySnapshotDiff(cmd *commander.Command, args []string) error {
11 var err error
12 if len(args) != 2 {
13 cmd.Usage()
14 return commander.ErrCommandError
15 }
16
17 onlyMatching := context.Flags().Lookup("only-matching").Value.Get().(bool)
18 collectionFactory := context.NewCollectionFactory()
19
20 // Load <name-a> snapshot
21 snapshotA, err := collectionFactory.SnapshotCollection().ByName(args[0])
22 if err != nil {
23 return fmt.Errorf("unable to load snapshot A: %s", err)
24 }
25
26 err = collectionFactory.SnapshotCollection().LoadComplete(snapshotA)
27 if err != nil {
28 return fmt.Errorf("unable to load snapshot A: %s", err)
29 }
30
31 // Load <name-b> snapshot
32 snapshotB, err := collectionFactory.SnapshotCollection().ByName(args[1])
33 if err != nil {
34 return fmt.Errorf("unable to load snapshot B: %s", err)
35 }
36
37 err = collectionFactory.SnapshotCollection().LoadComplete(snapshotB)
38 if err != nil {
39 return fmt.Errorf("unable to load snapshot B: %s", err)
40 }
41
42 // Calculate diff
43 diff, err := snapshotA.RefList().Diff(snapshotB.RefList(), collectionFactory.PackageCollection())
44 if err != nil {
45 return fmt.Errorf("unable to calculate diff: %s", err)
46 }
47
48 if len(diff) == 0 {
49 context.Progress().Printf("Snapshots are identical.\n")
50 } else {
51 context.Progress().Printf(" Arch | Package | Version in A | Version in B\n")
52 for _, pdiff := range diff {
53 if onlyMatching && (pdiff.Left == nil || pdiff.Right == nil) {
54 continue
55 }
56
57 var verA, verB, pkg, arch, code string
58
59 if pdiff.Left == nil {
60 verA = "-"
61 verB = pdiff.Right.Version
62 pkg = pdiff.Right.Name
63 arch = pdiff.Right.Architecture
64 } else {
65 pkg = pdiff.Left.Name
66 arch = pdiff.Left.Architecture
67 verA = pdiff.Left.Version

Callers

nothing calls this directly

Calls 12

SnapshotCollectionMethod · 0.95
PackageCollectionMethod · 0.95
FlagsMethod · 0.80
NewCollectionFactoryMethod · 0.80
DiffMethod · 0.80
ProgressMethod · 0.80
GetMethod · 0.65
PrintfMethod · 0.65
ColoredPrintfMethod · 0.65
ByNameMethod · 0.45
LoadCompleteMethod · 0.45
RefListMethod · 0.45

Tested by

no test coverage detected