Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Grr.App/Grr.App.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

<ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.9.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.2" />
<PackageReference Include="System.IO.Abstractions" Version="17.2.1" />
<PackageReference Include="TextCopy" Version="6.1.0" />
</ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions src/GrrUi.App/GrrUi.App.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.2" />
<PackageReference Include="Terminal.Gui" Version="1.7.2" />
<PackageReference Include="TextCopy" Version="6.1.0" />
</ItemGroup>
Expand Down
4 changes: 3 additions & 1 deletion src/RepoM.Api/Common/HardcodededMiniHumanizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ public class HardcodededMiniHumanizer : IHumanizer
private readonly IClock _clock;

public HardcodededMiniHumanizer()
: this(new SystemClock()) { }
: this(new SystemClock())
{
}

public HardcodededMiniHumanizer(IClock clock)
{
Expand Down
9 changes: 3 additions & 6 deletions src/RepoM.Api/Git/DefaultRepositoryIgnoreStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ namespace RepoM.Api.Git;
using System.IO;
using System.IO.Abstractions;
using System.Linq;
using RepoM.Api.Common;
using RepoM.Api.IO;

public class DefaultRepositoryIgnoreStore : FileRepositoryStore, IRepositoryIgnoreStore
Expand All @@ -20,8 +19,8 @@ public DefaultRepositoryIgnoreStore(
IFileSystem fileSystem)
: base(fileSystem)
{
AppDataPathProvider = appDataPathProvider ?? throw new ArgumentNullException(nameof(appDataPathProvider));
_fullFilename = Path.Combine(AppDataPathProvider.GetAppDataPath(), "Repositories.ignore");
_ = appDataPathProvider ?? throw new ArgumentNullException(nameof(appDataPathProvider));
_fullFilename = Path.Combine(appDataPathProvider.GetAppDataPath(), "Repositories.ignore");
}

public override string GetFileName()
Expand Down Expand Up @@ -71,7 +70,7 @@ private List<string> Ignores
return _ignores;
}

_ignores = Get()?.ToList() ?? new List<string>();
_ignores = Get().ToList();
UpdateRules();
}

Expand All @@ -83,6 +82,4 @@ private void UpdateRules()
{
_rules = Ignores.Select(i => new IgnoreRule(i));
}

public IAppDataPathProvider AppDataPathProvider { get; }
}
4 changes: 1 addition & 3 deletions src/RepoM.Api/Git/DefaultRepositoryMonitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,8 @@ public DefaultRepositoryMonitor(
_repositoryObservers = new Dictionary<string, IRepositoryObserver>();
_repositoryIgnoreStore = repositoryIgnoreStore;
_fileSystem = fileSystem ?? throw new ArgumentNullException(nameof(fileSystem));

_storeFlushTimer = new Timer(RepositoryStoreFlushTimerCallback, null, Timeout.Infinite, Timeout.Infinite);

_autoFetchHandler = autoFetchHandler ?? throw new ArgumentNullException(nameof(autoFetchHandler));
_storeFlushTimer = new Timer(RepositoryStoreFlushTimerCallback, null, Timeout.Infinite, Timeout.Infinite);
}

public Task ScanForLocalRepositoriesAsync()
Expand Down
28 changes: 19 additions & 9 deletions src/RepoM.Api/Git/DefaultRepositoryReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@ namespace RepoM.Api.Git;
using System.IO;
using System.Linq;
using LibGit2Sharp;
using Microsoft.Extensions.Logging;
using RepoM.Api.IO.ModuleBasedRepositoryActionProvider;

public class DefaultRepositoryReader : IRepositoryReader
{
private readonly IRepositoryTagsFactory _resolver;
private readonly ILogger _logger;

public DefaultRepositoryReader(IRepositoryTagsFactory resolver)
public DefaultRepositoryReader(IRepositoryTagsFactory resolver, ILogger logger)
{
_resolver = resolver;
_resolver = resolver ?? throw new ArgumentNullException(nameof(resolver));
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
}

public Git.Repository? ReadRepository(string path)
Expand All @@ -26,6 +29,7 @@ public DefaultRepositoryReader(IRepositoryTagsFactory resolver)
var repoPath = LibGit2Sharp.Repository.Discover(path);
if (string.IsNullOrEmpty(repoPath))
{
_logger.LogWarning("Could not Discover git repo in path {path}", path);
return null;
// return Api.Git.Repository.Empty;
}
Expand All @@ -35,6 +39,11 @@ public DefaultRepositoryReader(IRepositoryTagsFactory resolver)
{
result.Tags = _resolver.GetTags(result).ToArray();
}
else
{
_logger.LogWarning("Could not read git repo in path {path}", repoPath);
}

return result;
}

Expand All @@ -51,14 +60,14 @@ public DefaultRepositoryReader(IRepositoryTagsFactory resolver)
}
catch (LockedFileException)
{
_logger.LogWarning("LockedFileException {path}", repoPath);

if (currentTry >= maxRetries)
{
throw;
}
else
{
System.Threading.Thread.Sleep(500);
}

System.Threading.Thread.Sleep(500);
}

