From f47a540394e0ba0a2317b496230f27d0ce9ee595 Mon Sep 17 00:00:00 2001 From: RussKie Date: Mon, 12 Mar 2018 21:22:48 +1100 Subject: [PATCH] Deprecate repository type RSS feed functionality has been deprecated in #4008. However a number of residuals have been left behind, such as: * RepositoryCategoryType.RssFeed, and * RepositoryType.RssFeed * `RepositoryCategoryType` is deprecated and removed - after the removal of RssFeed member it become useless. * `RepositoryType` is deprecated and removed. * `Repository` type has been simplified to only contain the following members: - Path: path to the repository - Category: category has become a property of a repository and it now gets persisted along with it - Anchor: most/least used NB: some changes to DashboardItem are artificial to make the code compile - DashboardItem is being deleted in the subsequent PR. --- GitCommands/GitCommands.csproj | 2 - GitCommands/Repository/RecentRepoInfo.cs | 23 +++++------ GitCommands/Repository/Repositories.cs | 4 +- GitCommands/Repository/Repository.cs | 39 ++++++------------- GitCommands/Repository/RepositoryCategory.cs | 4 +- .../Repository/RepositoryCategoryType.cs | 8 ---- .../RepositoryDescriptionProvider.cs | 11 +++--- GitCommands/Repository/RepositoryHistory.cs | 12 +++--- GitCommands/Repository/RepositoryType.cs | 9 ----- .../DashboardControl/Dashboard.cs | 1 - .../DashboardControl/DashboardCategory.cs | 2 - .../DashboardControl/DashboardItem.cs | 22 +---------- GitUI/CommandsDialogs/FormBrowse.cs | 2 +- GitUI/CommandsDialogs/FormRemotes.cs | 2 +- 14 files changed, 39 insertions(+), 102 deletions(-) delete mode 100644 GitCommands/Repository/RepositoryCategoryType.cs delete mode 100644 GitCommands/Repository/RepositoryType.cs diff --git a/GitCommands/GitCommands.csproj b/GitCommands/GitCommands.csproj index a3d06a9c500..93713458736 100644 --- a/GitCommands/GitCommands.csproj +++ b/GitCommands/GitCommands.csproj @@ -189,9 +189,7 @@ - - diff --git a/GitCommands/Repository/RecentRepoInfo.cs b/GitCommands/Repository/RecentRepoInfo.cs index 7d2c126f011..e856bd43aac 100644 --- a/GitCommands/Repository/RecentRepoInfo.cs +++ b/GitCommands/Repository/RecentRepoInfo.cs @@ -28,17 +28,12 @@ public RecentRepoInfo(Repository repo, bool mostRecent) Caption = Repo.Path; } - if (Repo.Title != null) - { - ShortName = Repo.Title; - } - else if (DirInfo != null) + if (DirInfo != null) { ShortName = DirInfo.Name; + DirInfo = DirInfo.Parent; } - DirInfo = DirInfo?.Parent; - DirName = DirInfo?.FullName ?? ""; } @@ -246,10 +241,15 @@ private string MakePath(string l, string r) private void AddToOrderedMiddleDots(SortedList> orderedRepos, RecentRepoInfo repoInfo) { DirectoryInfo dirInfo; - try { dirInfo = new DirectoryInfo(repoInfo.Repo.Path); + if (!string.Equals(dirInfo.FullName, repoInfo.Repo.Path, StringComparison.OrdinalIgnoreCase)) + { + // this is likely to happen when attempting to interpret windows paths on linux + // e.g. dirInfo = DirectoryInfo("c:\\temp") -> dirInfo => /usr/home/temp + dirInfo = null; + } } catch (Exception) { @@ -259,18 +259,13 @@ private void AddToOrderedMiddleDots(SortedList> ord if (dirInfo == null) { repoInfo.Caption = repoInfo.Repo.Path; - if (repoInfo.Caption.IsNullOrEmpty()) - { - repoInfo.Caption = repoInfo.Repo.Title ?? string.Empty; - } } else { string root = null; string company = null; string repository = null; - var workingDir = dirInfo.Name; - + string workingDir = dirInfo.Name; dirInfo = dirInfo.Parent; if (dirInfo != null) { diff --git a/GitCommands/Repository/Repositories.cs b/GitCommands/Repository/Repositories.cs index 0793fb636fb..0168d98df12 100644 --- a/GitCommands/Repository/Repositories.cs +++ b/GitCommands/Repository/Repositories.cs @@ -112,7 +112,7 @@ private static void AssignRepositoryHistoryFromCategories(RepositoryHistory repo Repository catRepo = FindFirstCategoryRepository(repo.Path); if (catRepo != null) { - repo.Assign(catRepo); + repo.Path = catRepo.Path; } } } @@ -182,7 +182,7 @@ private static BindingList DeserializeRepositories(string xm if (repos != null) { repositories = new BindingList(); - foreach (var repositoryCategory in repos.Where(r => r.CategoryType == RepositoryCategoryType.Repositories)) + foreach (var repositoryCategory in repos) { repositoryCategory.SetIcon(); repositories.Add(repositoryCategory); diff --git a/GitCommands/Repository/Repository.cs b/GitCommands/Repository/Repository.cs index 392597ecf86..e9c8152a749 100644 --- a/GitCommands/Repository/Repository.cs +++ b/GitCommands/Repository/Repository.cs @@ -3,8 +3,11 @@ namespace GitCommands.Repository { + [Serializable] public class Repository { + private string _path; + public enum RepositoryAnchor { MostRecent, @@ -12,48 +15,29 @@ public enum RepositoryAnchor None } - public Repository() + // required by XmlSerializer + private Repository() { Anchor = RepositoryAnchor.None; } - public Repository(string path, string description, string title) + public Repository(string path) : this() { Path = path; - Description = description; - Title = title; - RepositoryType = RepositoryType.Repository; - } - - public string Title { get; set; } - private string _path; - public string Path - { - get => _path ?? string.Empty; - set => _path = value; } - public string Description { get; set; } public RepositoryAnchor Anchor { get; set; } - [XmlIgnore] - public bool IsRemote => PathIsUrl(Path); + public string Category { get; set; } [XmlIgnore] - public RepositoryType RepositoryType { get; set; } + public bool IsRemote => PathIsUrl(Path); - public void Assign(Repository source) + public string Path { - if (source == null) - { - return; - } - - Path = source.Path; - Title = source.Title; - Description = source.Description; - RepositoryType = source.RepositoryType; + get => _path ?? string.Empty; + set => _path = value; } public override string ToString() @@ -61,6 +45,7 @@ public override string ToString() return Path + " (" + Anchor.ToString() + ")"; } + // TODO: doesn't belong here public static bool PathIsUrl(string path) { return !string.IsNullOrEmpty(path) && diff --git a/GitCommands/Repository/RepositoryCategory.cs b/GitCommands/Repository/RepositoryCategory.cs index 80aabbd9d0e..ec8301305a2 100644 --- a/GitCommands/Repository/RepositoryCategory.cs +++ b/GitCommands/Repository/RepositoryCategory.cs @@ -29,8 +29,6 @@ public BindingList Repositories public string Description { get; set; } - public RepositoryCategoryType CategoryType { get; set; } - public virtual void SetIcon() { } @@ -45,4 +43,4 @@ public void AddRepository(Repository repo) Repositories.Add(repo); } } -} \ No newline at end of file +} diff --git a/GitCommands/Repository/RepositoryCategoryType.cs b/GitCommands/Repository/RepositoryCategoryType.cs deleted file mode 100644 index 77cde8ed042..00000000000 --- a/GitCommands/Repository/RepositoryCategoryType.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace GitCommands.Repository -{ - public enum RepositoryCategoryType - { - Repositories, - RssFeed - } -} \ No newline at end of file diff --git a/GitCommands/Repository/RepositoryDescriptionProvider.cs b/GitCommands/Repository/RepositoryDescriptionProvider.cs index 3bb5f0260d4..335df552ba7 100644 --- a/GitCommands/Repository/RepositoryDescriptionProvider.cs +++ b/GitCommands/Repository/RepositoryDescriptionProvider.cs @@ -44,14 +44,15 @@ public string Get(string repositoryDir) } string desc = ReadRepositoryDescription(repositoryDir); - if (desc.IsNullOrEmpty()) + if (!string.IsNullOrWhiteSpace(desc)) { - desc = Repositories.RepositoryHistory.Repositories - .Where(repo => repo.Path.Equals(repositoryDir, StringComparison.CurrentCultureIgnoreCase)) - .Select(repo => repo.Title) - .FirstOrDefault(); + return desc; } + desc = Repositories.RepositoryHistory.Repositories + .Where(repo => repo.Path.Equals(repositoryDir, StringComparison.CurrentCultureIgnoreCase)) + .Select(repo => repo.Path) + .FirstOrDefault(); return desc ?? dirInfo.Name; } diff --git a/GitCommands/Repository/RepositoryHistory.cs b/GitCommands/Repository/RepositoryHistory.cs index b4f916e0a52..ea6c991ea0b 100644 --- a/GitCommands/Repository/RepositoryHistory.cs +++ b/GitCommands/Repository/RepositoryHistory.cs @@ -21,7 +21,10 @@ public RepositoryHistory() [XmlIgnore] public int MaxCount { - get => _maxCount; + get + { + return _maxCount; + } set { _maxCount = value; @@ -34,10 +37,6 @@ public int MaxCount public override void SetIcon() { - foreach (var recentRepository in Repositories) - { - recentRepository.RepositoryType = RepositoryType.History; - } } public void RemoveRecentRepository(string repo) @@ -86,9 +85,8 @@ public void AddMostRecentRepository(string repo) break; } - var repository = new Repository(repo, null, null) + var repository = new Repository(repo) { - RepositoryType = RepositoryType.History, Anchor = anchor }; Repositories.Insert(0, repository); diff --git a/GitCommands/Repository/RepositoryType.cs b/GitCommands/Repository/RepositoryType.cs deleted file mode 100644 index ed9a1bc6f62..00000000000 --- a/GitCommands/Repository/RepositoryType.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace GitCommands.Repository -{ - public enum RepositoryType - { - Repository, - RssFeed, - History - } -} \ No newline at end of file diff --git a/GitUI/CommandsDialogs/BrowseDialog/DashboardControl/Dashboard.cs b/GitUI/CommandsDialogs/BrowseDialog/DashboardControl/Dashboard.cs index 2d913fdf977..ef7eb57550e 100644 --- a/GitUI/CommandsDialogs/BrowseDialog/DashboardControl/Dashboard.cs +++ b/GitUI/CommandsDialogs/BrowseDialog/DashboardControl/Dashboard.cs @@ -232,7 +232,6 @@ public void ShowRecentRepositories() { if (!Repositories.RepositoryCategories.Any(c => c.Repositories.Any(r => r.Path != null && r.Path.Equals(repository.Path, StringComparison.CurrentCultureIgnoreCase)))) { - repository.RepositoryType = RepositoryType.History; filteredRecentRepositoryHistory.Repositories.Add(repository); } } diff --git a/GitUI/CommandsDialogs/BrowseDialog/DashboardControl/DashboardCategory.cs b/GitUI/CommandsDialogs/BrowseDialog/DashboardControl/DashboardCategory.cs index 37d11de9f33..6bb1147a4a6 100644 --- a/GitUI/CommandsDialogs/BrowseDialog/DashboardControl/DashboardCategory.cs +++ b/GitUI/CommandsDialogs/BrowseDialog/DashboardControl/DashboardCategory.cs @@ -224,7 +224,6 @@ private void newCategoryMenuItem_Click(object sender, EventArgs e) } RepositoryCategory.RemoveRepository(_repository); - _repository.RepositoryType = RepositoryType.Repository; newRepositoryCategory.AddRepository(_repository); Repositories.RepositoryCategories.Add(newRepositoryCategory); @@ -303,7 +302,6 @@ private void addToItem_Click(object sender, EventArgs e) if (newRepositoryCategory.Description.Equals(toolStripItem.Text)) { RepositoryCategory.RemoveRepository(_repository); - _repository.RepositoryType = RepositoryType.Repository; newRepositoryCategory.AddRepository(_repository); } } diff --git a/GitUI/CommandsDialogs/BrowseDialog/DashboardControl/DashboardItem.cs b/GitUI/CommandsDialogs/BrowseDialog/DashboardControl/DashboardItem.cs index 09221fb4521..d17cc51a05e 100644 --- a/GitUI/CommandsDialogs/BrowseDialog/DashboardControl/DashboardItem.cs +++ b/GitUI/CommandsDialogs/BrowseDialog/DashboardControl/DashboardItem.cs @@ -3,7 +3,6 @@ using System.Windows.Forms; using GitCommands; using GitCommands.Repository; -using GitUI.Properties; using ResourceManager; namespace GitUI.CommandsDialogs.BrowseDialog.DashboardControl @@ -30,8 +29,6 @@ public DashboardItem(Repository repository) return; } - Bitmap icon = GetRepositoryIcon(repository); - if (AppSettings.DashboardShowCurrentBranch) { _branchNameLoader = new AsyncLoader(); @@ -44,10 +41,10 @@ public DashboardItem(Repository repository) return string.Empty; }, - UpdateBranchName); + UpdateBranchName); } - Initialize(icon, repository.Path, repository.Title, repository.Description); + Initialize(null, repository.Path, null, null); } public DashboardItem(Bitmap icon, string title) @@ -160,21 +157,6 @@ private void DashboardItem_VisibleChanged(object sender, EventArgs e) } } - private static Bitmap GetRepositoryIcon(Repository repository) - { - switch (repository.RepositoryType) - { - case RepositoryType.Repository: - return Resources.Star; - case RepositoryType.RssFeed: - return Resources.rss; - case RepositoryType.History: - return Resources.history; - default: - throw new ArgumentException("Repository type is not supported.", nameof(repository)); - } - } - private void OnKeyDown(object sender, PreviewKeyDownEventArgs e) { if (e.KeyCode == Keys.Enter || e.KeyCode == Keys.Space) diff --git a/GitUI/CommandsDialogs/FormBrowse.cs b/GitUI/CommandsDialogs/FormBrowse.cs index 41c84bbac71..03c3b00cf61 100644 --- a/GitUI/CommandsDialogs/FormBrowse.cs +++ b/GitUI/CommandsDialogs/FormBrowse.cs @@ -1717,7 +1717,7 @@ private void AddWorkingdirDropDownItem(Repository repo, string caption) toolStripItem.Click += (hs, he) => ChangeWorkingDir(repo.Path); - if (repo.Title != null || !repo.Path.Equals(caption)) + if (!repo.Path.Equals(caption)) { toolStripItem.ToolTipText = repo.Path; } diff --git a/GitUI/CommandsDialogs/FormRemotes.cs b/GitUI/CommandsDialogs/FormRemotes.cs index 16bcbed8870..d063c4cf8ef 100644 --- a/GitUI/CommandsDialogs/FormRemotes.cs +++ b/GitUI/CommandsDialogs/FormRemotes.cs @@ -269,7 +269,7 @@ private static void RemoteUpdate(IList remotes, string oldRemoteUrl, if (remotes.All(r => r.Path != newRemoteUrl)) { - remotes.Add(new Repository(newRemoteUrl, null, null)); + remotes.Add(new Repository(newRemoteUrl)); } }