MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / getMultiBranchTestRevtree1

Function getMultiBranchTestRevtree1

db/revtree_test.go:91–188  ·  view source on GitHub ↗

getMultiBranchTestRevtree1 returns a rev tree with the specified number of revisions/branches ┌────────┐ ┌────────┐ ┌────────┐ ┌────────┐ ╔════════╗ │ 1-a │─│ 2-a │─┬──│ 3-a │─│ 4-a │─║ 5-a ║ └────────┘ └────────┘ │ └────────┘ └────────┘ ╚════════╝ │ ┌─

(ctx context.Context, unconflictedBranchNumRevs, winningBranchNumRevs int, losingBranches []BranchSpec)

Source from the content-addressed store, hash-verified

89//
90// NOTE: the 1-a -- 2-a unconflicted branch can be longer, depending on value of unconflictedBranchNumRevs
91func getMultiBranchTestRevtree1(ctx context.Context, unconflictedBranchNumRevs, winningBranchNumRevs int, losingBranches []BranchSpec) RevTree {
92
93 if unconflictedBranchNumRevs < 1 {
94 panic(fmt.Sprintf("Must have at least 1 unconflictedBranchNumRevs"))
95 }
96
97 winningBranchDigest := "winning"
98
99 const testJSON = `{
100 "revs":[
101 "1-winning"
102 ],
103 "parents":[
104 -1
105 ],
106 "channels":[
107 null
108 ]
109 }`
110
111 revTree := RevTree{}
112 if err := base.JSONUnmarshal([]byte(testJSON), &revTree); err != nil {
113 panic(fmt.Sprintf("Error: %v", err))
114 }
115 if unconflictedBranchNumRevs > 1 {
116 // Add revs to unconflicted branch
117 addRevs(
118 ctx,
119 revTree,
120 "1-winning",
121 unconflictedBranchNumRevs-1,
122 winningBranchDigest,
123 )
124 }
125
126 if winningBranchNumRevs > 0 {
127
128 // Figure out which generation the conflicting branches will start at
129 generation := unconflictedBranchNumRevs
130
131 // Figure out the starting revision id on winning and losing branches
132 winningBranchStartRev := fmt.Sprintf("%d-%s", generation, winningBranchDigest)
133
134 // Add revs to winning branch
135 addRevs(
136 ctx,
137 revTree,
138 winningBranchStartRev,
139 winningBranchNumRevs,
140 winningBranchDigest,
141 )
142
143 }
144
145 for _, losingBranchSpec := range losingBranches {
146
147 if losingBranchSpec.NumRevs > 0 {
148

Calls 3

addRevisionMethod · 0.95
JSONUnmarshalFunction · 0.92
addRevsFunction · 0.85

Tested by

no test coverage detected