Skip to content

Commit

Permalink
Merge pull request microsoft#1647: Fix commit-graph expiration
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
derrickstolee authored Apr 2, 2020
2 parents b1b4d18 + af74760 commit 49fc874
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion GVFS/GVFS.Build/GVFS.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<PropertyGroup Label="Parameters">
<GVFSVersion>0.2.173.2</GVFSVersion>
<GitPackageVersion>2.20200323.8</GitPackageVersion>
<GitPackageVersion>2.20200402.1</GitPackageVersion>
</PropertyGroup>

<PropertyGroup Label="DefaultSettings">
Expand Down
16 changes: 15 additions & 1 deletion GVFS/GVFS.Common/Git/GitProcess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class GitProcess : ICredentialStore

private static readonly Encoding UTF8NoBOM = new UTF8Encoding(false);
private static bool failedToSetEncoding = false;
private static string expireTimeDateString;

/// <summary>
/// Lock taken for duration of running executingProcess.
Expand Down Expand Up @@ -81,6 +82,19 @@ public GitProcess(string gitBinPath, string workingDirectoryRoot)
}
}

public static string ExpireTimeDateString
{
get
{
if (expireTimeDateString == null)
{
expireTimeDateString = DateTime.Now.Subtract(TimeSpan.FromDays(1)).ToShortDateString();
}

return expireTimeDateString;
}
}

public bool LowerPriority { get; set; }

public static Result Init(Enlistment enlistment)
Expand Down Expand Up @@ -540,7 +554,7 @@ public Result WriteCommitGraph(string objectDir, List<string> packs)
{
// Do not expire commit-graph files that have been modified in the last hour.
// This will prevent deleting any commit-graph files that are currently in the commit-graph-chain.
string command = $"commit-graph write --stdin-packs --split --size-multiple=4 --expire-time={1 * 60 * 60} --object-dir \"{objectDir}\"";
string command = $"commit-graph write --stdin-packs --split --size-multiple=4 --expire-time={ExpireTimeDateString} --object-dir \"{objectDir}\"";
return this.InvokeGitInWorkingDirectoryRoot(
command,
useReadObjectHook: true,
Expand Down
2 changes: 1 addition & 1 deletion GVFS/GVFS.UnitTests/Maintenance/PostFetchStepTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class PostFetchStepTests
private MockGitProcess gitProcess;
private GVFSContext context;

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

[TestCase]
Expand Down

0 comments on commit 49fc874

Please sign in to comment.