Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit 41e7c28

Browse files
committed
Use ISimpleRepositoryModel instead of IGitRepositoryInfo
IGitRepositoryInfo is a VS type that doesn't cache url information. Switch to our ISimpleRepositoryModel which caches the local and remote information and that we can control.
1 parent 7e40aca commit 41e7c28

File tree

7 files changed

+26
-21
lines changed

7 files changed

+26
-21
lines changed

src/GitHub.Exports/Services/ITeamExplorerServiceHolder.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using GitHub.Primitives;
33
using Microsoft.VisualStudio.TeamFoundation.Git.Extensibility;
4+
using GitHub.Models;
45

56
namespace GitHub.Services
67
{
@@ -28,13 +29,13 @@ public interface ITeamExplorerServiceHolder
2829
/// <summary>
2930
/// A IGitRepositoryInfo representing the currently active repository
3031
/// </summary>
31-
IGitRepositoryInfo ActiveRepo { get; }
32+
ISimpleRepositoryModel ActiveRepo { get; }
3233
/// <summary>
3334
/// Subscribe to be notified when the active repository is set and Notify is called.
3435
/// </summary>
3536
/// <param name="who">The instance that is interested in being called (or a unique key/object for that instance)</param>
3637
/// <param name="handler">The handler to call when ActiveRepo is set</param>
37-
void Subscribe(object who, Action<IGitRepositoryInfo> handler);
38+
void Subscribe(object who, Action<ISimpleRepositoryModel> handler);
3839
/// <summary>
3940
/// Unsubscribe from notifications
4041
/// </summary>
@@ -46,7 +47,7 @@ public interface ITeamExplorerServiceHolder
4647

4748
public interface IGitAwareItem
4849
{
49-
IGitRepositoryInfo ActiveRepo { get; }
50+
ISimpleRepositoryModel ActiveRepo { get; }
5051

5152
/// <summary>
5253
/// Represents the web URL of the repository on GitHub.com, even if the origin is an SSH address.

src/GitHub.VisualStudio/Base/TeamExplorerGitRepoInfo.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using GitHub.Primitives;
1+
using GitHub.Models;
2+
using GitHub.Primitives;
23
using GitHub.Services;
34
using Microsoft.VisualStudio.TeamFoundation.Git.Extensibility;
45
using NullGuard;
@@ -12,9 +13,9 @@ public TeamExplorerGitRepoInfo()
1213
ActiveRepo = null;
1314
}
1415

15-
IGitRepositoryInfo activeRepo;
16+
ISimpleRepositoryModel activeRepo;
1617
[AllowNull]
17-
public IGitRepositoryInfo ActiveRepo
18+
public ISimpleRepositoryModel ActiveRepo
1819
{
1920
[return: AllowNull]
2021
get { return activeRepo; }

src/GitHub.VisualStudio/Base/TeamExplorerItemBase.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using GitHub.VisualStudio.Helpers;
88
using NullGuard;
99
using Octokit;
10+
using GitHub.Extensions;
1011

1112
namespace GitHub.VisualStudio.Base
1213
{
@@ -49,7 +50,7 @@ protected virtual void RepoChanged()
4950
var repo = ActiveRepo;
5051
if (repo != null)
5152
{
52-
var uri = repo.GetUriFromRepository();
53+
var uri = repo.CloneUrl;
5354
if (uri?.RepositoryName != null)
5455
{
5556
ActiveRepoUri = uri;

src/GitHub.VisualStudio/Base/TeamExplorerNavigationItemBase.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using Microsoft.VisualStudio.PlatformUI;
1111
using Microsoft.VisualStudio.TeamFoundation.Git.Extensibility;
1212
using NullGuard;
13+
using GitHub.Models;
1314

1415
namespace GitHub.VisualStudio.Base
1516
{
@@ -56,7 +57,7 @@ void OnThemeChanged()
5657
}
5758
}
5859

59-
void UpdateRepo(IGitRepositoryInfo repo)
60+
void UpdateRepo(ISimpleRepositoryModel repo)
6061
{
6162
ActiveRepo = repo;
6263
RepoChanged();

src/GitHub.VisualStudio/Base/TeamExplorerSectionBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public virtual void SaveContext(object sender, SectionSaveContextEventArgs e)
100100

101101
void SubscribeToRepoChanges()
102102
{
103-
holder.Subscribe(this, (IGitRepositoryInfo repo) =>
103+
holder.Subscribe(this, (ISimpleRepositoryModel repo) =>
104104
{
105105
ActiveRepo = repo;
106106
RepoChanged();

src/GitHub.VisualStudio/Base/TeamExplorerServiceHolder.cs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,16 @@
1111
using System.Linq;
1212
using System.Threading;
1313
using System.Globalization;
14+
using GitHub.Models;
1415

1516
namespace GitHub.VisualStudio.Base
1617
{
1718
[Export(typeof(ITeamExplorerServiceHolder))]
1819
[PartCreationPolicy(CreationPolicy.Shared)]
1920
public class TeamExplorerServiceHolder : ITeamExplorerServiceHolder
2021
{
21-
readonly Dictionary<object, Action<IGitRepositoryInfo>> activeRepoHandlers = new Dictionary<object, Action<IGitRepositoryInfo>>();
22-
IGitRepositoryInfo activeRepo;
22+
readonly Dictionary<object, Action<ISimpleRepositoryModel>> activeRepoHandlers = new Dictionary<object, Action<ISimpleRepositoryModel>>();
23+
ISimpleRepositoryModel activeRepo;
2324
bool activeRepoNotified = false;
2425

2526
IServiceProvider serviceProvider;
@@ -48,24 +49,24 @@ public IServiceProvider ServiceProvider
4849
if (serviceProvider == null)
4950
return;
5051
GitUIContext = GitUIContext ?? UIContext.FromUIContextGuid(new Guid("11B8E6D7-C08B-4385-B321-321078CDD1F8"));
51-
UIContextChanged(GitUIContext?.IsActive ?? false);
52+
UIContextChanged(GitUIContext?.IsActive ?? false, false);
5253
}
5354
}
5455

5556
[AllowNull]
56-
public IGitRepositoryInfo ActiveRepo
57+
public ISimpleRepositoryModel ActiveRepo
5758
{
5859
[return: AllowNull] get { return activeRepo; }
5960
private set
6061
{
61-
if (activeRepo.Compare(value))
62+
if (Equals(activeRepo, value))
6263
return;
6364
activeRepo = value;
6465
NotifyActiveRepo();
6566
}
6667
}
6768

68-
public void Subscribe(object who, Action<IGitRepositoryInfo> handler)
69+
public void Subscribe(object who, Action<ISimpleRepositoryModel> handler)
6970
{
7071
lock(activeRepoHandlers)
7172
{
@@ -140,7 +141,7 @@ async void UIContextChanged(bool active)
140141
if (repos == null)
141142
VsOutputLogger.WriteLine(string.Format(CultureInfo.CurrentCulture, "Error 2002: ActiveRepositories is null. GitService: '{0}'", GitService));
142143
}
143-
return repos?.FirstOrDefault();
144+
return repos?.FirstOrDefault()?.ToModel();
144145
});
145146
}
146147
else
@@ -156,11 +157,11 @@ void CheckAndUpdate(object sender, System.ComponentModel.PropertyChangedEventArg
156157
if (service == null)
157158
return;
158159

159-
var repo = service.ActiveRepositories.FirstOrDefault();
160+
var repo = service.ActiveRepositories.FirstOrDefault()?.ToModel();
160161
// this comparison is safe, the extension method supports null instances
161-
if (!repo.Compare(ActiveRepo))
162+
if (!repo.Equals(ActiveRepo))
162163
// so annoying that this is on the wrong thread
163-
syncContext.Post(r => ActiveRepo = r as IGitRepositoryInfo, repo);
164+
syncContext.Post(r => ActiveRepo = r as ISimpleRepositoryModel, repo);
164165
}
165166

166167
public IGitAwareItem HomeSection

src/GitHub.VisualStudio/TeamExplorer/Connect/GitHubConnectSection.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ async void UpdateRepositoryList(object sender, NotifyCollectionChangedEventArgs
209209
.Cast<ISimpleRepositoryModel>()
210210
.ForEach(async r =>
211211
{
212-
if (String.Equals(Holder.ActiveRepo?.RepositoryPath, r.LocalPath, StringComparison.CurrentCultureIgnoreCase))
212+
if (Equals(Holder.ActiveRepo, r))
213213
SelectedRepository = r;
214214
var repo = await ApiFactory.Create(r.CloneUrl).GetRepository();
215215
r.SetIcon(repo.Private, repo.Fork);
@@ -298,7 +298,7 @@ public void Login()
298298

299299
public bool OpenRepository()
300300
{
301-
var old = Repositories.FirstOrDefault(x => String.Equals(Holder.ActiveRepo?.RepositoryPath, x.LocalPath, StringComparison.CurrentCultureIgnoreCase));
301+
var old = Repositories.FirstOrDefault(x => x.Equals(Holder.ActiveRepo));
302302
// open the solution selection dialog when the user wants to switch to a different repo
303303
// since there's no other way of changing the source control context in VS
304304
if (!Equals(SelectedRepository, old))

0 commit comments

Comments
 (0)