Discovers existing tags in the repository, resolves them by applying ReleaseTagVersion.DefinitionStrength, detects some of the possible inconsistencies and provide a GetVersionInfo to retrieve commit information.
示例#1
0
        internal CommitVersionInfo( 
            TagCollector tagCollector, 
            string commitSha, 
            IFullTagCommit thisCommit, 
            IFullTagCommit contentCommit, 
            CommitVersionInfo prevCommitParent, 
            CommitVersionInfo prevMaxCommitParent )
        {
            Debug.Assert( thisCommit == null || thisCommit.ThisTag != null );
            Debug.Assert( thisCommit == null || contentCommit == thisCommit, "this commit exists => content commit is this commit" );
            _tagCollector = tagCollector;
            _commitSha = commitSha;
            _thisCommit = thisCommit;
            _contentCommit = contentCommit;

            if( prevCommitParent != null )
            {
                _prevCommit = prevCommitParent._thisCommit != null ? prevCommitParent : prevCommitParent._prevCommit;
            }

            if( prevMaxCommitParent != null )
            {
                Debug.Assert( prevMaxCommitParent.PreviousMaxTag == null || prevMaxCommitParent._prevMaxCommit != null );
                if( prevMaxCommitParent._prevMaxCommit == null || prevMaxCommitParent.BestContentTag > prevMaxCommitParent.PreviousMaxTag )
                {
                    Debug.Assert( prevMaxCommitParent.MaxTag == prevMaxCommitParent.BestContentTag );
                    _prevMaxCommit = prevMaxCommitParent;
                    _maxCommitDepth = 1;
                }
                else
                {
                    Debug.Assert( prevMaxCommitParent.MaxTag == prevMaxCommitParent.PreviousMaxTag );
                    _prevMaxCommit = prevMaxCommitParent._prevMaxCommit;
                    _maxCommitDepth = prevMaxCommitParent._maxCommitDepth + 1;
                }
                Debug.Assert( _prevMaxCommit != null );
            }
            _maxCommit = BestContentTag >= PreviousMaxTag 
                            ? (_contentCommit != null ? _contentCommit.BestCommit : null) 
                            : (_prevMaxCommit._contentCommit != null ? _prevMaxCommit._contentCommit.BestCommit : null);
        }
