Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Highlighting of authored commits (PR #2672)
Adds highlighting of commits by author. Commits are matched with current user's email address (if no commit is selected) or with email of author of currently selected commit. The feature can be configured in the 'Settings' dialog on the 'Colors' page, commits are highlighted with LighYellow color by default.
- Loading branch information
Showing
18 changed files
with
527 additions
and
258 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace GitCommands.Git | ||
{ | ||
public sealed class AuthorEmailEqualityComparer : IEqualityComparer<GitRevision>, IEqualityComparer<string> | ||
{ | ||
private static readonly AuthorEmailEqualityComparer CachedInstance = new AuthorEmailEqualityComparer(); | ||
public static AuthorEmailEqualityComparer Instance | ||
{ | ||
get { return CachedInstance; } | ||
} | ||
|
||
public bool Equals(GitRevision x, GitRevision y) | ||
{ | ||
if (ReferenceEquals(x, y)) return true; | ||
if (ReferenceEquals(x, null)) return false; | ||
if (ReferenceEquals(y, null)) return false; | ||
return Equals(x.AuthorEmail, y.AuthorEmail); | ||
} | ||
|
||
public int GetHashCode(GitRevision revision) | ||
{ | ||
return GetHashCode(revision.AuthorEmail); | ||
} | ||
|
||
public bool Equals(string firstAuthorEmail, string secondAuthorEmail) | ||
{ | ||
return String.Equals(firstAuthorEmail, secondAuthorEmail, StringComparison.OrdinalIgnoreCase); | ||
} | ||
|
||
public int GetHashCode(string authorEmail) | ||
{ | ||
return authorEmail != null ? authorEmail.GetHashCode() : 0; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
168 changes: 168 additions & 0 deletions
168
GitExtensionsTest/GitUI/AuthorEmailBasedRevisionHighlightingFixture.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
using System; | ||
using System.IO; | ||
using FluentAssertions; | ||
using GitCommands; | ||
using GitCommands.Config; | ||
using GitUI.UserControls; | ||
using NUnit.Framework; | ||
|
||
namespace GitExtensionsTest.GitUI | ||
{ | ||
[TestFixture] | ||
class AuthorEmailBasedRevisionHighlightingFixture | ||
{ | ||
private const string ExpectedAuthorEmail1 = "doe1@example.org"; | ||
private const string ExpectedAuthorEmail2 = "doe2@example.org"; | ||
|
||
[Test] | ||
public void AuthorEmailToHighlight_should_be_null_when_no_revision_change_processed_yet() | ||
{ | ||
var sut = new AuthorEmailBasedRevisionHighlighting(); | ||
|
||
sut.AuthorEmailToHighlight.Should().BeNull(); | ||
} | ||
|
||
[Test] | ||
public void When_multiple_revisions_selected_Then_ProcessSelectionChange_should_return_NoAction() | ||
{ | ||
var sut = new AuthorEmailBasedRevisionHighlighting(); | ||
var currentModule = NewModule(); | ||
|
||
var action = sut.ProcessRevisionSelectionChange(currentModule, | ||
new[] | ||
{ | ||
NewRevisionWithAuthorEmail(currentModule, ExpectedAuthorEmail1), | ||
NewRevisionWithAuthorEmail(currentModule, ExpectedAuthorEmail1) | ||
}); | ||
|
||
action.Should().Be(AuthorEmailBasedRevisionHighlighting.SelectionChangeAction.NoAction); | ||
} | ||
|
||
[Test] | ||
public void Given_previously_selected_revision_When_multiple_revisions_selected_Then_AuthorEmailToHighlight_should_not_change() | ||
{ | ||
var sut = new AuthorEmailBasedRevisionHighlighting(); | ||
var currentModule = NewModule(); | ||
sut.ProcessRevisionSelectionChange(currentModule, | ||
new[] {NewRevisionWithAuthorEmail(currentModule, ExpectedAuthorEmail1)}); | ||
|
||
sut.ProcessRevisionSelectionChange(currentModule, | ||
new[] | ||
{ | ||
NewRevisionWithAuthorEmail(currentModule, ExpectedAuthorEmail2), | ||
NewRevisionWithAuthorEmail(currentModule, ExpectedAuthorEmail1) | ||
}); | ||
|
||
sut.AuthorEmailToHighlight.Should().Be(ExpectedAuthorEmail1); | ||
} | ||
|
||
[Test] | ||
public void Given_no_previously_selected_revision_When_single_revision_selected_Then_ProcessSelectionChange_should_return_RefreshUserInterface() | ||
{ | ||
var sut = new AuthorEmailBasedRevisionHighlighting(); | ||
var currentModule = NewModule(); | ||
|
||
var action = sut.ProcessRevisionSelectionChange(currentModule, new[] { NewRevisionWithAuthorEmail(currentModule, ExpectedAuthorEmail1) }); | ||
|
||
action.Should().Be(AuthorEmailBasedRevisionHighlighting.SelectionChangeAction.RefreshUserInterface); | ||
} | ||
|
||
[Test] | ||
public void Given_no_previously_selected_revision_When_single_revision_selected_Then_AuthorEmailToHighlight_should_change() | ||
{ | ||
var sut = new AuthorEmailBasedRevisionHighlighting(); | ||
var currentModule = NewModule(); | ||
|
||
sut.ProcessRevisionSelectionChange(currentModule, new[] {NewRevisionWithAuthorEmail(currentModule, ExpectedAuthorEmail1)}); | ||
|
||
sut.AuthorEmailToHighlight.Should().Be(ExpectedAuthorEmail1); | ||
} | ||
|
||
[Test] | ||
public void Given_previously_selected_revision_When_single_revision_with_same_author_email_selected_Then_ProcessSelectionChange_should_return_NoAction() | ||
{ | ||
var sut = new AuthorEmailBasedRevisionHighlighting(); | ||
var currentModule = NewModule(); | ||
sut.ProcessRevisionSelectionChange(currentModule, new[] { NewRevisionWithAuthorEmail(currentModule, ExpectedAuthorEmail1) }); | ||
|
||
var action = sut.ProcessRevisionSelectionChange(currentModule, new[] { NewRevisionWithAuthorEmail(currentModule, ExpectedAuthorEmail1) }); | ||
|
||
action.Should().Be(AuthorEmailBasedRevisionHighlighting.SelectionChangeAction.NoAction); | ||
} | ||
|
||
[Test] | ||
public void Given_previously_selected_revision_When_single_revision_with_same_author_email_selected_Then_AuthorEmailToHighlight_should_not_change() | ||
{ | ||
var sut = new AuthorEmailBasedRevisionHighlighting(); | ||
var currentModule = NewModule(); | ||
sut.ProcessRevisionSelectionChange(currentModule, new[] { NewRevisionWithAuthorEmail(currentModule, ExpectedAuthorEmail1) }); | ||
|
||
sut.ProcessRevisionSelectionChange(currentModule, new[] { NewRevisionWithAuthorEmail(currentModule, ExpectedAuthorEmail1) }); | ||
|
||
sut.AuthorEmailToHighlight.Should().Be(ExpectedAuthorEmail1); | ||
} | ||
|
||
[Test] | ||
public void Given_previously_selected_revision_When_single_revision_with_different_author_email_selected_Then_ProcessSelectionChange_should_return_RefreshUserInterface() | ||
{ | ||
var sut = new AuthorEmailBasedRevisionHighlighting(); | ||
var currentModule = NewModule(); | ||
sut.ProcessRevisionSelectionChange(currentModule, new[] { NewRevisionWithAuthorEmail(currentModule, ExpectedAuthorEmail1) }); | ||
|
||
var action = sut.ProcessRevisionSelectionChange(currentModule, new[] { NewRevisionWithAuthorEmail(currentModule, ExpectedAuthorEmail2) }); | ||
|
||
action.Should().Be(AuthorEmailBasedRevisionHighlighting.SelectionChangeAction.RefreshUserInterface); | ||
} | ||
|
||
[Test] | ||
public void Given_previously_selected_revision_When_single_revision_with_different_author_email_selected_Then_AuthorEmailToHighlight_should_change() | ||
{ | ||
var sut = new AuthorEmailBasedRevisionHighlighting(); | ||
var currentModule = NewModule(); | ||
sut.ProcessRevisionSelectionChange(currentModule, new[] { NewRevisionWithAuthorEmail(currentModule, ExpectedAuthorEmail1) }); | ||
|
||
sut.ProcessRevisionSelectionChange(currentModule, new[] { NewRevisionWithAuthorEmail(currentModule, ExpectedAuthorEmail2) }); | ||
|
||
sut.AuthorEmailToHighlight.Should().Be(ExpectedAuthorEmail2); | ||
} | ||
|
||
[Test] | ||
public void Given_previously_selected_revision_When_no_revision_selected_Then_ProcessSelectionChange_should_return_RefreshUserInterface() | ||
{ | ||
var sut = new AuthorEmailBasedRevisionHighlighting(); | ||
var currentModule = NewModule(); | ||
currentModule.SetSetting(SettingKeyString.UserEmail, ExpectedAuthorEmail2); | ||
sut.ProcessRevisionSelectionChange(currentModule, new[] { NewRevisionWithAuthorEmail(currentModule, ExpectedAuthorEmail1) }); | ||
|
||
var action = sut.ProcessRevisionSelectionChange(currentModule, new GitRevision[0]); | ||
|
||
action.Should().Be(AuthorEmailBasedRevisionHighlighting.SelectionChangeAction.RefreshUserInterface); | ||
} | ||
|
||
[Test] | ||
public void Given_previously_selected_revision_When_no_revision_selected_Then_AuthorEmailToHighlight_should_be_value_of_current_user_email_setting() | ||
{ | ||
var sut = new AuthorEmailBasedRevisionHighlighting(); | ||
var currentModule = NewModule(); | ||
currentModule.SetSetting(SettingKeyString.UserEmail, ExpectedAuthorEmail2); | ||
sut.ProcessRevisionSelectionChange(currentModule, new[] { NewRevisionWithAuthorEmail(currentModule, ExpectedAuthorEmail1) }); | ||
|
||
sut.ProcessRevisionSelectionChange(currentModule, new GitRevision[0]); | ||
|
||
sut.AuthorEmailToHighlight.Should().Be(ExpectedAuthorEmail2); | ||
} | ||
|
||
private static GitModule NewModule() | ||
{ | ||
return new GitModule(Path.GetTempPath()); | ||
} | ||
|
||
private static GitRevision NewRevisionWithAuthorEmail(GitModule currentModule, string authorEmail) | ||
{ | ||
return new GitRevision(currentModule, Guid.NewGuid().ToString()) | ||
{ | ||
AuthorEmail = authorEmail | ||
}; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.