Skip to content

Commit 7c33f9e

Browse files
authored
Merge pull request #1885 from tyrielv/honor-no-prefetch
Ensure --no-prefetch clone is honored by maintenance
2 parents 9a05674 + 14f0d30 commit 7c33f9e

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

GVFS/GVFS.Common/Maintenance/PrefetchStep.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)