示例#2
0
        internal CommitVersionInfo(
            TagCollector tagCollector,
            string commitSha,
            IFullTagCommit thisCommit,
            IFullTagCommit contentCommit,
            CommitVersionInfo prevCommitParent,
            CommitVersionInfo prevMaxCommitParent)
        {
            Debug.Assert(thisCommit == null || thisCommit.ThisTag != null);
            Debug.Assert(thisCommit == null || contentCommit == thisCommit, "this commit exists => content commit is this commit");
            _tagCollector  = tagCollector;
            _commitSha     = commitSha;
            _thisCommit    = thisCommit;
            _contentCommit = contentCommit;

            if (prevCommitParent != null)
            {
                _prevCommit = prevCommitParent._thisCommit != null ? prevCommitParent : prevCommitParent._prevCommit;
            }

            if (prevMaxCommitParent != null)
            {
                Debug.Assert(prevMaxCommitParent.PreviousMaxTag == null || prevMaxCommitParent._prevMaxCommit != null);
                if (prevMaxCommitParent._prevMaxCommit == null || prevMaxCommitParent.BestContentTag > prevMaxCommitParent.PreviousMaxTag)
                {
                    Debug.Assert(prevMaxCommitParent.MaxTag == prevMaxCommitParent.BestContentTag);
                    _prevMaxCommit  = prevMaxCommitParent;
                    _maxCommitDepth = 1;
                }
                else
                {
                    Debug.Assert(prevMaxCommitParent.MaxTag == prevMaxCommitParent.PreviousMaxTag);
                    _prevMaxCommit  = prevMaxCommitParent._prevMaxCommit;
                    _maxCommitDepth = prevMaxCommitParent._maxCommitDepth + 1;
                }
                Debug.Assert(_prevMaxCommit != null);
            }
            _maxCommit = BestContentTag >= PreviousMaxTag
                            ? (_contentCommit != null ? _contentCommit.BestCommit : null)
                            : (_prevMaxCommit._contentCommit != null ? _prevMaxCommit._contentCommit.BestCommit : null);
        }
 RepositoryInfo( Repository r, RepositoryInfoOptions options, string gitSolutionDir )
     : this()
 {
     if( options == null ) options = new RepositoryInfoOptions();
     Options = options;
     if( r == null ) RepositoryError = "No Git repository.";
     else
     {
         Debug.Assert( gitSolutionDir != null && gitSolutionDir[gitSolutionDir.Length-1] == Path.DirectorySeparatorChar );
         GitSolutionDirectory = gitSolutionDir;
         Commit commit;
         CIBranchVersionMode ciVersionMode;
         string ciBuildName;
         RepositoryError = TryFindCommit( options, r, out commit, out ciVersionMode, out ciBuildName );
         Debug.Assert( (ciVersionMode != CIBranchVersionMode.None) == (ciBuildName != null) );
         if( commit != null )
         {
             CommitSha = commit.Sha;
             CommitDateUtc = commit.Author.When.ToUniversalTime().DateTime;
             IsDirtyExplanations = ComputeIsDirty( r, commit, options );
             if( !IsDirty || options.IgnoreDirtyWorkingFolder )
             {
                 StringBuilder errors = new StringBuilder();
                 TagCollector collector = new TagCollector( errors,
                                                             r,
                                                             options.StartingVersionForCSemVer,
                                                             c => c.Sha == CommitSha ? ReleaseTagParsingMode.RaiseErrorOnMalformedTag : ReleaseTagParsingMode.IgnoreMalformedTag,
                                                             options.OverriddenTags );
                 if( errors.Length == 0 )
                 {
                     CommitVersionInfo info = collector.GetVersionInfo( commit );
                     ExistingVersions = collector.ExistingVersions.TagCommits;
                     PossibleVersions = info.PossibleVersions;
                     PossibleVersionsStrict = info.PossibleVersionsStrict;
                     PreviousRelease = info.PreviousCommit;
                     PreviousMaxRelease = info.PreviousMaxCommit;
                     if( info.ThisCommit != null )
                     {
                         bool strictMode = options.PossibleVersionsMode.IsStrict();
                         var possibleSet = strictMode ? info.PossibleVersionsStrict : info.PossibleVersions;
                         if( possibleSet.Contains( info.ThisCommit.ThisTag ) )
                         {
                             ValidReleaseTag = info.ThisCommit.ThisTag;
                         }
                         else
                         {
                             ReleaseTagIsNotPossibleError = true;
                             errors.Append( "Release tag '" )
                                    .Append( info.ThisCommit.ThisTag.OriginalTagText )
                                    .Append( "' is not valid here. Valid tags are: " )
                                    .Append( string.Join( ", ", possibleSet ) )
                                    .AppendLine();
                             if( strictMode && info.PossibleVersions.Contains( info.ThisCommit.ThisTag ))
                             {
                                 if( options.PossibleVersionsMode == PossibleVersionsMode.Default )
                                 {
                                     errors.Append( "Consider setting <PossibleVersionsMode>AllSuccessors</PossibleVersionsMode> in RepositoryInfo.xml to allow this version." );
                                 }
                                 else
                                 {
                                     errors.Append( "Current <PossibleVersionsMode>Restricted</PossibleVersionsMode> in RepositoryInfo.xml forbids this version." );
                                 }
                             }
                         }
                     }
                     else
                     {
                         if( ciBuildName != null )
                         {
                             CIRelease = CIReleaseInfo.Create( commit, ciVersionMode, ciBuildName, errors, info );
                         }
                     }
                 }
                 if( errors.Length > 0 ) SetError( errors, out ReleaseTagErrorLines, out ReleaseTagErrorText );
             }
         }
     }
 }
        /// <summary>
        /// Initializes a new <see cref="RepositoryInfo"/> on a <see cref="Repository"/>.
        /// </summary>
        /// <param name="r">The rpository (can be invalid and even null).</param>
        /// <param name="options">Optional options.</param>
        public RepositoryInfo(Repository r, RepositoryInfoOptions options = null)
        {
            Options       = options ?? new RepositoryInfoOptions();
            CommitDateUtc = InformationalVersion.ZeroCommitDate;
            if (r == null)
            {
                RepositoryError = "No Git repository.";
            }
            else
            {
                Commit commit;
                CIBranchVersionMode ciVersionMode;
                string ciBuildName;
                RepositoryError = TryFindCommit(options, r, out commit, out ciVersionMode, out ciBuildName);
                Debug.Assert((ciVersionMode != CIBranchVersionMode.None) == (ciBuildName != null));
                if (commit != null)
                {
                    CommitSha           = commit.Sha;
                    CommitDateUtc       = commit.Author.When.UtcDateTime;
                    IsDirtyExplanations = ComputeIsDirty(r, commit, options);
                    if (!IsDirty || options.IgnoreDirtyWorkingFolder)
                    {
                        StringBuilder errors    = new StringBuilder();
                        TagCollector  collector = new TagCollector(errors,
                                                                   r,
                                                                   options.StartingVersionForCSemVer,
                                                                   options.OverriddenTags,
                                                                   options.SingleMajor);
                        if (errors.Length == 0)
                        {
                            ExistingVersions = collector.ExistingVersions.TagCommits;

                            var info = collector.GetCommitInfo(commit);
                            Debug.Assert(info != null);

                            CommitInfo = info;

                            var rawPossible = info.PossibleVersions;
                            IEnumerable <CSVersion> possibles = rawPossible;
                            if (options.OnlyPatch)
                            {
                                possibles = possibles.Where(v => v.IsPatch);
                            }
                            if (options.SingleMajor.HasValue)
                            {
                                possibles = possibles.Where(v => v.Major == options.SingleMajor.Value);
                            }
                            PossibleVersions = possibles != rawPossible?possibles.ToList() : rawPossible;

                            var rawNextPossible = info.NextPossibleVersions;
                            IEnumerable <CSVersion> nextPossibles = rawNextPossible;
                            if (options.OnlyPatch)
                            {
                                nextPossibles = nextPossibles.Where(v => v.IsPatch);
                            }
                            if (options.SingleMajor.HasValue)
                            {
                                nextPossibles = nextPossibles.Where(v => v.Major == options.SingleMajor.Value);
                            }
                            NextPossibleVersions = nextPossibles != rawNextPossible?nextPossibles.ToList() : rawNextPossible;

                            var thisCommit = info.BasicInfo?.UnfilteredThisCommit;
                            if (info.BasicInfo?.BestCommit?.ThisTag > thisCommit?.ThisTag)
                            {
                                BetterExistingVersion = info.BasicInfo.BestCommit;
                            }
                            if (thisCommit != null)
                            {
                                if (PossibleVersions.Contains(thisCommit.ThisTag))
                                {
                                    ValidReleaseTag = thisCommit.ThisTag;
                                }
                                else
                                {
                                    ReleaseTagIsNotPossibleError = true;
                                    errors.Append("Release tag '")
                                    .Append(thisCommit.ThisTag.ParsedText)
                                    .AppendLine("' is not valid here. ");
                                    errors.Append("Valid tags are: ")
                                    .Append(string.Join(", ", PossibleVersions))
                                    .AppendLine();
                                    if (PossibleVersions != rawPossible &&
                                        rawPossible.Contains(thisCommit.ThisTag))
                                    {
                                        errors.AppendLine("Note: this version is invalid because of <SingleMajor> or <OnlyPatch> setting in RepositoryInfo.xml.");
                                    }
                                }
                            }
                            else
                            {
                                // There is no release tag on the commit point.
                                if (ciBuildName != null)
                                {
                                    CIRelease = CIReleaseInfo.Create(commit, ciVersionMode, ciBuildName, errors, info.BasicInfo);
                                }
                            }
                        }
                        if (errors.Length > 0)
                        {
                            ReleaseTagError = errors.ToString();
                        }
                    }

                    // Conclusion:
                    if (CIRelease != null)
                    {
                        //ContentOrFinalNuGetVersion =
                        FinalNuGetVersion = CIRelease.BuildVersionNuGet;
                        FinalSemVersion   = CIRelease.BuildVersion;
                    }
                    else if (ValidReleaseTag != null)
                    {
                        FinalNuGetVersion = SVersion.Parse(ValidReleaseTag.ToString(CSVersionFormat.NuGetPackage), false);
                        FinalSemVersion   = ValidReleaseTag;
                    }
                }
            }
            // Handles FinalInformationalVersion and SVersion.ZeroVersion for versions if needed.
            if (FinalSemVersion == null)
            {
                FinalSemVersion           = SVersion.ZeroVersion;
                FinalNuGetVersion         = SVersion.ZeroVersion;
                FinalInformationalVersion = InformationalVersion.ZeroInformationalVersion;
            }
            else
            {
                FinalInformationalVersion = InformationalVersion.BuildInformationalVersion(FinalSemVersion.NormalizedText, FinalNuGetVersion.NormalizedText, CommitSha, CommitDateUtc);
            }
        }
