MCPcopy Create free account
hub / github.com/git-bug/git-bug / Validate

Method Validate

entities/identity/identity.go:387–417  ·  view source on GitHub ↗

Validate check if the Identity data is valid

()

Source from the content-addressed store, hash-verified

385
386// Validate check if the Identity data is valid
387func (i *Identity) Validate() error {
388 lastTimes := make(map[string]lamport.Time)
389
390 if len(i.versions) == 0 {
391 return fmt.Errorf("no version")
392 }
393
394 for _, v := range i.versions {
395 if err := v.Validate(); err != nil {
396 return err
397 }
398
399 // check for always increasing lamport time
400 // check that a new version didn't drop a clock
401 for name, previous := range lastTimes {
402 if now, ok := v.times[name]; ok {
403 if now < previous {
404 return fmt.Errorf("non-chronological lamport clock %s (%d --> %d)", name, previous, now)
405 }
406 } else {
407 return fmt.Errorf("version has less lamport clocks than before (missing %s)", name)
408 }
409 }
410
411 for name, now := range v.times {
412 lastTimes[name] = now
413 }
414 }
415
416 return nil
417}
418
419func (i *Identity) lastVersion() *version {
420 if len(i.versions) <= 0 {

Callers 1

CommitMethod · 0.95

Calls 2

ErrorfMethod · 0.80
ValidateMethod · 0.65

Tested by

no test coverage detected