예제 #1
0
    public static VersionVariables GetVersion(string directory, Authentication authentication, bool noFetch, IFileSystem fileSystem)
    {
        var gitDir = GitDirFinder.TreeWalkForDotGitDir(directory);

        using (var repo = RepositoryLoader.GetRepo(gitDir))
        {
            var ticks = DirectoryDateFinder.GetLastDirectoryWrite(directory);
            var key   = string.Format("{0}:{1}:{2}", repo.Head.CanonicalName, repo.Head.Tip.Sha, ticks);

            CachedVersion result;
            if (versionCacheVersions.TryGetValue(key, out result))
            {
                if (result.Timestamp != ticks)
                {
                    Logger.WriteInfo("Change detected. flushing cache.");
                    result.VersionVariables = ExecuteCore.ExecuteGitVersion(fileSystem, null, null, authentication, null, noFetch, directory, null);
                }
                return(result.VersionVariables);
            }
            Logger.WriteInfo("Version not in cache. Calculating version.");

            return((versionCacheVersions[key] = new CachedVersion
            {
                VersionVariables = ExecuteCore.ExecuteGitVersion(fileSystem, null, null, authentication, null, noFetch, directory, null),
                Timestamp = ticks
            }).VersionVariables);
        }
    }
예제 #2
0
    public static CachedVersion GetVersion(string gitDirectory, Config configuration)
    {
        using (var repo = RepositoryLoader.GetRepo(gitDirectory))
        {
            var           versionFinder = new GitVersionFinder();
            var           context       = new GitVersionContext(repo, configuration);
            var           ticks         = DirectoryDateFinder.GetLastDirectoryWrite(gitDirectory);
            var           key           = string.Format("{0}:{1}:{2}", repo.Head.CanonicalName, repo.Head.Tip.Sha, ticks);
            CachedVersion cachedVersion;
            if (versionCacheVersions.TryGetValue(key, out cachedVersion))
            {
                if (cachedVersion.Timestamp != ticks)
                {
                    Logger.WriteInfo("Change detected. flushing cache.");
                    cachedVersion.SemanticVersion   = versionFinder.FindVersion(context);
                    cachedVersion.MasterReleaseDate = LastMinorVersionFinder.Execute(repo, new Config(), repo.Head.Tip);
                }
                return(cachedVersion);
            }
            Logger.WriteInfo("Version not in cache. Calculating version.");

            return(versionCacheVersions[key] = new CachedVersion
            {
                SemanticVersion = versionFinder.FindVersion(context),
                MasterReleaseDate = LastMinorVersionFinder.Execute(repo, new Config(), repo.Head.Tip),
                Timestamp = ticks
            });
        }
    }
예제 #3
0
    public static CachedVersion GetVersion(string gitDirectory)
    {
        using (var repo = RepositoryLoader.GetRepo(gitDirectory))
        {
            var           ticks = DirectoryDateFinder.GetLastDirectoryWrite(gitDirectory);
            var           key   = string.Format("{0}:{1}:{2}", repo.Head.CanonicalName, repo.Head.Tip.Sha, ticks);
            CachedVersion cachedVersion;
            if (versionCacheVersions.TryGetValue(key, out cachedVersion))
            {
                if (cachedVersion.Timestamp != ticks)
                {
                    Logger.WriteInfo("Change detected. flushing cache.");
                    cachedVersion.SemanticVersion   = GitVersionFinder.GetSemanticVersion(repo);
                    cachedVersion.MasterReleaseDate = LastVersionOnMasterFinder.Execute(repo, repo.Head.Tip);
                }
                return(cachedVersion);
            }
            Logger.WriteInfo("Version not in cache. Calculating version.");

            //TODO: cope with githubflow
            //if (GitVersionFinder.ShouldGitHubFlowVersioningSchemeApply(repo))
            //{
            //    return rd;
            //}
            return(versionCacheVersions[key] = new CachedVersion
            {
                SemanticVersion = GitVersionFinder.GetSemanticVersion(repo),
                MasterReleaseDate = LastVersionOnMasterFinder.Execute(repo, repo.Head.Tip),
                Timestamp = ticks
            });
        }
    }
예제 #4
0
    public static Tuple <CachedVersion, GitVersionContext> GetVersion(string gitDirectory, Config configuration)
    {
        using (var repo = RepositoryLoader.GetRepo(gitDirectory))
        {
            var versionFinder = new GitVersionFinder();
            var context       = new GitVersionContext(repo, configuration);
            var ticks         = DirectoryDateFinder.GetLastDirectoryWrite(gitDirectory);
            var key           = string.Format("{0}:{1}:{2}", repo.Head.CanonicalName, repo.Head.Tip.Sha, ticks);

            Tuple <CachedVersion, GitVersionContext> result;
            if (versionCacheVersions.TryGetValue(key, out result))
            {
                if (result.Item1.Timestamp != ticks)
                {
                    Logger.WriteInfo("Change detected. flushing cache.");
                    result.Item1.SemanticVersion = versionFinder.FindVersion(context);
                }
                return(result);
            }
            Logger.WriteInfo("Version not in cache. Calculating version.");

            return(versionCacheVersions[key] = Tuple.Create(new CachedVersion
            {
                SemanticVersion = versionFinder.FindVersion(context),
                Timestamp = ticks
            }, context));
        }
    }
예제 #5
0
    public void DirectoryDateFinderTest()
    {
        var stopwatch = Stopwatch.StartNew();

        DirectoryDateFinder.GetLastDirectoryWrite(@"C:\Code\NServiceBus\.git");
        Debug.WriteLine(stopwatch.ElapsedMilliseconds);
        stopwatch = Stopwatch.StartNew();
        DirectoryDateFinder.GetLastDirectoryWrite(@"C:\Code\NServiceBus\.git");
        Debug.WriteLine(stopwatch.ElapsedMilliseconds);
    }