Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace maintenance with 'git maintenance run' #398

Merged
merged 13 commits into from Oct 8, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
47 changes: 45 additions & 2 deletions Scalar.Common/Git/GitProcess.cs
Expand Up @@ -13,6 +13,15 @@ namespace Scalar.Common.Git
{
public class GitProcess : ICredentialStore
{
public enum MaintenanceTask
{
GC,
CommitGraph,
LooseObjects,
IncrementalRepack,
Prefetch,
}

/// <remarks>
/// For UnitTest purposes
/// </remarks>
Expand Down Expand Up @@ -429,6 +438,38 @@ public Result ForceCheckout(string target)
return this.InvokeGitInWorkingDirectoryRoot("checkout -f " + target, fetchMissingObjects: true);
}

public Result MaintenanceRunTask(MaintenanceTask task, string objectDir)
{
string taskStr;
switch (task)
{
case MaintenanceTask.CommitGraph:
taskStr = "commit-graph";
break;

case MaintenanceTask.LooseObjects:
taskStr = "loose-objects";
break;

case MaintenanceTask.IncrementalRepack:
taskStr = "incremental-repack";
break;

case MaintenanceTask.Prefetch:
taskStr = "prefetch";
break;

default:
throw new InvalidOperationException($"Cannot run maintenance task {task}");
}

return this.InvokeGitInWorkingDirectoryRoot(
$"-c pack.window=0 -c pack.depth=0 maintenance run --task={taskStr} --quiet",
derrickstolee marked this conversation as resolved.
Show resolved Hide resolved
fetchMissingObjects: true,
userInteractive: false,
gitObjectsDirectory: objectDir);
}

public Result ForegroundFetch(string remote)
{
// By using "--refmap", we override the configured refspec,
Expand Down Expand Up @@ -819,7 +860,8 @@ private Result InvokeGitOutsideEnlistment(string command)
bool fetchMissingObjects,
Action<StreamWriter> writeStdIn = null,
Action<string> parseStdOutLine = null,
bool userInteractive = true)
bool userInteractive = true,
string gitObjectsDirectory = null)
{
return this.InvokeGitImpl(
command,
Expand All @@ -829,7 +871,8 @@ private Result InvokeGitOutsideEnlistment(string command)
writeStdIn: writeStdIn,
parseStdOutLine: parseStdOutLine,
timeoutMs: -1,
userInteractive: userInteractive);
userInteractive: userInteractive,
gitObjectsDirectory: gitObjectsDirectory);
}

/// <summary>
Expand Down