コード例 #1
0
        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);
            }
        }
コード例 #2
0
        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);
            }
        }
コード例 #3
0
 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),
     };
 }
コード例 #4
0
 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),
     });
 }
コード例 #5
0
        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));
        }
コード例 #6
0
        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));
        }
コード例 #7
0
        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);
        }
コード例 #8
0
        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);
            }
        }
コード例 #9
0
ファイル: RepositoryCache.cs プロジェクト: automagic/poshgit2
        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;
            }
        }
コード例 #10
0
ファイル: ExpiringCache.cs プロジェクト: automagic/poshgit2
        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;
                }
            }
        }
コード例 #11
0
ファイル: ExpiringCache.cs プロジェクト: TheOneRing/poshgit2
        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);
                }
            }
        }
コード例 #12
0
 private IReadOnlyCollection<string> UpdatePaths(IEnumerable<string> paths, ICurrentWorkingDirectory cwd)
 {
     return paths.Select(p => cwd.CreateRelativePath(Path.GetFullPath(Path.Combine(GitDir, "..", p))))
         .ToList()
         .AsReadOnly();
 }
コード例 #13
0
 private IReadOnlyCollection <string> UpdatePaths(IEnumerable <string> paths, ICurrentWorkingDirectory cwd)
 {
     return(paths.Select(p => cwd.CreateRelativePath(Path.GetFullPath(Path.Combine(GitDir, "..", p))))
            .ToList()
            .AsReadOnly());
 }
コード例 #14
0
 public NamedPipePoshGitClient(ILogger log, ICurrentWorkingDirectory cwd)
 {
     _log        = log;
     _cwd        = cwd;
     _serializer = JsonSerializer.Create();
 }
コード例 #15
0
        public Task<IRepositoryStatus> FindRepoAsync(ICurrentWorkingDirectory cwd, CancellationToken cancellationToken)
        {
            EnsureServerIsAvailable();

            return _repositoryCache.FindRepoAsync(cwd, cancellationToken);
        }
コード例 #16
0
        public Task <IRepositoryStatus> FindRepoAsync(ICurrentWorkingDirectory cwd, CancellationToken cancellationToken)
        {
            EnsureServerIsAvailable();

            return(_repositoryCache.FindRepoAsync(cwd, cancellationToken));
        }
コード例 #17
0
        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;
        }