Skip to content

Commit 616e9b1

Browse files
Merge pull request #362: 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 4ba6c1c + d72985f commit 616e9b1

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
VFS for Git (which is less flexible). Only update that version if we rely upon a
4444
new command-line interface in Git or if there is a truly broken interaction.
4545
-->
46-
<GitPackageVersion>2.20200323.8</GitPackageVersion>
46+
<GitPackageVersion>2.20200402.1</GitPackageVersion>
4747
<MinimumGitVersion>v2.25.0.vfs.1.1</MinimumGitVersion>
4848

4949
<WatchmanPackageUrl>https://github.com/facebook/watchman/suites/307436006/artifacts/304557</WatchmanPackageUrl>

Scalar.Common/Git/GitProcess.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,24 @@ namespace Scalar.Common.Git
1313
{
1414
public class GitProcess : ICredentialStore
1515
{
16+
/// <remarks>
17+
/// For UnitTest purposes
18+
/// </remarks>
19+
public static string ExpireTimeDateString
20+
{
21+
get
22+
{
23+
if (expireTimeDateString == null)
24+
{
25+
expireTimeDateString = DateTime.Now.Subtract(TimeSpan.FromDays(1)).ToShortDateString();
26+
}
27+
28+
return expireTimeDateString;
29+
}
30+
}
31+
32+
private static string expireTimeDateString;
33+
1634
private const int HResultEHANDLE = -2147024890; // 0x80070006 E_HANDLE
1735

1836
private static readonly Encoding UTF8NoBOM = new UTF8Encoding(false);
@@ -572,10 +590,11 @@ public Result WriteCommitGraph(string objectDir)
572590
{
573591
// Do not expire commit-graph files that have been modified in the last hour.
574592
// This will prevent deleting any commit-graph files that are currently in the commit-graph-chain.
575-
string command = $"commit-graph write --reachable --split --size-multiple=4 --expire-time={1 * 60 * 60} --object-dir \"{objectDir}\"";
593+
string command = $"commit-graph write --reachable --split --size-multiple=4 --expire-time={ExpireTimeDateString} --object-dir \"{objectDir}\"";
576594
return this.InvokeGitInWorkingDirectoryRoot(command, fetchMissingObjects: true);
577595
}
578596

597+
579598
public Result VerifyCommitGraph(string objectDir)
580599
{
581600
string command = "commit-graph verify --shallow --object-dir \"" + objectDir + "\"";

Scalar.UnitTests/Maintenance/CommitGraphStepTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ public class CommitGraphStepTests
1818
private MockGitProcess gitProcess;
1919
private ScalarContext context;
2020

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

2425
[TestCase]

0 commit comments

Comments
 (0)