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

Switching to HashSet for the list of files to be prefetched to improv… #827

Merged
merged 2 commits into from Feb 23, 2019
Merged
Changes from all commits
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
24 changes: 13 additions & 11 deletions GVFS/GVFS.Common/Prefetch/Git/DiffHelper.cs
Expand Up @@ -5,23 +5,24 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace GVFS.Common.Prefetch.Git
{
public class DiffHelper
{
private const string AreaPath = nameof(DiffHelper);

private ITracer tracer;
private List<string> fileList;
private HashSet<string> exactFileList;
private List<string> patternList;
private List<string> folderList;
private HashSet<string> filesAdded = new HashSet<string>(StringComparer.OrdinalIgnoreCase);

private HashSet<DiffTreeResult> stagedDirectoryOperations = new HashSet<DiffTreeResult>(new DiffTreeByNameComparer());
private HashSet<string> stagedFileDeletes = new HashSet<string>(StringComparer.OrdinalIgnoreCase);

private Enlistment enlistment;
private GitProcess git;
private GitProcess git;

public DiffHelper(ITracer tracer, Enlistment enlistment, IEnumerable<string> fileList, IEnumerable<string> folderList, bool includeSymLinks)
: this(tracer, enlistment, new GitProcess(enlistment), fileList, folderList, includeSymLinks)
Expand All @@ -31,7 +32,8 @@ public DiffHelper(ITracer tracer, Enlistment enlistment, IEnumerable<string> fil
public DiffHelper(ITracer tracer, Enlistment enlistment, GitProcess git, IEnumerable<string> fileList, IEnumerable<string> folderList, bool includeSymLinks)
{
this.tracer = tracer;
this.fileList = new List<string>(fileList);
this.exactFileList = new HashSet<string>(fileList.Where(x => !x.StartsWith("*")), StringComparer.OrdinalIgnoreCase);
this.patternList = fileList.Where(x => x.StartsWith("*")).ToList();
this.folderList = new List<string>(folderList);
this.enlistment = enlistment;
this.git = git;
Expand All @@ -41,8 +43,8 @@ public DiffHelper(ITracer tracer, Enlistment enlistment, GitProcess git, IEnumer
this.FileDeleteOperations = new ConcurrentQueue<string>();
this.FileAddOperations = new ConcurrentDictionary<string, HashSet<PathWithMode>>(StringComparer.OrdinalIgnoreCase);
this.RequiredBlobs = new BlockingCollection<string>();
}

}
public bool ShouldIncludeSymLinks { get; set; }

public bool HasFailures { get; private set; }
Expand Down Expand Up @@ -325,15 +327,15 @@ private bool ShouldIncludeResult(DiffTreeResult blobAdd)
return true;
}

if (this.fileList.Count == 0 && this.folderList.Count == 0)
if (this.exactFileList.Count == 0 &&
this.patternList.Count == 0 &&
this.folderList.Count == 0)
{
return true;
}

if (this.fileList.Any(path =>
path.StartsWith("*")
? blobAdd.TargetPath.EndsWith(path.Substring(1), StringComparison.OrdinalIgnoreCase)
: blobAdd.TargetPath.Equals(path, StringComparison.OrdinalIgnoreCase)))
if (this.exactFileList.Contains(blobAdd.TargetPath) ||
this.patternList.Any(path => blobAdd.TargetPath.EndsWith(path.Substring(1), StringComparison.OrdinalIgnoreCase)))
{
return true;
}
Expand Down