@@ -16,6 +16,7 @@ public class PrefetchStep : GitMaintenanceStep
1616 private const int LockWaitTimeMs = 100 ;
1717 private const int WaitingOnLockLogThreshold = 50 ;
1818 private const string PrefetchCommitsAndTreesLock = "prefetch-commits-trees.lock" ;
19+ private const int NoExistingPrefetchPacks = - 1 ;
1920 private readonly TimeSpan timeBetweenPrefetches = TimeSpan . FromMinutes ( 70 ) ;
2021
2122 public PrefetchStep ( GVFSContext context , GitObjects gitObjects , bool requireCacheLock = true )
@@ -80,6 +81,18 @@ protected override void PerformMaintenance()
8081 return ;
8182 }
8283
84+ if ( last == NoExistingPrefetchPacks )
85+ {
86+ /* If there are no existing prefetch packs, that means that either the
87+ * first prefetch is still in progress or the clone was run with "--no-prefetch".
88+ * In either case, we should not run prefetch as a maintenance task.
89+ * If users want to prefetch after cloning with "--no-prefetch", they can run
90+ * "gvfs prefetch" manually. Also, "git pull" and "git fetch" will run prefetch
91+ * as a pre-command hook. */
92+ this . Context . Tracer . RelatedInfo ( this . Area + ": Skipping prefetch since there are no existing prefetch packs" ) ;
93+ return ;
94+ }
95+
8396 DateTime lastDateTime = EpochConverter . FromUnixEpochSeconds ( last ) ;
8497 DateTime now = DateTime . UtcNow ;
8598
@@ -150,7 +163,7 @@ private bool TryGetMaxGoodPrefetchTimestamp(out long maxGoodTimestamp, out strin
150163 . OrderBy ( packInfo => packInfo . Timestamp )
151164 . ToList ( ) ;
152165
153- maxGoodTimestamp = - 1 ;
166+ maxGoodTimestamp = NoExistingPrefetchPacks ;
154167
155168 int firstBadPack = - 1 ;
156169 for ( int i = 0 ; i < orderedPacks . Count ; ++ i )
0 commit comments