@@ -107,7 +107,7 @@ type GitRepositoryReconcilerOptions struct {
107107
108108// gitRepoReconcilerFunc is the function type for all the Git repository
109109// reconciler functions.
110- type gitRepoReconcilerFunc func (ctx context.Context , obj * sourcev1.GitRepository , artifact * sourcev1. Artifact , includes * artifactSet , dir string ) (sreconcile.Result , error )
110+ type gitRepoReconcilerFunc func (ctx context.Context , obj * sourcev1.GitRepository , commit * git. Commit , includes * artifactSet , dir string ) (sreconcile.Result , error )
111111
112112func (r * GitRepositoryReconciler ) SetupWithManager (mgr ctrl.Manager ) error {
113113 return r .SetupWithManagerAndOptions (mgr , GitRepositoryReconcilerOptions {})
@@ -207,7 +207,7 @@ func (r *GitRepositoryReconciler) reconcile(ctx context.Context, obj *sourcev1.G
207207 conditions .MarkReconciling (obj , "NewGeneration" , "reconciling new object generation (%d)" , obj .Generation )
208208 }
209209
210- var artifact sourcev1. Artifact
210+ var commit git. Commit
211211 var includes artifactSet
212212
213213 // Create temp dir for Git clone
@@ -224,7 +224,7 @@ func (r *GitRepositoryReconciler) reconcile(ctx context.Context, obj *sourcev1.G
224224 var res sreconcile.Result
225225 var resErr error
226226 for _ , rec := range reconcilers {
227- recResult , err := rec (ctx , obj , & artifact , & includes , tmpDir )
227+ recResult , err := rec (ctx , obj , & commit , & includes , tmpDir )
228228 // Exit immediately on ResultRequeue.
229229 if recResult == sreconcile .ResultRequeue {
230230 return sreconcile .ResultRequeue , nil
@@ -248,7 +248,8 @@ func (r *GitRepositoryReconciler) reconcile(ctx context.Context, obj *sourcev1.G
248248// If the artifact in the Status object of the resource disappeared from storage, it is removed from the object.
249249// If the object does not have an artifact in its Status object, a v1beta1.ArtifactUnavailableCondition is set.
250250// If the hostname of any of the URLs on the object do not match the current storage server hostname, they are updated.
251- func (r * GitRepositoryReconciler ) reconcileStorage (ctx context.Context , obj * sourcev1.GitRepository , artifact * sourcev1.Artifact , includes * artifactSet , dir string ) (sreconcile.Result , error ) {
251+ func (r * GitRepositoryReconciler ) reconcileStorage (ctx context.Context ,
252+ obj * sourcev1.GitRepository , _ * git.Commit , includes * artifactSet , dir string ) (sreconcile.Result , error ) {
252253 // Garbage collect previous advertised artifact(s) from storage
253254 _ = r .garbageCollect (ctx , obj )
254255
@@ -284,7 +285,7 @@ func (r *GitRepositoryReconciler) reconcileStorage(ctx context.Context, obj *sou
284285// If both the checkout and signature verification are successful, the given artifact pointer is set to a new artifact
285286// with the available metadata.
286287func (r * GitRepositoryReconciler ) reconcileSource (ctx context.Context ,
287- obj * sourcev1.GitRepository , artifact * sourcev1. Artifact , _ * artifactSet , dir string ) (sreconcile.Result , error ) {
288+ obj * sourcev1.GitRepository , commit * git. Commit , _ * artifactSet , dir string ) (sreconcile.Result , error ) {
288289 // Configure authentication strategy to access the source
289290 var authOpts * git.AuthOptions
290291 var err error
@@ -344,7 +345,7 @@ func (r *GitRepositoryReconciler) reconcileSource(ctx context.Context,
344345 // Checkout HEAD of reference in object
345346 gitCtx , cancel := context .WithTimeout (ctx , obj .Spec .Timeout .Duration )
346347 defer cancel ()
347- commit , err := checkoutStrategy .Checkout (gitCtx , dir , obj .Spec .URL , authOpts )
348+ c , err := checkoutStrategy .Checkout (gitCtx , dir , obj .Spec .URL , authOpts )
348349 if err != nil {
349350 e := & serror.Event {
350351 Err : fmt .Errorf ("failed to checkout and determine revision: %w" , err ),
@@ -354,6 +355,8 @@ func (r *GitRepositoryReconciler) reconcileSource(ctx context.Context,
354355 // Coin flip on transient or persistent error, return error and hope for the best
355356 return sreconcile .ResultEmpty , e
356357 }
358+ // Assign the commit to the shared commit reference.
359+ * commit = * c
357360 ctrl .LoggerFrom (ctx ).V (logger .DebugLevel ).Info ("git repository checked out" , "url" , obj .Spec .URL , "revision" , commit .String ())
358361 conditions .Delete (obj , sourcev1 .FetchFailedCondition )
359362
@@ -362,9 +365,6 @@ func (r *GitRepositoryReconciler) reconcileSource(ctx context.Context,
362365 return result , err
363366 }
364367
365- // Create potential new artifact with current available metadata
366- * artifact = r .Storage .NewArtifactFor (obj .Kind , obj .GetObjectMeta (), commit .String (), fmt .Sprintf ("%s.tar.gz" , commit .Hash .String ()))
367-
368368 // Mark observations about the revision on the object
369369 if ! obj .GetArtifact ().HasRevision (commit .String ()) {
370370 message := fmt .Sprintf ("new upstream revision '%s'" , commit .String ())
@@ -383,7 +383,11 @@ func (r *GitRepositoryReconciler) reconcileSource(ctx context.Context,
383383// Source ignore patterns are loaded, and the given directory is archived.
384384// On a successful archive, the artifact and includes in the status of the given object are set, and the symlink in the
385385// storage is updated to its path.
386- func (r * GitRepositoryReconciler ) reconcileArtifact (ctx context.Context , obj * sourcev1.GitRepository , artifact * sourcev1.Artifact , includes * artifactSet , dir string ) (sreconcile.Result , error ) {
386+ func (r * GitRepositoryReconciler ) reconcileArtifact (ctx context.Context ,
387+ obj * sourcev1.GitRepository , commit * git.Commit , includes * artifactSet , dir string ) (sreconcile.Result , error ) {
388+ // Create potential new artifact with current available metadata
389+ artifact := r .Storage .NewArtifactFor (obj .Kind , obj .GetObjectMeta (), commit .String (), fmt .Sprintf ("%s.tar.gz" , commit .Hash .String ()))
390+
387391 // Always restore the Ready condition in case it got removed due to a transient error
388392 defer func () {
389393 if obj .GetArtifact ().HasRevision (artifact .Revision ) && ! includes .Diff (obj .Status .IncludedArtifacts ) {
@@ -419,14 +423,14 @@ func (r *GitRepositoryReconciler) reconcileArtifact(ctx context.Context, obj *so
419423 }
420424
421425 // Ensure artifact directory exists and acquire lock
422- if err := r .Storage .MkdirAll (* artifact ); err != nil {
426+ if err := r .Storage .MkdirAll (artifact ); err != nil {
423427 e := & serror.Event {
424428 Err : fmt .Errorf ("failed to create artifact directory: %w" , err ),
425429 Reason : sourcev1 .StorageOperationFailedReason ,
426430 }
427431 return sreconcile .ResultEmpty , e
428432 }
429- unlock , err := r .Storage .Lock (* artifact )
433+ unlock , err := r .Storage .Lock (artifact )
430434 if err != nil {
431435 return sreconcile .ResultEmpty , & serror.Event {
432436 Err : fmt .Errorf ("failed to acquire lock for artifact: %w" , err ),
@@ -448,7 +452,7 @@ func (r *GitRepositoryReconciler) reconcileArtifact(ctx context.Context, obj *so
448452 }
449453
450454 // Archive directory to storage
451- if err := r .Storage .Archive (artifact , dir , SourceIgnoreFilter (ps , nil )); err != nil {
455+ if err := r .Storage .Archive (& artifact , dir , SourceIgnoreFilter (ps , nil )); err != nil {
452456 return sreconcile .ResultEmpty , & serror.Event {
453457 Err : fmt .Errorf ("unable to archive artifact to storage: %w" , err ),
454458 Reason : sourcev1 .StorageOperationFailedReason ,
@@ -457,14 +461,14 @@ func (r *GitRepositoryReconciler) reconcileArtifact(ctx context.Context, obj *so
457461 r .AnnotatedEventf (obj , map [string ]string {
458462 "revision" : artifact .Revision ,
459463 "checksum" : artifact .Checksum ,
460- }, corev1 .EventTypeNormal , "NewArtifact" , "stored artifact for revision '%s'" , artifact . Revision )
464+ }, corev1 .EventTypeNormal , "NewArtifact" , "stored artifact for commit '%s'" , commit . ShortMessage () )
461465
462466 // Record it on the object
463467 obj .Status .Artifact = artifact .DeepCopy ()
464468 obj .Status .IncludedArtifacts = * includes
465469
466470 // Update symlink on a "best effort" basis
467- url , err := r .Storage .Symlink (* artifact , "latest.tar.gz" )
471+ url , err := r .Storage .Symlink (artifact , "latest.tar.gz" )
468472 if err != nil {
469473 r .eventLogf (ctx , obj , corev1 .EventTypeWarning , sourcev1 .StorageOperationFailedReason ,
470474 "failed to update status URL symlink: %s" , err )
@@ -481,7 +485,8 @@ func (r *GitRepositoryReconciler) reconcileArtifact(ctx context.Context, obj *so
481485// If an include is unavailable, it marks the object with v1beta1.IncludeUnavailableCondition and returns early.
482486// If the copy operations are successful, it deletes the v1beta1.IncludeUnavailableCondition from the object.
483487// If the artifactSet differs from the current set, it marks the object with v1beta1.ArtifactOutdatedCondition.
484- func (r * GitRepositoryReconciler ) reconcileInclude (ctx context.Context , obj * sourcev1.GitRepository , _ * sourcev1.Artifact , includes * artifactSet , dir string ) (sreconcile.Result , error ) {
488+ func (r * GitRepositoryReconciler ) reconcileInclude (ctx context.Context ,
489+ obj * sourcev1.GitRepository , _ * git.Commit , includes * artifactSet , dir string ) (sreconcile.Result , error ) {
485490 artifacts := make (artifactSet , len (obj .Spec .Include ))
486491 for i , incl := range obj .Spec .Include {
487492 // Do this first as it is much cheaper than copy operations
0 commit comments