コード例 #1
0
        private static void ApplyConfigOverrides(SVM.Configuration config, VersionContext context)
        {
            if (config == null)
            {
                return;
            }

            var firstMatch = config.Branches
                             .Overrides.FirstOrDefault(x => Regex.IsMatch(context.Result.CanonicalBranchName, x.Match, RegexOptions.IgnoreCase));

            if (firstMatch != null)
            {
                if (firstMatch.Label != null)
                {
                    config.Label.Clear();
                    config.Label.AddRange(firstMatch.Label);
                }

                if (firstMatch.Metadata != null)
                {
                    config.Metadata.Clear();
                    config.Metadata.AddRange(firstMatch.Metadata);
                }
            }
        }
コード例 #2
0
        private void PopulateHeight(VersionContext context)
        {
            // Get the state of this tree to compare for diffs
            var tipTree = context.Repository.Head.Tip.Tree;

            // Initialise count - The current commit counts, include offset
            var height = 1 + context.Configuration.OffSet;

            // skip the first commit as that is our baseline
            var commits = GetReachableCommits(context.Repository).Skip(1).GetEnumerator();

            while (commits.MoveNext())
            {
                // Get the current tree
                var next = commits.Current.Tree;

                // Perform a diff
                var diff = context.Repository.Diff.Compare <TreeChanges>(next, tipTree);

                // If a change to the file is found, stop counting
                if (HasVersionChange(diff, commits.Current, context))
                {
                    break;
                }

                // Increment height
                height++;
            }

            context.Result.Height = height;
        }
コード例 #3
0
        private static bool HasVersionChange(
            TreeChanges diff,
            Commit commit,
            VersionContext context)
        {
            if (diff.Any(d => d.Path == Constants.VersionFileName))
            {
                var commitConfig = GetConfiguration(commit, context);
                return(commitConfig != null && !_comparer.Equals(context.Configuration, commitConfig));
            }

            return(false);
        }
コード例 #4
0
        private static SVM.Configuration GetConfiguration(Commit commit, VersionContext context)
        {
            var gitObj = commit?.Tree[Constants.VersionFileName]?.Target;

            if (gitObj == null)
            {
                return(null);
            }

            var config = Read((gitObj as Blob).GetContentText());

            ApplyConfigOverrides(config, context);
            return(config);
        }