MCPcopy Index your code
hub / github.com/docker/docker-agent / cloneSessionItem

Function cloneSessionItem

pkg/session/branch.go:128–150  ·  view source on GitHub ↗
(item Item)

Source from the content-addressed store, hash-verified

126}
127
128func cloneSessionItem(item Item) (Item, error) {
129 switch {
130 case item.Message != nil:
131 cloned := cloneMessage(item.Message)
132 // Branched messages must get fresh database IDs when persisted, so
133 // drop the parent's row ID.
134 cloned.ID = 0
135 return Item{Message: cloned}, nil
136 case item.SubSession != nil:
137 clonedSub, err := cloneSubSession(item.SubSession)
138 if err != nil {
139 return Item{}, err
140 }
141 return Item{SubSession: clonedSub}, nil
142 case item.Summary != "":
143 return Item{Summary: item.Summary, Cost: item.Cost}, nil
144 case item.Error != nil:
145 errCopy := *item.Error
146 return Item{Error: &errCopy}, nil
147 default:
148 return Item{}, errors.New("cannot clone empty session item")
149 }
150}
151
152func cloneSubSession(src *Session) (*Session, error) {
153 if src == nil {

Callers 3

branchSessionWithTitleFunction · 0.85
cloneSubSessionFunction · 0.85
TestCloneSessionItemFunction · 0.85

Calls 3

cloneMessageFunction · 0.85
cloneSubSessionFunction · 0.85
NewMethod · 0.45

Tested by 1

TestCloneSessionItemFunction · 0.68