Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
</PropertyGroup>

<ItemGroup>
<!-- CLI -->
<PackageVersion Include="CommandLineParser" Version="2.6.0" />

<!-- Serialization -->
<PackageVersion Include="Newtonsoft.Json" Version="13.0.1" />

Expand Down Expand Up @@ -47,7 +44,7 @@
Future packages: pre-declared for Phase 2+ branches to avoid
merge conflicts on this file. Not yet referenced by any project.
-->
<PackageVersion Include="System.CommandLine" Version="2.0.3" />
<PackageVersion Include="System.CommandLine" Version="2.0.5" />
<PackageVersion Include="System.IO.Pipes.AccessControl" Version="8.0.0" />
<PackageVersion Include="System.Text.Json" Version="8.0.5" />
</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion GVFS/FastFetch/FastFetch.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="CommandLineParser" />
<PackageReference Include="System.CommandLine" />
<PackageReference Include="MicroBuild.Core" ExcludeAssets="none" />
</ItemGroup>

Expand Down
205 changes: 111 additions & 94 deletions GVFS/FastFetch/FastFetchVerb.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
using CommandLine;
using GVFS.Common;
using GVFS.Common.Git;
using GVFS.Common.Http;
using GVFS.Common.Prefetch;
using GVFS.Common.Tracing;
using System;
using System.CommandLine;

