Skip to content

Commit

Permalink
Deprecate repository type
Browse files Browse the repository at this point in the history
RSS feed functionality has been deprecated in gitextensions#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.
  • Loading branch information
RussKie committed Mar 12, 2018
1 parent 8050a80 commit f47a540
Show file tree
Hide file tree
Showing 14 changed files with 39 additions and 102 deletions.
2 changes: 0 additions & 2 deletions GitCommands/GitCommands.csproj
Expand Up @@ -189,9 +189,7 @@
<Compile Include="Patch\PatchFile.cs" />
<Compile Include="Patch\PatchManager.cs" />
<Compile Include="Repository\Repositories.cs" />
<Compile Include="Repository\RepositoryCategoryType.cs" />
<Compile Include="Repository\RepositoryHistory.cs" />
<Compile Include="Repository\RepositoryType.cs" />
<Compile Include="RevisionGraph.cs" />
<Compile Include="Settings\AppSettings.cs" />
<Compile Include="Statistics\CommitCounter.cs" />
Expand Down
23 changes: 9 additions & 14 deletions GitCommands/Repository/RecentRepoInfo.cs
Expand Up @@ -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 ?? "";
}

Expand Down Expand Up @@ -246,10 +241,15 @@ private string MakePath(string l, string r)
private void AddToOrderedMiddleDots(SortedList<string, List<RecentRepoInfo>> 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)
{
Expand All @@ -259,18 +259,13 @@ private void AddToOrderedMiddleDots(SortedList<string, List<RecentRepoInfo>> 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)
{
Expand Down
4 changes: 2 additions & 2 deletions GitCommands/Repository/Repositories.cs
Expand Up @@ -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;
}
}
}
Expand Down Expand Up @@ -182,7 +182,7 @@ private static BindingList<RepositoryCategory> DeserializeRepositories(string xm
if (repos != null)
{
repositories = new BindingList<RepositoryCategory>();
foreach (var repositoryCategory in repos.Where(r => r.CategoryType == RepositoryCategoryType.Repositories))
foreach (var repositoryCategory in repos)
{
repositoryCategory.SetIcon();
repositories.Add(repositoryCategory);
Expand Down
39 changes: 12 additions & 27 deletions GitCommands/Repository/Repository.cs
Expand Up @@ -3,64 +3,49 @@

namespace GitCommands.Repository
{
[Serializable]
public class Repository
{
private string _path;

public enum RepositoryAnchor
{
MostRecent,
LessRecent,
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()
{
return Path + " (" + Anchor.ToString() + ")";
}

// TODO: doesn't belong here
public static bool PathIsUrl(string path)
{
return !string.IsNullOrEmpty(path) &&
Expand Down
4 changes: 1 addition & 3 deletions GitCommands/Repository/RepositoryCategory.cs
Expand Up @@ -29,8 +29,6 @@ public BindingList<Repository> Repositories

public string Description { get; set; }

public RepositoryCategoryType CategoryType { get; set; }

public virtual void SetIcon()
{
}
Expand All @@ -45,4 +43,4 @@ public void AddRepository(Repository repo)
Repositories.Add(repo);
}
}
}
}
8 changes: 0 additions & 8 deletions GitCommands/Repository/RepositoryCategoryType.cs

This file was deleted.

11 changes: 6 additions & 5 deletions GitCommands/Repository/RepositoryDescriptionProvider.cs
Expand Up @@ -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;
}

Expand Down
12 changes: 5 additions & 7 deletions GitCommands/Repository/RepositoryHistory.cs
Expand Up @@ -21,7 +21,10 @@ public RepositoryHistory()
[XmlIgnore]
public int MaxCount
{
get => _maxCount;
get
{
return _maxCount;
}
set
{
_maxCount = value;
Expand All @@ -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)
Expand Down Expand Up @@ -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);
Expand Down
9 changes: 0 additions & 9 deletions GitCommands/Repository/RepositoryType.cs

This file was deleted.

Expand Up @@ -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);
}
}
Expand Down
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
}
Expand Down
Expand Up @@ -3,7 +3,6 @@
using System.Windows.Forms;
using GitCommands;
using GitCommands.Repository;
using GitUI.Properties;
using ResourceManager;

namespace GitUI.CommandsDialogs.BrowseDialog.DashboardControl
Expand All @@ -30,8 +29,6 @@ public DashboardItem(Repository repository)
return;
}

Bitmap icon = GetRepositoryIcon(repository);

if (AppSettings.DashboardShowCurrentBranch)
{
_branchNameLoader = new AsyncLoader();
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion GitUI/CommandsDialogs/FormBrowse.cs
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion GitUI/CommandsDialogs/FormRemotes.cs
Expand Up @@ -269,7 +269,7 @@ private static void RemoteUpdate(IList<Repository> remotes, string oldRemoteUrl,

if (remotes.All(r => r.Path != newRemoteUrl))
{
remotes.Add(new Repository(newRemoteUrl, null, null));
remotes.Add(new Repository(newRemoteUrl));
}
}

Expand Down

0 comments on commit f47a540

Please sign in to comment.