Skip to content
Draft
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
6 changes: 6 additions & 0 deletions GVFS/GVFS.Common/GVFSConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,12 @@ public static class DotGVFS
public const string LogName = "logs";
public const string MountLock = "mount.lock";

/// <summary>
/// The mount creates this file when a working-tree change needs a sparse-index cone
/// change that the index does not have yet. The pre-command hook checks it.
/// </summary>
public const string ConeChangePending = "ConeChangePending";

public static class Databases
{
public const string Name = "databases";
Expand Down
68 changes: 68 additions & 0 deletions GVFS/GVFS.Common/Git/GitProcess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -896,6 +896,43 @@ public Result ListSparseDirectories(Action<string> onSparseDirectory)
});
}

/// <summary>
/// List the paths that differ between HEAD and the index or the working tree, with
/// <c>git status --porcelain=v2</c>: changed and unmerged tracked paths, and untracked
/// files. An untracked folder ends with '/'. Git does not list ignored files.
/// </summary>
/// <remarks>
/// <c>git status</c> reads a sparse index without expanding it, and it compares the
/// content of a file whose stat data changed, so a file that has the content of HEAD
/// again is not listed. <c>--no-optional-locks</c> stops Git from writing the refreshed
/// index, so this does not need the GVFS lock. <c>--no-deserialize</c> stops Git from
/// reading the GVFS status cache. The virtual file system stays on, so Git checks only
/// the paths that the mount reports, and it looks for untracked files only there.
/// <c>COMMAND_HOOK_LOCK</c> makes Git skip the pre-command and post-command hooks.
/// </remarks>
public Result ListPathsThatDifferFromHead(Action<string> onPath, int timeoutMs)
{
ArgumentNullException.ThrowIfNull(onPath);

return this.InvokeGitImpl(
"--no-optional-locks status --porcelain=v2 -z --untracked-files=normal --no-renames --ignore-submodules=all --no-deserialize",
workingDirectory: this.workingDirectoryRoot,
dotGitDirectory: null,
useReadObjectHook: true,
writeStdIn: null,
parseStdOutLine: null,
timeoutMs: timeoutMs,
usePreCommandHook: false,
parseStdOutToken: record =>
{
string path = GetPorcelainV2Path(record);
if (path != null)
{
onPath(path);
}
});
}

/// <summary>Run <c>git version --build-options</c>.</summary>
public Result VersionBuildOptions()
{
Expand Down Expand Up @@ -924,6 +961,37 @@ internal static bool HasBuildOption(string buildOptionsOutput, string option)
return false;
}

/// <summary>
/// Return the path of a <c>git status --porcelain=v2 -z</c> record for a changed,
/// unmerged, or untracked entry, or null for any other record. The path of an untracked
/// folder ends with '/'.
/// </summary>
internal static string GetPorcelainV2Path(string record)
{
// "1 XY sub mH mI mW hH hI path", "u XY sub m1 m2 m3 mW h1 h2 h3 path", and
// "? path". The path is the rest of the record, so it can contain spaces.
int pathField;
if (record.StartsWith("1 ", StringComparison.Ordinal))
{
pathField = 8;
}
else if (record.StartsWith("u ", StringComparison.Ordinal))
{
pathField = 10;
}
else if (record.StartsWith("? ", StringComparison.Ordinal))
{
pathField = 1;
}
else
{
return null;
}

string[] fields = record.Split(' ', pathField + 1);
return fields.Length == pathField + 1 && fields[pathField].Length > 0 ? fields[pathField] : null;
}

public Result Status(bool allowObjectDownloads, bool useStatusCache, bool showUntracked = false)
{
string command = "status";
Expand Down
50 changes: 50 additions & 0 deletions GVFS/GVFS.Common/NamedPipes/ConeManagementNamedPipeMessages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ public static partial class NamedPipeMessages
/// no longer runs.
/// </para>
/// <para>
/// When a working-tree change needs a cone change that the index does not have yet,
/// the mount creates the <see cref="GVFSConstants.DotGVFS.ConeChangePending"/> file. The
/// pre-command hook then sends an <see cref="ApplyRequest"/> before Git reads the index,
/// also for a command that names no paths. The requesting Git process must hold the
/// GVFS lock, as for a widen.
/// </para>
/// <para>
/// A body is a list of fields separated by NUL. The header and the body split on the
/// first '|' only, so a field can contain '|'.
/// </para>
Expand All @@ -45,6 +52,7 @@ public static class ConeManagement
{
public const string WidenRequest = "ConeWiden";
public const string NarrowRequest = "ConeNarrow";
public const string ApplyRequest = "ConeApply";

/// <summary>The mount applied the request.</summary>
public const string SuccessResult = "S";
Expand Down Expand Up @@ -73,6 +81,13 @@ public static class ConeManagement
/// </summary>
public const int WidenReplyCeilingMs = 10000;

/// <summary>
/// The time in which the mount applies a pending working-tree change. A slower apply
/// is a warning. The hook waits for the apply reply up to
/// <see cref="WidenReplyCeilingMs"/>, for the same reason as for a widen.
/// </summary>
public const int ApplyWaitBudgetMs = 5000;

/// <summary>
/// The maximum time that the post-command hook waits for a narrow reply. Git has
/// already run, so this wait only delays the return to the user.
Expand Down Expand Up @@ -225,6 +240,41 @@ public static bool TryParse(string body, out NarrowParameters parameters)
return true;
}
}

/// <summary>
/// Parameters for an apply request: the command id of the Git command that holds the
/// GVFS lock and waits for the mount to apply the pending cone change.
/// </summary>
public class ApplyParameters
{
public ApplyParameters(string commandId)
{
this.CommandId = commandId ?? string.Empty;
}

/// <summary>The Git process id, as decimal digits, or empty.</summary>
public string CommandId { get; }

public string ToBody()
{
return this.CommandId;
}

/// <summary>
/// Parse an apply body. Return false when the command id is not valid.
/// </summary>
public static bool TryParse(string body, out ApplyParameters parameters)
{
parameters = null;
if (!IsValidCommandId(body))
{
return false;
}

parameters = new ApplyParameters(body);
return true;
}
}
}
}
}
Loading
Loading