MCPcopy Index your code
hub / github.com/git-bug/git-bug / readOperationPackClock

Function readOperationPackClock

entity/dag/operation_pack.go:297–325  ·  view source on GitHub ↗

readOperationPackClock is similar to readOperationPack but only read and decode the Lamport clocks. Validity of those is left for the caller to decide.

(repo repository.RepoData, commit repository.Commit)

Source from the content-addressed store, hash-verified

295// readOperationPackClock is similar to readOperationPack but only read and decode the Lamport clocks.
296// Validity of those is left for the caller to decide.
297func readOperationPackClock(repo repository.RepoData, commit repository.Commit) (lamport.Time, lamport.Time, error) {
298 entries, err := repo.ReadTree(commit.TreeHash)
299 if err != nil {
300 return 0, 0, err
301 }
302
303 var createTime lamport.Time
304 var editTime lamport.Time
305
306 for _, entry := range entries {
307 switch {
308 case strings.HasPrefix(entry.Name, createClockEntryPrefix):
309 v, err := strconv.ParseUint(strings.TrimPrefix(entry.Name, createClockEntryPrefix), 10, 64)
310 if err != nil {
311 return 0, 0, errors.Wrap(err, "can't read creation lamport time")
312 }
313 createTime = lamport.Time(v)
314
315 case strings.HasPrefix(entry.Name, editClockEntryPrefix):
316 v, err := strconv.ParseUint(strings.TrimPrefix(entry.Name, editClockEntryPrefix), 10, 64)
317 if err != nil {
318 return 0, 0, errors.Wrap(err, "can't read edit lamport time")
319 }
320 editTime = lamport.Time(v)
321 }
322 }
323
324 return createTime, editTime, nil
325}
326
327// unmarshallPack delegate the unmarshalling of the Operation's JSON to the decoding
328// function provided by the concrete entity. This gives access to the concrete type of each

Callers 1

readClockNoCheckFunction · 0.85

Calls 3

TimeTypeAlias · 0.92
ReadTreeMethod · 0.65
HasPrefixMethod · 0.45

Tested by

no test coverage detected