Skip to content

Commit

Permalink
StatusCompressor static, values const instead of static
Browse files Browse the repository at this point in the history
  • Loading branch information
coenm committed Sep 10, 2023
1 parent 90bcd1c commit cf7bbad
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 37 deletions.
5 changes: 2 additions & 3 deletions src/RepoM.Api/Git/RepositoryViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,8 @@ private void EnsureStatusCache()
return;
}

var compressor = new StatusCompressor();
_cachedRepositoryStatus = compressor.Compress(Repository);
_cachedRepositoryStatusWithBranch = compressor.CompressWithBranch(Repository);
_cachedRepositoryStatus = StatusCompressor.Compress(Repository);
_cachedRepositoryStatusWithBranch = StatusCompressor.CompressWithBranch(Repository);

_cachedRepositoryStatusCode = repositoryStatusCode;
}
Expand Down
12 changes: 6 additions & 6 deletions src/RepoM.Api/Git/StatusCharacterMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ namespace RepoM.Api.Git;

public static class StatusCharacterMap
{
public static string IdenticalSign => "\u2261";
public const char IDENTICAL_SIGN = '\u2261';

public static string NoUpstreamSign => "\u2302";
public const char NO_UPSTREAM_SIGN = '\u2302';

public static string ArrowUpSign => "\u2191";
public const char ARROW_UP_SIGN = '\u2191';

public static string ArrowDownSign => "\u2193";
public const char ARROW_DOWN_SIGN = '\u2193';

public static string EllipsesSign => "\u2026";
public const char ELLIPSES_SIGN = '\u2026';

public static string StashSign => "\u205E";
public const char STASH_SIGN = '\u205E';
}
19 changes: 10 additions & 9 deletions src/RepoM.Api/Git/StatusCompressor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ namespace RepoM.Api.Git;

using System.Text;

public class StatusCompressor
public static class StatusCompressor
{
private const int COMMIT_SHA_DISPLAY_CHARS = 7;

public string Compress(Repository repository)
public static string Compress(Repository repository)
{
if (string.IsNullOrEmpty(repository.CurrentBranch))
{
Expand All @@ -27,13 +27,13 @@ public string Compress(Repository repository)
{
if (isOnCommitLevel)
{
builder.Append(StatusCharacterMap.IdenticalSign);
builder.Append(StatusCharacterMap.IDENTICAL_SIGN);
}
else
{
if (isBehind)
{
builder.Append($"{StatusCharacterMap.ArrowDownSign}{repository.BehindBy}");
builder.Append($"{StatusCharacterMap.ARROW_DOWN_SIGN}{repository.BehindBy}");
}

if (isAhead)
Expand All @@ -43,13 +43,13 @@ public string Compress(Repository repository)
builder.Append(' ');
}

builder.Append($"{StatusCharacterMap.ArrowUpSign}{repository.AheadBy}");
builder.Append($"{StatusCharacterMap.ARROW_UP_SIGN}{repository.AheadBy}");
}
}
}
else
{
builder.Append(StatusCharacterMap.NoUpstreamSign);
builder.Append(StatusCharacterMap.NO_UPSTREAM_SIGN);
}

if (printAddStagedRemoved)
Expand Down Expand Up @@ -84,13 +84,14 @@ public string Compress(Repository repository)
builder.Append(' ');
}

builder.Append(StatusCharacterMap.StashSign + repository.StashCount);
builder.Append(StatusCharacterMap.STASH_SIGN);
builder.Append(repository.StashCount);
}

return builder.ToString();
}

public string CompressWithBranch(Repository repository)
public static string CompressWithBranch(Repository repository)
{
var branch = repository.CurrentBranch;

Expand All @@ -104,7 +105,7 @@ public string CompressWithBranch(Repository repository)
// put commit shas in parenthesis (), shorten them and show ellipses afterwards
if (repository.CurrentBranchIsDetached && branch.Length > COMMIT_SHA_DISPLAY_CHARS)
{
branch = $"({branch[..COMMIT_SHA_DISPLAY_CHARS]}{StatusCharacterMap.EllipsesSign})";
branch = $"({branch[..COMMIT_SHA_DISPLAY_CHARS]}{StatusCharacterMap.ELLIPSES_SIGN})";
}
}

Expand Down
1 change: 0 additions & 1 deletion src/RepoM.App/Bootstrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ public static void RegisterServices(IFileSystem fileSystem)
{
Container.RegisterInstance<ObjectCache>(MemoryCache.Default);
Container.Register<MainWindow>(Lifestyle.Singleton);
Container.Register<StatusCompressor>(Lifestyle.Singleton);
Container.Register<IRepositoryInformationAggregator, DefaultRepositoryInformationAggregator>(Lifestyle.Singleton);
Container.Register<IRepositoryMonitor, DefaultRepositoryMonitor>(Lifestyle.Singleton);
Container.Register<IRepositoryDetectorFactory, DefaultRepositoryDetectorFactory>(Lifestyle.Singleton);
Expand Down
14 changes: 7 additions & 7 deletions src/RepoM.App/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -641,13 +641,13 @@ private string GetHelp()
{
return _translationService.Translate(
"Help Detail",
StatusCharacterMap.IdenticalSign,
StatusCharacterMap.StashSign,
StatusCharacterMap.IdenticalSign,
StatusCharacterMap.ArrowUpSign,
StatusCharacterMap.ArrowDownSign,
StatusCharacterMap.NoUpstreamSign,
StatusCharacterMap.StashSign
StatusCharacterMap.IDENTICAL_SIGN,
StatusCharacterMap.STASH_SIGN,
StatusCharacterMap.IDENTICAL_SIGN,
StatusCharacterMap.ARROW_UP_SIGN,
StatusCharacterMap.ARROW_DOWN_SIGN,
StatusCharacterMap.NO_UPSTREAM_SIGN,
StatusCharacterMap.STASH_SIGN
);
}

Expand Down
21 changes: 10 additions & 11 deletions tests/RepoM.Api.Tests/Git/StatusCompressorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,28 @@ namespace RepoM.Api.Tests.Git;
public class StatusCompressorTests
{
private readonly RepositoryBuilder _builder = new();
private readonly StatusCompressor _compressor = new();

private string Compress(Repository repo)
private static string Compress(Repository repo)
{
return _compressor.Compress(repo);
return StatusCompressor.Compress(repo);
}

private string CompressWithBranch(Repository repo)
private static string CompressWithBranch(Repository repo)
{
return _compressor.CompressWithBranch(repo);
return StatusCompressor.CompressWithBranch(repo);
}

private string Up => StatusCharacterMap.ArrowUpSign;
private string Up => StatusCharacterMap.ARROW_UP_SIGN.ToString();

private string Down => StatusCharacterMap.ArrowDownSign;
private string Down => StatusCharacterMap.ARROW_DOWN_SIGN.ToString();

private string Eq => StatusCharacterMap.IdenticalSign;
private string Eq => StatusCharacterMap.IDENTICAL_SIGN.ToString();

private string NoUp => StatusCharacterMap.NoUpstreamSign;
private string NoUp => StatusCharacterMap.NO_UPSTREAM_SIGN.ToString();

private string Ellipses => StatusCharacterMap.EllipsesSign;
private string Ellipses => StatusCharacterMap.ELLIPSES_SIGN.ToString();

private string StashCount => StatusCharacterMap.StashSign;
private string StashCount => StatusCharacterMap.STASH_SIGN.ToString();

public class CompressMethod : StatusCompressorTests
{
Expand Down

0 comments on commit cf7bbad

Please sign in to comment.