Skip to content

Commit 49fc874

Browse files
Merge pull request #1647: Fix commit-graph expiration
Wow, this was really not working as expected. See microsoft/git#255 for how broken the `--expire-time` argument was. Fix this by using the fixed argument and passing a datetime instead of an offset by seconds. This will provide a longer window for old commit-graph files, but apparently we've been leaving turd files around for a long time without anyone noticing.
2 parents b1b4d18 + af74760 commit 49fc874

3 files changed

Lines changed: 17 additions & 3 deletions

File tree

GVFS/GVFS.Build/GVFS.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
<PropertyGroup Label="Parameters">
55
<GVFSVersion>0.2.173.2</GVFSVersion>
6-
<GitPackageVersion>2.20200323.8</GitPackageVersion>
6+
<GitPackageVersion>2.20200402.1</GitPackageVersion>
77
</PropertyGroup>
88

99
<PropertyGroup Label="DefaultSettings">

GVFS/GVFS.Common/Git/GitProcess.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public class GitProcess : ICredentialStore
1616

1717
private static readonly Encoding UTF8NoBOM = new UTF8Encoding(false);
1818
private static bool failedToSetEncoding = false;
19+
private static string expireTimeDateString;
1920

2021
/// <summary>
2122
/// Lock taken for duration of running executingProcess.
@@ -81,6 +82,19 @@ public GitProcess(string gitBinPath, string workingDirectoryRoot)
8182
}
8283
}
8384

85+
public static string ExpireTimeDateString
86+
{
87+
get
88+
{
89+
if (expireTimeDateString == null)
90+
{
91+
expireTimeDateString = DateTime.Now.Subtract(TimeSpan.FromDays(1)).ToShortDateString();
92+
}
93+
94+
return expireTimeDateString;
95+
}
96+
}
97+
8498
public bool LowerPriority { get; set; }
8599

86100
public static Result Init(Enlistment enlistment)
@@ -540,7 +554,7 @@ public Result WriteCommitGraph(string objectDir, List<string> packs)
540554
{
541555
// Do not expire commit-graph files that have been modified in the last hour.
542556
// This will prevent deleting any commit-graph files that are currently in the commit-graph-chain.
543-
string command = $"commit-graph write --stdin-packs --split --size-multiple=4 --expire-time={1 * 60 * 60} --object-dir \"{objectDir}\"";
557+
string command = $"commit-graph write --stdin-packs --split --size-multiple=4 --expire-time={ExpireTimeDateString} --object-dir \"{objectDir}\"";
544558
return this.InvokeGitInWorkingDirectoryRoot(
545559
command,
546560
useReadObjectHook: true,

GVFS/GVFS.UnitTests/Maintenance/PostFetchStepTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class PostFetchStepTests
1818
private MockGitProcess gitProcess;
1919
private GVFSContext context;
2020

21-
private string CommitGraphWriteCommand => $"commit-graph write --stdin-packs --split --size-multiple=4 --expire-time=3600 --object-dir \"{this.context.Enlistment.GitObjectsRoot}\"";
21+
private string CommitGraphWriteCommand => $"commit-graph write --stdin-packs --split --size-multiple=4 --expire-time={GitProcess.ExpireTimeDateString} --object-dir \"{this.context.Enlistment.GitObjectsRoot}\"";
2222
private string CommitGraphVerifyCommand => $"commit-graph verify --shallow --object-dir \"{this.context.Enlistment.GitObjectsRoot}\"";
2323

2424
[TestCase]

0 commit comments

Comments
 (0)