Skip to content

Commit

Permalink
Initial sparse implementation
Browse files Browse the repository at this point in the history
Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
  • Loading branch information
derrickstolee committed Aug 22, 2019
1 parent 536ae42 commit ecb213e
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Scalar.Build/Scalar.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<PropertyGroup Label="Parameters">
<ScalarVersion>0.2.173.2</ScalarVersion>
<GitPackageVersion>2.20190820.1</GitPackageVersion>
<GitPackageVersion>2.20190822.3-sc</GitPackageVersion>
</PropertyGroup>

<PropertyGroup Label="DefaultSettings">
Expand Down
5 changes: 5 additions & 0 deletions Scalar.Common/Git/GitProcess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ public static Result Init(Enlistment enlistment)
return new GitProcess(enlistment).InvokeGitOutsideEnlistment("init \"" + enlistment.WorkingDirectoryBackingRoot + "\"");
}

public static Result SparseCheckoutInit(Enlistment enlistment)
{
return new GitProcess(enlistment).InvokeGitInWorkingDirectoryRoot("sparse-checkout init", useReadObjectHook: false);
}

public static ConfigResult GetFromGlobalConfig(string gitBinPath, string settingName)
{
return new ConfigResult(
Expand Down
3 changes: 2 additions & 1 deletion Scalar.FunctionalTests/Tools/ScalarProcess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ public ScalarProcess(string pathToScalar, string enlistmentRoot, string localCac

public void Clone(string repositorySource, string branchToCheckout, bool skipPrefetch)
{
// TODO: consider sparse clone for functional tests
string args = string.Format(
"clone \"{0}\" \"{1}\" --branch \"{2}\" --local-cache-path \"{3}\" {4}",
"clone --sparse=false \"{0}\" \"{1}\" --branch \"{2}\" --local-cache-path \"{3}\" {4}",
repositorySource,
this.enlistmentRoot,
branchToCheckout,
Expand Down
32 changes: 32 additions & 0 deletions Scalar/CommandLine/CloneVerb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@
using Scalar.Common.FileSystem;
using Scalar.Common.Git;
using Scalar.Common.Http;
<<<<<<< HEAD
using Scalar.Common.Prefetch;
using Scalar.Common.Tracing;
using System;
using System.Collections.Generic;
=======
using Scalar.Common.Tracing;
using System;
>>>>>>> Initial sparse implementation [PR BUILD]
using System.Diagnostics;
using System.IO;
using System.Linq;
Expand Down Expand Up @@ -67,6 +72,16 @@ public class CloneVerb : ScalarVerb
HelpText = "Use this option to override the path for the local Scalar cache.")]
public string LocalCacheRoot { get; set; }

<<<<<<< HEAD
=======
[Option(
"sparse",
Required = false,
Default = true,
HelpText = "When cloning, create a sparse working directory.")]
public bool Sparse { get; set; }

>>>>>>> Initial sparse implementation [PR BUILD]
protected override string VerbName
{
get { return CloneVerbName; }
Expand Down Expand Up @@ -520,6 +535,7 @@ private Result CreateClone(
return new Result(installHooksError);
}

<<<<<<< HEAD
// Place block below in an if statement when sparse clone is available.
{
BlobPrefetcher prefetcher = new BlobPrefetcher(
Expand All @@ -542,6 +558,8 @@ private Result CreateClone(
hydratedFileCount: out int _);
}

=======
>>>>>>> Initial sparse implementation [PR BUILD]
GitProcess.Result forceCheckoutResult = git.ForceCheckout(branch);
if (forceCheckoutResult.ExitCodeIsFailure && forceCheckoutResult.Errors.IndexOf("unable to read tree") > 0)
{
Expand Down Expand Up @@ -639,6 +657,20 @@ private Result TryInitRepo(ITracer tracer, GitRefs refs, Enlistment enlistmentTo
Path.Combine(repoPath, ScalarConstants.DotGit.PackedRefs),
refs.ToPackedRefs());

<<<<<<< HEAD
=======
if (this.Sparse)
{
GitProcess.Result sparseCheckoutResult = GitProcess.SparseCheckoutInit(enlistmentToInit);
if (sparseCheckoutResult.ExitCodeIsFailure)
{
string error = string.Format("Could not init sparse-checkout at to {0}: {1}", repoPath, sparseCheckoutResult.Errors);
tracer.RelatedError(error);
return new Result(error);
}
}

>>>>>>> Initial sparse implementation [PR BUILD]
return new Result(true);
}

Expand Down

0 comments on commit ecb213e

Please sign in to comment.