示例#5
0
 public FilteredView(TagCollector c, CSVersion excluded)
 {
     _collector = c;
     _excluded  = excluded;
     _cache     = new Dictionary <string, BasicCommitInfo>();
 }
示例#6
0
 RepositoryInfo(Repository r, RepositoryInfoOptions options, string gitSolutionDir)
     : this()
 {
     if (options == null)
     {
         options = new RepositoryInfoOptions();
     }
     Options = options;
     if (r == null)
     {
         RepositoryError = "No Git repository.";
     }
     else
     {
         Debug.Assert(gitSolutionDir != null && gitSolutionDir[gitSolutionDir.Length - 1] == Path.DirectorySeparatorChar);
         GitSolutionDirectory = gitSolutionDir;
         Commit commit;
         CIBranchVersionMode ciVersionMode;
         string ciBuildName;
         RepositoryError = TryFindCommit(options, r, out commit, out ciVersionMode, out ciBuildName);
         Debug.Assert((ciVersionMode != CIBranchVersionMode.None) == (ciBuildName != null));
         if (commit != null)
         {
             CommitSha           = commit.Sha;
             CommitDateUtc       = commit.Author.When.ToUniversalTime().DateTime;
             IsDirtyExplanations = ComputeIsDirty(r, commit, options);
             if (!IsDirty || options.IgnoreDirtyWorkingFolder)
             {
                 StringBuilder errors    = new StringBuilder();
                 TagCollector  collector = new TagCollector(errors,
                                                            r,
                                                            options.StartingVersionForCSemVer,
                                                            c => c.Sha == CommitSha ? ReleaseTagParsingMode.RaiseErrorOnMalformedTag : ReleaseTagParsingMode.IgnoreMalformedTag,
                                                            options.OverriddenTags);
                 if (errors.Length == 0)
                 {
                     CommitVersionInfo info = collector.GetVersionInfo(commit);
                     ExistingVersions       = collector.ExistingVersions.TagCommits;
                     PossibleVersions       = info.PossibleVersions;
                     PossibleVersionsStrict = info.PossibleVersionsStrict;
                     PreviousRelease        = info.PreviousCommit;
                     PreviousMaxRelease     = info.PreviousMaxCommit;
                     if (info.ThisCommit != null)
                     {
                         bool strictMode  = options.PossibleVersionsMode.IsStrict();
                         var  possibleSet = strictMode ? info.PossibleVersionsStrict : info.PossibleVersions;
                         if (possibleSet.Contains(info.ThisCommit.ThisTag))
                         {
                             ValidReleaseTag = info.ThisCommit.ThisTag;
                         }
                         else
                         {
                             ReleaseTagIsNotPossibleError = true;
                             errors.Append("Release tag '")
                             .Append(info.ThisCommit.ThisTag.OriginalTagText)
                             .Append("' is not valid here. Valid tags are: ")
                             .Append(string.Join(", ", possibleSet))
                             .AppendLine();
                             if (strictMode && info.PossibleVersions.Contains(info.ThisCommit.ThisTag))
                             {
                                 if (options.PossibleVersionsMode == PossibleVersionsMode.Default)
                                 {
                                     errors.Append("Consider setting <PossibleVersionsMode>AllSuccessors</PossibleVersionsMode> in RepositoryInfo.xml to allow this version.");
                                 }
                                 else
                                 {
                                     errors.Append("Current <PossibleVersionsMode>Restricted</PossibleVersionsMode> in RepositoryInfo.xml forbids this version.");
                                 }
                             }
                         }
                     }
                     else
                     {
                         if (ciBuildName != null)
                         {
                             CIRelease = CIReleaseInfo.Create(commit, ciVersionMode, ciBuildName, errors, info);
                         }
                     }
                 }
                 if (errors.Length > 0)
                 {
                     SetError(errors, out ReleaseTagErrorLines, out ReleaseTagErrorText);
                 }
             }
         }
     }
 }