namespace FastFetch
{
[Verb("fastfetch", HelpText = "Fast-fetch a branch")]
public class FastFetchVerb
{
// Testing has shown that more than 16 download threads does not improve
Expand All @@ -19,131 +18,149 @@ public class FastFetchVerb
private const int ExitFailure = 1;
private const int ExitSuccess = 0;

[Option(
'c',
"commit",
Required = false,
HelpText = "Commit to fetch")]
public string Commit { get; set; }

[Option(
'b',
"branch",
Required = false,
HelpText = "Branch to fetch")]
public string Branch { get; set; }

[Option(
"cache-server-url",
Required = false,
Default = "",
HelpText = "Defines the url of the cache server")]
public string CacheServerUrl { get; set; }

[Option(
"chunk-size",
Required = false,
Default = 4000,
HelpText = "Sets the number of objects to be downloaded in a single pack")]
public int ChunkSize { get; set; }

[Option(
"checkout",
Required = false,
Default = false,
HelpText = "Checkout the target commit into the working directory after fetching")]
public bool Checkout { get; set; }

[Option(
"force-checkout",
Required = false,
Default = false,
HelpText = "Force FastFetch to checkout content as if the current repo had just been initialized." +
"This allows you to include more folders from the repo that were not originally checked out." +
"Can only be used with the --checkout option.")]
public bool ForceCheckout { get; set; }

[Option(
"search-thread-count",
Required = false,
Default = 0,
HelpText = "Sets the number of threads to use for finding missing blobs. (0 for number of logical cores)")]
public int SearchThreadCount { get; set; }

[Option(
"download-thread-count",
Required = false,
Default = 0,
HelpText = "Sets the number of threads to use for downloading. (0 for number of logical cores)")]
public int DownloadThreadCount { get; set; }

[Option(
"index-thread-count",
Required = false,
Default = 0,
HelpText = "Sets the number of threads to use for indexing. (0 for number of logical cores)")]
public int IndexThreadCount { get; set; }

[Option(
"checkout-thread-count",
Required = false,
Default = 0,
HelpText = "Sets the number of threads to use for checkout. (0 for number of logical cores)")]
public int CheckoutThreadCount { get; set; }

[Option(
'r',
"max-retries",
Required = false,
Default = 10,
HelpText = "Sets the maximum number of attempts for downloading a pack")]

public int MaxAttempts { get; set; }

[Option(
"git-path",
Default = "",
Required = false,
HelpText = "Sets the path and filename for git.exe if it isn't expected to be on %PATH%.")]
public string GitBinPath { get; set; }

[Option(
"folders",
Required = false,
Default = "",
HelpText = "A semicolon-delimited list of folders to fetch")]

public string FolderList { get; set; }

[Option(
"folders-list",
Required = false,
Default = "",
HelpText = "A file containing line-delimited list of folders to fetch")]
public string FolderListFile { get; set; }

[Option(
"Allow-index-metadata-update-from-working-tree",
Required = false,
Default = false,
HelpText = "When specified, index metadata (file times and sizes) is updated from disk if not already in the index. " +
"This flag should only be used when the working tree is known to be in a good state. " +
"Do not use this flag if the working tree is not 100% known to be good as it would cause 'git status' to misreport.")]
public bool AllowIndexMetadataUpdateFromWorkingTree { get; set; }

[Option(
"verbose",
Required = false,
Default = false,
HelpText = "Show all outputs on the console in addition to writing them to a log file")]
public bool Verbose { get; set; }

[Option(
"parent-activity-id",
Required = false,
Default = "",
HelpText = "The GUID of the caller - used for telemetry purposes.")]
public string ParentActivityId { get; set; }

public static RootCommand BuildRootCommand()
{
RootCommand rootCommand = new RootCommand("Fast-fetch a branch");

Option<string> commitOption = new Option<string>("--commit", new[] { "-c" }) { Description = "Commit to fetch" };
rootCommand.Add(commitOption);

Option<string> branchOption = new Option<string>("--branch", new[] { "-b" }) { Description = "Branch to fetch" };
rootCommand.Add(branchOption);

Option<string> cacheServerUrlOption = new Option<string>("--cache-server-url")
{
Description = "Defines the url of the cache server",
DefaultValueFactory = (_) => ""
};
rootCommand.Add(cacheServerUrlOption);

Option<int> chunkSizeOption = new Option<int>("--chunk-size")
{
Description = "Sets the number of objects to be downloaded in a single pack",
DefaultValueFactory = (_) => 4000
};
rootCommand.Add(chunkSizeOption);

Option<bool> checkoutOption = new Option<bool>("--checkout") { Description = "Checkout the target commit into the working directory after fetching" };
rootCommand.Add(checkoutOption);

Option<bool> forceCheckoutOption = new Option<bool>("--force-checkout") { Description = "Force FastFetch to checkout content as if the current repo had just been initialized." };
rootCommand.Add(forceCheckoutOption);

Option<int> searchThreadCountOption = new Option<int>("--search-thread-count") { Description = "Sets the number of threads to use for finding missing blobs. (0 for number of logical cores)", DefaultValueFactory = (_) => 0 };
rootCommand.Add(searchThreadCountOption);

Option<int> downloadThreadCountOption = new Option<int>("--download-thread-count") { Description = "Sets the number of threads to use for downloading. (0 for number of logical cores)", DefaultValueFactory = (_) => 0 };
rootCommand.Add(downloadThreadCountOption);

Option<int> indexThreadCountOption = new Option<int>("--index-thread-count") { Description = "Sets the number of threads to use for indexing. (0 for number of logical cores)", DefaultValueFactory = (_) => 0 };
rootCommand.Add(indexThreadCountOption);

Option<int> checkoutThreadCountOption = new Option<int>("--checkout-thread-count") { Description = "Sets the number of threads to use for checkout. (0 for number of logical cores)", DefaultValueFactory = (_) => 0 };
rootCommand.Add(checkoutThreadCountOption);

Option<int> maxRetriesOption = new Option<int>("--max-retries", new[] { "-r" })
{
Description = "Sets the maximum number of attempts for downloading a pack",
DefaultValueFactory = (_) => 10
};
rootCommand.Add(maxRetriesOption);

Option<string> gitPathOption = new Option<string>("--git-path")
{
Description = "Sets the path and filename for git.exe if it isn't expected to be on %PATH%.",
DefaultValueFactory = (_) => ""
};
rootCommand.Add(gitPathOption);

Option<string> foldersOption = new Option<string>("--folders")
{
Description = "A semicolon-delimited list of folders to fetch",
DefaultValueFactory = (_) => ""
};
rootCommand.Add(foldersOption);

Option<string> foldersListOption = new Option<string>("--folders-list")
{
Description = "A file containing line-delimited list of folders to fetch",
DefaultValueFactory = (_) => ""
};
rootCommand.Add(foldersListOption);

Option<bool> allowIndexMetadataOption = new Option<bool>("--Allow-index-metadata-update-from-working-tree") { Description = "When specified, index metadata is updated from disk if not already in the index." };
rootCommand.Add(allowIndexMetadataOption);

Option<bool> verboseOption = new Option<bool>("--verbose") { Description = "Show all outputs on the console in addition to writing them to a log file" };
rootCommand.Add(verboseOption);

Option<string> parentActivityIdOption = new Option<string>("--parent-activity-id")
{
Description = "The GUID of the caller - used for telemetry purposes.",
DefaultValueFactory = (_) => ""
};
rootCommand.Add(parentActivityIdOption);

rootCommand.SetAction((ParseResult result) =>
{
FastFetchVerb verb = new FastFetchVerb();
verb.Commit = result.GetValue(commitOption);
verb.Branch = result.GetValue(branchOption);
verb.CacheServerUrl = result.GetValue(cacheServerUrlOption) ?? "";
verb.ChunkSize = result.GetValue(chunkSizeOption);
verb.Checkout = result.GetValue(checkoutOption);
verb.ForceCheckout = result.GetValue(forceCheckoutOption);
verb.SearchThreadCount = result.GetValue(searchThreadCountOption);
verb.DownloadThreadCount = result.GetValue(downloadThreadCountOption);
verb.IndexThreadCount = result.GetValue(indexThreadCountOption);
verb.CheckoutThreadCount = result.GetValue(checkoutThreadCountOption);
verb.MaxAttempts = result.GetValue(maxRetriesOption);
verb.GitBinPath = result.GetValue(gitPathOption) ?? "";
verb.FolderList = result.GetValue(foldersOption) ?? "";
verb.FolderListFile = result.GetValue(foldersListOption) ?? "";
verb.AllowIndexMetadataUpdateFromWorkingTree = result.GetValue(allowIndexMetadataOption);
verb.Verbose = result.GetValue(verboseOption);
verb.ParentActivityId = result.GetValue(parentActivityIdOption) ?? "";
verb.Execute();
});

return rootCommand;
}

public void Execute()
{
Environment.ExitCode = this.ExecuteWithExitCode();
Expand Down
6 changes: 3 additions & 3 deletions GVFS/FastFetch/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using CommandLine;
using System.CommandLine;
using GVFS.PlatformLoader;

namespace FastFetch
Expand All @@ -8,8 +8,8 @@ public class Program
public static void Main(string[] args)
{
GVFSPlatformLoader.Initialize();
Parser.Default.ParseArguments<FastFetchVerb>(args)
.WithParsed(fastFetch => fastFetch.Execute());
RootCommand rootCommand = FastFetchVerb.BuildRootCommand();
rootCommand.Parse(args).Invoke();
}
}
}
24 changes: 18 additions & 6 deletions GVFS/GVFS.FunctionalTests.LockHolder/AcquireGVFSLock.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using CommandLine;
using GVFS.Common;
using GVFS.Common.NamedPipes;
using GVFS.Platform.Windows;
using System;
using System.CommandLine;
using System.Diagnostics;
using System.Runtime.InteropServices;

Expand All @@ -12,13 +12,25 @@ public class AcquireGVFSLockVerb
{
private static string fullCommand = "GVFS.FunctionalTests.LockHolder";

[Option(
"skip-release-lock",
Default = false,
Required = false,
HelpText = "Skip releasing the GVFS lock when exiting the program.")]
public bool NoReleaseLock { get; set; }

public static RootCommand BuildRootCommand()
{
RootCommand rootCommand = new RootCommand();

Option<bool> skipReleaseLockOption = new Option<bool>("--skip-release-lock") { Description = "Skip releasing the GVFS lock when exiting the program." };
rootCommand.Add(skipReleaseLockOption);

rootCommand.SetAction((ParseResult result) =>
{
AcquireGVFSLockVerb verb = new AcquireGVFSLockVerb();
verb.NoReleaseLock = result.GetValue(skipReleaseLockOption);
verb.Execute();
});

return rootCommand;
}

public void Execute()
{
string errorMessage;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CommandLineParser" />
<PackageReference Include="System.CommandLine" />
</ItemGroup>

<ItemGroup>
Expand Down
6 changes: 3 additions & 3 deletions GVFS/GVFS.FunctionalTests.LockHolder/Program.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
using CommandLine;
using System.CommandLine;

namespace GVFS.FunctionalTests.LockHolder
{
public class Program
{
public static void Main(string[] args)
{
Parser.Default.ParseArguments<AcquireGVFSLockVerb>(args)
.WithParsed(acquireGVFSLock => acquireGVFSLock.Execute());
RootCommand rootCommand = AcquireGVFSLockVerb.BuildRootCommand();
rootCommand.Parse(args).Invoke();
}
}
}
2 changes: 1 addition & 1 deletion GVFS/GVFS.Mount/GVFS.Mount.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="CommandLineParser" />
<PackageReference Include="System.CommandLine" />
</ItemGroup>

</Project>
Loading