Skip to content

Commit

Permalink
Merge pull request #8952 from gerhardol/feature/range-diff-rev-list
Browse files Browse the repository at this point in the history
range-diff: Incorrect limit when selecting four commits
  • Loading branch information
gerhardol committed Mar 11, 2021
2 parents 9f05f5a + f611964 commit bffea66
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 18 deletions.
28 changes: 13 additions & 15 deletions GitCommands/Git/GitModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,11 @@ public async Task<List<ConflictData>> GetConflictsAsync(string? filename = "")

public int? GetCommitCount(string parent, string child, bool cache = false)
{
if (parent == child)
{
return 0;
}

var args = new GitArgumentBuilder("rev-list")
{
parent,
Expand All @@ -783,25 +788,13 @@ public async Task<List<ConflictData>> GetConflictsAsync(string? filename = "")
return null;
}

public int? GetCommitDiffCount(ObjectId baseId, ObjectId parentId)
public (int? first, int? second) GetCommitRangeDiffCount(ObjectId firstId, ObjectId secondId)
{
var args = new GitArgumentBuilder("rev-list")
{
$"{baseId} {parentId}",
"--count"
};
var output = _gitExecutable.GetOutput(args);

if (int.TryParse(output, out var commitCount))
if (firstId == secondId)
{
return commitCount;
return (0, 0);
}

return null;
}

public (int? first, int? second) GetCommitRangeDiffCount(ObjectId firstId, ObjectId secondId)
{
var args = new GitArgumentBuilder("rev-list")
{
$"{firstId}...{secondId}",
Expand Down Expand Up @@ -3620,6 +3613,11 @@ public string OpenWithDifftool(string? filename, string? oldFileName = "", strin

public ObjectId? GetMergeBase(ObjectId a, ObjectId b)
{
if (a == b)
{
return a;
}

var args = new GitArgumentBuilder("merge-base")
{
a,
Expand Down
10 changes: 7 additions & 3 deletions GitUI/UserControls/FileStatusDiffCalculator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,8 @@ public IReadOnlyList<FileStatusWithDescription> SetDiffs(IReadOnlyList<GitRevisi
// to avoid that GE seem to hang when selecting the range diff
int count = (baseA is null || baseB is null
? baseToFirstCount + baseToSecondCount
: module.GetCommitDiffCount(baseA, firstRevHead)
+ module.GetCommitDiffCount(baseB, selectedRevHead))
: module.GetCommitCount(firstRevHead.ToString(), baseA.ToString(), cache: true)
+ module.GetCommitCount(selectedRevHead.ToString(), baseB.ToString(), cache: true))
?? rangeDiffCommitLimit;
if (!GitVersion.Current.SupportRangeDiffTool || count >= rangeDiffCommitLimit)
{
Expand All @@ -222,7 +222,11 @@ public IReadOnlyList<FileStatusWithDescription> SetDiffs(IReadOnlyList<GitRevisi
return fileStatusDescs;

static ObjectId GetRevisionOrHead(GitRevision rev, Lazy<ObjectId> head)
=> rev.IsArtificial ? head.Value : rev.ObjectId;
=> rev.ObjectId == ObjectId.IndexId
? rev.FirstParentId!
: rev.IsArtificial
? head.Value
: rev.ObjectId;

static string GetDescriptionForRevision(Func<ObjectId, string>? describeRevision, ObjectId objectId)
=> describeRevision is not null ? describeRevision(objectId) : objectId.ToShortString();
Expand Down

0 comments on commit bffea66

Please sign in to comment.