コード例 #1
0
        public static Repository GetRepositoryReference(string path, string id)
        {
            VersionControlSystem detectedVCS = null;
            FilePath             bestMatch   = FilePath.Null;

            foreach (VersionControlSystem vcs in GetVersionControlSystems())
            {
                var newPath = vcs.GetRepositoryPath(path, id);
                if (!newPath.IsNullOrEmpty)
                {
                    // Check whether we have no match or if a new match is found with a longer path.
                    // TODO: If the repo root is not the same as the repo reference, ask user for input.
                    // TODO: If we have two version control directories in the same place, ask user for input.
                    if (bestMatch.IsNullOrEmpty)
                    {
                        bestMatch   = newPath;
                        detectedVCS = vcs;
                    }
                    else if (bestMatch.CompareTo(newPath) <= 0)
                    {
                        bestMatch   = newPath;
                        detectedVCS = vcs;
                    }
                }
            }
            return(detectedVCS == null ? null : detectedVCS.GetRepositoryReference(bestMatch, id));
        }
コード例 #2
0
        public static Repository GetRepositoryReference(string path, string id)
        {
            VersionControlSystem detectedVCS  = null;
            FilePath             shortestPath = FilePath.Null;

            foreach (VersionControlSystem vcs in GetVersionControlSystems())
            {
                var newPath = vcs.GetRepositoryPath(path, id);
                if (!newPath.IsNullOrEmpty)
                {
                    if (string.IsNullOrEmpty(shortestPath))
                    {
                        shortestPath = newPath;
                        detectedVCS  = vcs;
                    }
                    else if (shortestPath.CompareTo(newPath) <= 0)
                    {
                        // They are guaranteed to be on the same path segments, so choose by path length.
                        shortestPath = newPath;
                        detectedVCS  = vcs;
                    }
                }
            }
            return(detectedVCS == null ? null : detectedVCS.GetRepositoryReference(shortestPath, id));
        }
コード例 #3
0
        public static Repository GetRepositoryReference(string path, string id)
        {
            VersionControlSystem detectedVCS = null;
            FilePath             bestMatch   = FilePath.Null;

            foreach (VersionControlSystem vcs in GetVersionControlSystems())
            {
                var newPath = vcs.GetRepositoryPath(path, id);
                if (!newPath.IsNullOrEmpty)
                {
                    // Check whether we have no match or if a new match is found with a longer path.
                    // TODO: If the repo root is not the same as the repo reference, ask user for input.
                    // TODO: If we have two version control directories in the same place, ask user for input.
                    if (bestMatch.IsNullOrEmpty)
                    {
                        bestMatch   = newPath;
                        detectedVCS = vcs;
                    }
                    else if (bestMatch.CompareTo(newPath) <= 0)
                    {
                        bestMatch   = newPath;
                        detectedVCS = vcs;
                    }
                }
            }

            bestMatch = bestMatch.CanonicalPath;

            lock (repositoryCacheLock) {
                if (repositoryCache.TryGetValue(bestMatch, out var repository))
                {
                    if (!repository.IsDisposed)
                    {
                        return(repository);
                    }
                    repositoryCache.Remove(bestMatch);
                }

                try {
                    var repo = detectedVCS?.GetRepositoryReference(bestMatch, id);
                    if (repo != null)
                    {
                        repo.RepositoryPath = bestMatch.CanonicalPath;
                        repositoryCache.Add(bestMatch, repo);
                        Instrumentation.Repositories.Inc(new RepositoryMetadata(detectedVCS));
                    }
                    return(repo);
                } catch (Exception e) {
                    LoggingService.LogError($"Could not query {detectedVCS.Name} repository reference", e);
                    return(null);
                }
            }
        }
コード例 #4
0
        public static Repository GetRepositoryReference(string path, string id)
        {
            VersionControlSystem detectedVCS = null;
            FilePath             bestMatch   = FilePath.Null;

            foreach (VersionControlSystem vcs in GetVersionControlSystems())
            {
                var newPath = vcs.GetRepositoryPath(path, id);
                if (!newPath.IsNullOrEmpty)
                {
                    // Check whether we have no match or if a new match is found with a longer path.
                    // TODO: If the repo root is not the same as the repo reference, ask user for input.
                    // TODO: If we have two version control directories in the same place, ask user for input.
                    if (bestMatch.IsNullOrEmpty)
                    {
                        bestMatch   = newPath;
                        detectedVCS = vcs;
                    }
                    else if (bestMatch.CompareTo(newPath) <= 0)
                    {
                        bestMatch   = newPath;
                        detectedVCS = vcs;
                    }
                }
            }

            bestMatch = bestMatch.CanonicalPath;

            try {
                return(repositoryCache.GetOrAdd(bestMatch, p => {
                    var result = detectedVCS?.GetRepositoryReference(p, id);
                    if (result != null)
                    {
                        Instrumentation.Repositories.Inc(new RepositoryMetadata(detectedVCS));
                        return result;
                    }
                    // never add null values
                    throw new ArgumentNullException("result");
                }));
            } catch (Exception e) {
                // ArgumentNullException for "result" is expected when GetRepositoryReference returns null, no need to log
                if (!(e is ArgumentNullException ne) || ne.ParamName != "result")
                {
                    LoggingService.LogInternalError($"Could not query {detectedVCS.Name} repository reference", e);
                }
                return(null);
            }
        }