currentTry++;
Expand All @@ -67,7 +76,7 @@ public DefaultRepositoryReader(IRepositoryTagsFactory resolver)
return repository;
}

private static Git.Repository? ReadRepositoryInternal(string repoPath)
private Git.Repository? ReadRepositoryInternal(string repoPath)
{
try
{
Expand All @@ -78,7 +87,7 @@ public DefaultRepositoryReader(IRepositoryTagsFactory resolver)

HeadDetails headDetails = GetHeadDetails(repo);

var repository = new Git.Repository()
var repository = new Git.Repository
{
Name = workingDirectory.Name,
Path = workingDirectory.FullName,
Expand Down Expand Up @@ -114,8 +123,9 @@ public DefaultRepositoryReader(IRepositoryTagsFactory resolver)

return repository;
}
catch (Exception)
catch (Exception e)
{
_logger.LogError(e, "Could not read (LibGit2Sharp) repo in {path}.", repoPath);
return null;
// return Api.Git.Repository.Empty;
}
Expand Down
1 change: 0 additions & 1 deletion src/RepoM.Api/Git/DefaultRepositoryStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ namespace RepoM.Api.Git;
using System;
using System.IO;
using System.IO.Abstractions;
using RepoM.Api.Common;
using RepoM.Api.IO;

public class DefaultRepositoryStore : FileRepositoryStore
Expand Down
18 changes: 9 additions & 9 deletions src/RepoM.Api/Git/FileRepositoryStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@ namespace RepoM.Api.Git;
using System.Collections.Generic;
using System.IO.Abstractions;
using System.Linq;
using RepoM.Api.Common;

public abstract class FileRepositoryStore : IRepositoryStore
{
private protected readonly IFileSystem FileSystem;
private readonly IFileSystem _fileSystem;

protected FileRepositoryStore(IFileSystem fileSystem)
{
FileSystem = fileSystem ?? throw new ArgumentNullException(nameof(fileSystem));
_fileSystem = fileSystem ?? throw new ArgumentNullException(nameof(fileSystem));
}

public abstract string GetFileName();
Expand All @@ -24,11 +23,11 @@ public IEnumerable<string> Get(string file)
return Array.Empty<string>();
}

if (FileSystem.File.Exists(file))
if (_fileSystem.File.Exists(file))
{
try
{
return FileSystem.File.ReadAllLines(file);
return _fileSystem.File.ReadAllLines(file);
}
catch (Exception)
{
Expand All @@ -53,22 +52,23 @@ public void Set(IEnumerable<string> paths)
}

var file = GetFileName();
var path = FileSystem.Directory.GetParent(file).FullName;
var path = _fileSystem.Directory.GetParent(file).FullName;

if (!FileSystem.Directory.Exists(path))
if (!_fileSystem.Directory.Exists(path))
{
FileSystem.Directory.CreateDirectory(path);
_fileSystem.Directory.CreateDirectory(path);
}

try
{
FileSystem.File.WriteAllLines(GetFileName(), paths.ToArray());
_fileSystem.File.WriteAllLines(GetFileName(), paths.ToArray());
}
catch (Exception)
{
// swallow for now.
}
}

// todo remove
public bool UseFilePersistence { get; set; } = true;
}
1 change: 0 additions & 1 deletion src/RepoM.Api/Git/Remote.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ namespace RepoM.Api.Git;
using System;
using System.Diagnostics;
using System.IO;
using System.Xml.Linq;

[DebuggerDisplay("{Key}/{Name}")]
public class Remote
Expand Down
4 changes: 2 additions & 2 deletions src/RepoM.Api/Git/Repository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ public override bool Equals(object obj)

private static string? Normalize(string path)
{
// yeah not that beautiful but we have to add a blackslash
// or slash (depending on the OS) and on Mono, I dont have Path.PathSeparator.
// yeah not that beautiful but we have to add a backslash
// or slash (depending on the OS) and on Mono, I don't have Path.PathSeparator.
// so we add a random char with Path.Combine() and remove it again
path = System.IO.Path.Combine(path, "_");
path = path.Substring(0, path.Length - 1);
Expand Down
9 changes: 8 additions & 1 deletion src/RepoM.Api/IO/DefaultAppDataPathProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,21 @@ namespace RepoM.Api.IO;
using System.IO;

public class DefaultAppDataPathProvider : IAppDataPathProvider
{
{
private static readonly string _applicationDataRepoM = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "RepoM");

private DefaultAppDataPathProvider()
{
}

public static DefaultAppDataPathProvider Instance { get; } = new();

public string GetAppDataPath()
{
return _applicationDataRepoM ;
}

[Obsolete("Not used.")]
public string GetAppResourcesPath()
{
return Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location);
Expand Down
Loading