public ReadonlyCopyRepositoryStatus(IRepositoryStatus status, ICurrentWorkingDirectory cwd = null) { Branch = status.Branch; AheadBy = status.AheadBy; BehindBy = status.BehindBy; GitDir = status.GitDir; LocalBranches = status.LocalBranches; RemoteBranches = status.RemoteBranches; Stashes = status.Stashes; Remotes = status.Remotes; Configuration = status.Configuration; if (cwd == null) { CurrentWorkingDirectory = status.CurrentWorkingDirectory; Working = status.Working; Index = status.Index; } else { CurrentWorkingDirectory = cwd.CWD; Working = UpdateItemPaths(status.Working, cwd); Index = UpdateItemPaths(status.Index, cwd); } }
public ChangedItemsCollection UpdateItemPaths(ChangedItemsCollection items, ICurrentWorkingDirectory cwd) { return new ChangedItemsCollection { Added = UpdatePaths(items.Added, cwd), Deleted = UpdatePaths(items.Deleted, cwd), Modified = UpdatePaths(items.Modified, cwd), Unmerged = UpdatePaths(items.Unmerged, cwd), }; }
public ChangedItemsCollection UpdateItemPaths(ChangedItemsCollection items, ICurrentWorkingDirectory cwd) { return(new ChangedItemsCollection { Added = UpdatePaths(items.Added, cwd), Deleted = UpdatePaths(items.Deleted, cwd), Modified = UpdatePaths(items.Modified, cwd), Unmerged = UpdatePaths(items.Unmerged, cwd), }); }
public UpdateableRepositoryStatus(string folder, ILogger log, Func <string, IRepository> repositoryFactory, Func <string, IFolderWatcher> folderWatcherFactory, ICurrentWorkingDirectory cwd) { _log = log; _cwd = cwd; Working = new ChangedItemsCollection(); Index = new ChangedItemsCollection(); Task.Run(() => Initialize(folder, repositoryFactory, folderWatcherFactory)); }
public Task <IRepositoryStatus> FindRepoAsync(ICurrentWorkingDirectory cwd, CancellationToken cancellationToken) { return(SendReceiveCommandAsync(async(reader, writer) => { await writer.WriteLineAsync(cwd.CWD); using (var jsonReader = new JsonTextReader(reader)) { return _serializer .Deserialize <ReadWriteRepositoryStatus>(jsonReader) as IRepositoryStatus; } }, NamedPipeCommand.FindRepo, cancellationToken)); }
private async Task <bool> ProcessGetRepoCommandAsync(ICurrentWorkingDirectory cwd, CancellationToken token) { using (var scope = _scope.BeginLifetimeScope(builder => builder.RegisterInstance(cwd).As <ICurrentWorkingDirectory>())) { var repo = await scope.Resolve <Task <IRepositoryStatus> >(); if (repo != null) { _log.Information("{@Repo}", repo); } else { _log.Information("No repo found: {@Input}", cwd); } } return(true); }
public Task <IRepositoryStatus> FindRepoAsync(ICurrentWorkingDirectory cwd, CancellationToken cancellationToken) { var @null = Task.FromResult <IRepositoryStatus>(null); if (!cwd.IsValid) { return(@null); } var path = cwd.CWD; var repo = FindGitRepo(path); if (repo == null) { return(@null); } IRepositoryStatus oldStatus; if (_repositories.TryGetValue(repo, out oldStatus)) { _log.Information("Found repo: {Path}", repo); return(Task.FromResult(new ReadonlyCopyRepositoryStatus(oldStatus, cwd) as IRepositoryStatus)); } try { _log.Information("Creating repo: {Path}", repo); var status = _factory(repo, cwd); _repositories.Add(repo, status); return(Task.FromResult(new ReadonlyCopyRepositoryStatus(status, cwd) as IRepositoryStatus)); } catch (RepositoryNotFoundException) { return(@null); } }
public Task<IRepositoryStatus> FindRepoAsync(ICurrentWorkingDirectory cwd, CancellationToken cancellationToken) { var @null = Task.FromResult<IRepositoryStatus>(null); if (!cwd.IsValid) { return @null; } var path = cwd.CWD; var repo = FindGitRepo(path); if (repo == null) { return @null; } IRepositoryStatus oldStatus; if (_repositories.TryGetValue(repo, out oldStatus)) { _log.Information("Found repo: {Path}", repo); return Task.FromResult(new ReadonlyCopyRepositoryStatus(oldStatus, cwd) as IRepositoryStatus); } try { _log.Information("Creating repo: {Path}", repo); var status = _factory(repo, cwd); _repositories.Add(repo, status); return Task.FromResult(new ReadonlyCopyRepositoryStatus(status, cwd) as IRepositoryStatus); } catch (RepositoryNotFoundException) { return @null; } }
public Task<IRepositoryStatus> FindRepoAsync(ICurrentWorkingDirectory cwd, CancellationToken cancellationToken) { var @null = Task.FromResult<IRepositoryStatus>(null); if (!cwd.IsValid) { return @null; } var path = cwd.CWD; var repo = FindGitRepo(path); if (repo == null) { return @null; } lock (_cache) { if (_cache.Contains(repo)) { var item = _cache.GetCacheItem(repo); var value = item.Value as IRepositoryStatus; if (value == null) { _log.Warning("Found an entry that is not IRepositoryStatus: {CacheValue}", item.Value?.GetType()); _cache.Remove(repo); } else { _log.Verbose("Found repo: {Path}", repo); return Task.FromResult(new ReadonlyCopyRepositoryStatus(value, cwd) as IRepositoryStatus); } } try { _log.Information("Creating repo: {Path}", repo); var status = _factory(repo, cwd); var policy = new CacheItemPolicy { RemovedCallback = arg => { _log.Information("Removing repo from cache: {Repo}", repo); (arg.CacheItem.Value as IDisposable)?.Dispose(); }, SlidingExpiration = TimeSpan.FromMinutes(10) }; _cache.Add(new CacheItem(repo, status), policy); return Task.FromResult(new ReadonlyCopyRepositoryStatus(status, cwd) as IRepositoryStatus); } catch (RepositoryNotFoundException) { return @null; } catch (Exception e) { _log.Warning(e, "Unknown exception in ExpiringCache"); return @null; } } }
public Task <IRepositoryStatus> FindRepoAsync(ICurrentWorkingDirectory cwd, CancellationToken cancellationToken) { var @null = Task.FromResult <IRepositoryStatus>(null); if (!cwd.IsValid) { return(@null); } var path = cwd.CWD; var repo = FindGitRepo(path); if (repo == null) { return(@null); } lock (_cache) { if (_cache.Contains(repo)) { var item = _cache.GetCacheItem(repo); var value = item.Value as IRepositoryStatus; if (value == null) { _log.Warning("Found an entry that is not IRepositoryStatus: {CacheValue}", item.Value?.GetType()); _cache.Remove(repo); } else { _log.Verbose("Found repo: {Path}", repo); return(Task.FromResult(new ReadonlyCopyRepositoryStatus(value, cwd) as IRepositoryStatus)); } } try { _log.Information("Creating repo: {Path}", repo); var status = _factory(repo, cwd); var policy = new CacheItemPolicy { RemovedCallback = arg => { _log.Information("Removing repo from cache: {Repo}", repo); (arg.CacheItem.Value as IDisposable)?.Dispose(); }, SlidingExpiration = TimeSpan.FromMinutes(10) }; _cache.Add(new CacheItem(repo, status), policy); return(Task.FromResult(new ReadonlyCopyRepositoryStatus(status, cwd) as IRepositoryStatus)); } catch (RepositoryNotFoundException) { return(@null); } catch (Exception e) { _log.Warning(e, "Unknown exception in ExpiringCache"); return(@null); } } }
private IReadOnlyCollection<string> UpdatePaths(IEnumerable<string> paths, ICurrentWorkingDirectory cwd) { return paths.Select(p => cwd.CreateRelativePath(Path.GetFullPath(Path.Combine(GitDir, "..", p)))) .ToList() .AsReadOnly(); }
private IReadOnlyCollection <string> UpdatePaths(IEnumerable <string> paths, ICurrentWorkingDirectory cwd) { return(paths.Select(p => cwd.CreateRelativePath(Path.GetFullPath(Path.Combine(GitDir, "..", p)))) .ToList() .AsReadOnly()); }
public NamedPipePoshGitClient(ILogger log, ICurrentWorkingDirectory cwd) { _log = log; _cwd = cwd; _serializer = JsonSerializer.Create(); }
public Task<IRepositoryStatus> FindRepoAsync(ICurrentWorkingDirectory cwd, CancellationToken cancellationToken) { EnsureServerIsAvailable(); return _repositoryCache.FindRepoAsync(cwd, cancellationToken); }
public Task <IRepositoryStatus> FindRepoAsync(ICurrentWorkingDirectory cwd, CancellationToken cancellationToken) { EnsureServerIsAvailable(); return(_repositoryCache.FindRepoAsync(cwd, cancellationToken)); }
private async Task<bool> ProcessGetRepoCommandAsync(ICurrentWorkingDirectory cwd, CancellationToken token) { using (var scope = _scope.BeginLifetimeScope(builder => builder.RegisterInstance(cwd).As<ICurrentWorkingDirectory>())) { var repo = await scope.Resolve<Task<IRepositoryStatus>>(); if (repo != null) { _log.Information("{@Repo}", repo); } else { _log.Information("No repo found: {@Input}", cwd); } } return true; }