1212 FingerprinterOption func (* Fingerprinter )
1313
1414 // A Fingerprinter answers whether a task is up-to-date. It owns the
15- // resolution of the fingerprinting method (the task's method, falling back
16- // to the default) and the construction of the underlying checkers, so that
17- // every caller gets the same answer for the same task.
15+ // resolution of the fingerprinting method and the checkers behind it.
1816 Fingerprinter struct {
1917 defaultMethod string
2018 tempDir string
@@ -69,12 +67,9 @@ func (f *Fingerprinter) resolveMethod(t *ast.Task) string {
6967 return f .defaultMethod
7068}
7169
72- // Kind returns the kind of fingerprint variable ("checksum", "timestamp" or
73- // "none") produced by the method resolved for the given task. It is the only
74- // entry point that tolerates an invalid method — it reports it as "checksum"
75- // so that merely naming a variable cannot fail; the method is validated by
76- // [Fingerprinter.SourceValue] and [Fingerprinter.UpToDate], on the paths that
77- // actually need a checker.
70+ // Kind names the fingerprint variable ("checksum", "timestamp" or "none") the
71+ // resolved method injects. An invalid method is reported as "checksum" here and
72+ // rejected by the entry points that build a checker.
7873func (f * Fingerprinter ) Kind (t * ast.Task ) string {
7974 if f .sourcesChecker != nil {
8075 return f .sourcesChecker .Kind ()
@@ -87,12 +82,8 @@ func (f *Fingerprinter) Kind(t *ast.Task) string {
8782 }
8883}
8984
90- // SourceValue returns the value of the fingerprint variable (CHECKSUM or
91- // TIMESTAMP) for the given task. It resolves the checker from the method
92- // itself, not from [Fingerprinter.Kind], so an invalid method is rejected here
93- // rather than silently fingerprinted as a checksum. It is potentially
94- // expensive, so callers should only invoke it when the task actually
95- // references the variable.
85+ // SourceValue returns the value of the fingerprint variable for the given task.
86+ // It is potentially expensive, so only call it when the task references it.
9687func (f * Fingerprinter ) SourceValue (t * ast.Task ) (any , error ) {
9788 sourcesChecker , err := f .resolveSourcesChecker (t )
9889 if err != nil {
@@ -131,39 +122,29 @@ func (f *Fingerprinter) UpToDate(ctx context.Context, t *ast.Task) (bool, error)
131122 statusIsSet := len (t .Status ) != 0
132123 sourcesIsSet := len (t .Sources ) != 0
133124
134- // If status is set, check if it is up-to-date
135125 if statusIsSet {
136126 statusUpToDate , err = statusChecker .IsUpToDate (ctx , t )
137127 if err != nil {
138128 return false , err
139129 }
140130 }
141131
142- // If sources is set, check if they are up-to-date
143132 if sourcesIsSet {
144133 sourcesUpToDate , err = sourcesChecker .IsUpToDate (t )
145134 if err != nil {
146135 return false , err
147136 }
148137 }
149138
150- // If both status and sources are set, the task is up-to-date if both are up-to-date
151139 if statusIsSet && sourcesIsSet {
152140 return statusUpToDate && sourcesUpToDate , nil
153141 }
154-
155- // If only status is set, the task is up-to-date if the status is up-to-date
156142 if statusIsSet {
157143 return statusUpToDate , nil
158144 }
159-
160- // If only sources is set, the task is up-to-date if the sources are up-to-date
161145 if sourcesIsSet {
162146 return sourcesUpToDate , nil
163147 }
164-
165- // If no status or sources are set, the task should always run
166- // i.e. it is never considered "up-to-date"
167148 return false , nil
168149}
169150
@@ -177,9 +158,7 @@ func (f *Fingerprinter) OnError(t *ast.Task) error {
177158 return sourcesChecker .OnError (t )
178159}
179160
180- // resolveSourcesChecker is the single place where a task is mapped to a
181- // [SourcesCheckable], so that every entry point of the [Fingerprinter] agrees
182- // on the checker a given task gets.
161+ // resolveSourcesChecker is the single place where a task is mapped to a checker.
183162func (f * Fingerprinter ) resolveSourcesChecker (t * ast.Task ) (SourcesCheckable , error ) {
184163 if f .sourcesChecker != nil {
185164 return f .sourcesChecker , nil
0 commit comments