10000 Skip building diff patch while doing stage/reset · libgit2/libgit2sharp@bcc25ce · GitHub
[go: up one dir, main page]

Skip to content

Commit bcc25ce

Browse files
committed
Skip building diff patch while doing stage/reset
1 parent 49ca833 commit bcc25ce

File tree

4 files changed

+21
-6
lines changed

4 files changed

+21
-6
lines changed

LibGit2Sharp/CompareOptions.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public CompareOptions()
1212
{
1313
ContextLines = 3;
1414
InterhunkLines = 0;
15+
SkipPatchBuilding = false;
1516
}
1617

1718
/// <summary>
@@ -25,5 +26,11 @@ public CompareOptions()
2526
/// (Default = 0)
2627
/// </summary>
2728
public int InterhunkLines { get; set; }
29+
30+
/// <summary>
31+
/// Flag to skip patch building. May be used if only file name and status required.
32+
/// (Default = false)
33+
/// </summary>
34+
internal bool SkipPatchBuilding { get; set; }
2835
}
2936
}

LibGit2Sharp/Diff.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,8 @@ private TreeChanges BuildTreeChangesFromComparer(
270270
DispatchUnmatchedPaths(explicitPathsOptions, filePaths, matchedPaths);
271271
}
272272

273-
return new TreeChanges(diffList);
273+
bool skipPatchBuilding = (compareOptions != null) && compareOptions.SkipPatchBuilding;
274+
return new TreeChanges(diffList, skipPatchBuilding);
274275
}
275276
}
276277

LibGit2Sharp/Index.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,8 @@ public virtual void Stage(IEnumerable<string> paths, ExplicitPathsOptions explic
156156
{
157157
Ensure.ArgumentNotNull(paths, "paths");
158158

159-
TreeChanges changes = repo.Diff.Compare(DiffModifiers.IncludeUntracked | DiffModifiers.IncludeIgnored, paths, explicitPathsOptions);
159+
var compareOptions = new CompareOptions { SkipPatchBuilding = true };
160+
TreeChanges changes = repo.Diff.Compare(DiffModifiers.IncludeUntracked | DiffModifiers.IncludeIgnored, paths, explicitPathsOptions, compareOptions);
160161

161162
foreach (var treeEntryChanges in changes)
162163
{
@@ -213,7 +214,8 @@ public virtual void Unstage(IEnumerable<string> paths, ExplicitPathsOptions expl
213214

214215
if (repo.Info.IsHeadOrphaned)
215216
{
216-
TreeChanges changes = repo.Diff.Compare(null, DiffTargets.Index, paths, explicitPathsOptions);
217+
var compareOptions = new CompareOptions { SkipPatchBuilding = true };
218+
TreeChanges changes = repo.Diff.Compare(null, DiffTargets.Index, paths, explicitPathsOptions, compareOptions);
217219

218220
Reset(changes);
219221
}
@@ -348,7 +350,8 @@ public virtual void Remove(string path, bool removeFromWorkingDirectory = true,
348350
public virtual void Remove(IEnumerable<string> paths, bool removeFromWorkingDirectory = true, ExplicitPathsOptions explicitPathsOptions = null)
349351
{
350352
var pathsList = paths.ToList();
351-
TreeChanges changes = repo.Diff.Compare(DiffModifiers.IncludeUnmodified | DiffModifiers.IncludeUntracked, pathsList, explicitPathsOptions);
353+
var compareOptions = new CompareOptions { SkipPatchBuilding = true };
354+
TreeChanges changes = repo.Diff.Compare(DiffModifiers.IncludeUnmodified | DiffModifiers.IncludeUntracked, pathsList, explicitPathsOptions, compareOptions);
352355

353356
var pathsTodelete = pathsList.Where(p => Directory.Exists(Path.Combine(repo.Info.WorkingDirectory, p))).ToList();
354357

LibGit2Sharp/TreeChanges.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,14 @@ private static IDictionary<ChangeKind, Action<TreeChanges, TreeEntryChanges>> Bu
4848
protected TreeChanges()
4949
{ }
5050

51-
internal TreeChanges(DiffListSafeHandle diff)
51+
internal TreeChanges(DiffListSafeHandle diff, bool skipPatchBuilding = false)
5252
{
5353
Proxy.git_diff_foreach(diff, FileCallback, null, DataCallback);
54-
Proxy.git_diff_print_patch(diff, PrintCallBack);
54+
55+
if (!skipPatchBuilding)
56+
{
57+
Proxy.git_diff_print_patch(diff, PrintCallBack);
58+
}
5559
}
5660

5761
private int DataCallback(GitDiffDelta delta, GitDiffRange range, GitDiffLineOrigin lineOrigin, IntPtr content, UIntPtr contentLen, IntPtr payload)

0 commit comments

Comments
 (0)
0