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

Method Validate

entity/dag/entity.go:367–397  ·  view source on GitHub ↗

Validate check if the Entity data is valid

()

Source from the content-addressed store, hash-verified

365
366// Validate check if the Entity data is valid
367func (e *Entity) Validate() error {
368 // non-empty
369 if len(e.ops) == 0 && len(e.staging) == 0 {
370 return fmt.Errorf("entity has no operations")
371 }
372
373 // check if each operation are valid
374 for _, op := range e.ops {
375 if err := op.Validate(); err != nil {
376 return err
377 }
378 }
379
380 // check if staging is valid if needed
381 for _, op := range e.staging {
382 if err := op.Validate(); err != nil {
383 return err
384 }
385 }
386
387 // Check that there is no colliding operation's ID
388 ids := make(map[entity.Id]struct{})
389 for _, op := range e.Operations() {
390 if _, ok := ids[op.Id()]; ok {
391 return fmt.Errorf("id collision: %s", op.Id())
392 }
393 ids[op.Id()] = struct{}{}
394 }
395
396 return nil
397}
398
399// Operations return the ordered operations
400func (e *Entity) Operations() []Operation {

Callers 1

CommitMethod · 0.95

Calls 4

OperationsMethod · 0.95
ErrorfMethod · 0.80
ValidateMethod · 0.65
IdMethod · 0.65

Tested by

no test coverage detected