( moduleKey ModuleKey, getCreateTime func() (time.Time, error), options ...CommitOption, )
| 65 | } |
| 66 | |
| 67 | func newCommit( |
| 68 | moduleKey ModuleKey, |
| 69 | getCreateTime func() (time.Time, error), |
| 70 | options ...CommitOption, |
| 71 | ) *commit { |
| 72 | commitOptions := newCommitOptions() |
| 73 | for _, option := range options { |
| 74 | option(commitOptions) |
| 75 | } |
| 76 | if commitOptions.expectedDigest != nil { |
| 77 | // We need to preserve this, as if we do not, the new value for moduleKey |
| 78 | // will end up recursively calling itself when moduleKey.Digest() is called |
| 79 | // in the anonymous function. We could just extract moduleKeyDigestFunc := moduleKey.Digest |
| 80 | // and call that, but we make a variable to reference the original ModuleKey just for consistency. |
| 81 | originalModuleKey := moduleKey |
| 82 | moduleKey = newModuleKeyNoValidate( |
| 83 | originalModuleKey.FullName(), |
| 84 | originalModuleKey.CommitID(), |
| 85 | func() (Digest, error) { |
| 86 | moduleKeyDigest, err := originalModuleKey.Digest() |
| 87 | if err != nil { |
| 88 | return nil, err |
| 89 | } |
| 90 | if !DigestEqual(commitOptions.expectedDigest, moduleKeyDigest) { |
| 91 | return nil, &DigestMismatchError{ |
| 92 | FullName: originalModuleKey.FullName(), |
| 93 | CommitID: originalModuleKey.CommitID(), |
| 94 | ExpectedDigest: commitOptions.expectedDigest, |
| 95 | ActualDigest: moduleKeyDigest, |
| 96 | } |
| 97 | } |
| 98 | return moduleKeyDigest, nil |
| 99 | }, |
| 100 | ) |
| 101 | } |
| 102 | return &commit{ |
| 103 | moduleKey: moduleKey, |
| 104 | getCreateTime: sync.OnceValues(getCreateTime), |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | func (c *commit) ModuleKey() ModuleKey { |
| 109 | return c.moduleKey |
no test coverage detected
searching dependent graphs…