MCPcopy Create free account
hub / github.com/bufbuild/buf / newCommit

Function newCommit

private/bufpkg/bufmodule/commit.go:67–106  ·  view source on GitHub ↗
(
	moduleKey ModuleKey,
	getCreateTime func() (time.Time, error),
	options ...CommitOption,
)

Source from the content-addressed store, hash-verified

65}
66
67func 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
108func (c *commit) ModuleKey() ModuleKey {
109 return c.moduleKey

Callers 1

NewCommitFunction · 0.70

Calls 7

newCommitOptionsFunction · 0.85
optionStruct · 0.85
newModuleKeyNoValidateFunction · 0.85
DigestEqualFunction · 0.70
FullNameMethod · 0.65
CommitIDMethod · 0.65
DigestMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…