internal BasicCommitInfo(ITagCommit thisCommit, ITagCommit best, BasicCommitInfo parent)
 {
     UnfilteredThisCommit = thisCommit;
     if (best != null)
     {
         BestCommit = best;
         if (parent != null)
         {
             var maxBelow = parent.MaxCommit;
             if (best.ThisTag > maxBelow.ThisTag)
             {
                 BelowDepth = 0;
             }
             else
             {
                 BelowDepth      = parent.BelowDepth + 1;
                 BestCommitBelow = maxBelow;
             }
         }
     }
     else
     {
         Debug.Assert(parent != null, "Not both can be null.");
         BelowDepth      = parent.BelowDepth + 1;
         BestCommitBelow = parent.MaxCommit;
     }
     Debug.Assert(MaxCommit != null);
 }
示例#2
0
            public BasicCommitInfo GetInfo(Commit c)
            {
                string sha = c.Sha;

                if (_cache.TryGetValue(sha, out var d))
                {
                    return(d);
                }
                TagCommit  commit = _collector.GetCommit(sha);
                ITagCommit best;

                if (commit != null)
                {
                    best = commit.GetBestCommitExcept(_excluded);
                }
                else
                {
                    TagCommit content = _collector.GetCommit(c.Tree.Sha);
                    best = content?.GetBestCommitExcept(_excluded);
                }
                BasicCommitInfo p = ReadParents(c);

                if (best != null || p != null)
                {
                    d = new BasicCommitInfo(commit, best, p);
                }
                _cache.Add(sha, d);
                return(d);
            }
示例#3
0
 internal CommitInfo(
     string sha,
     BasicCommitInfo basic,
     IReadOnlyList <CSVersion> possibleVersions,
     IReadOnlyList <CSVersion> nextPossibleVersions)
 {
     CommitSha            = sha;
     BasicInfo            = basic;
     NextPossibleVersions = nextPossibleVersions;
     PossibleVersions     = possibleVersions;
 }
示例#4
0
        internal static CIReleaseInfo Create(
            Commit commit,
            CIBranchVersionMode ciVersionMode,
            string ciBuildName,
            StringBuilder errors,
            BasicCommitInfo info)
        {
            var       actualBaseTag = info?.MaxCommit.ThisTag;
            CSVersion ciBaseTag = actualBaseTag ?? CSVersion.VeryFirstVersion;
            SVersion  ciBuildVersionNuGet = null, ciBuildVersion = null;

            // If there is no base release found, we fall back to ZeroTimedBased mode.
            if (ciVersionMode == CIBranchVersionMode.ZeroTimed || actualBaseTag == null)
            {
                DateTime timeRelease = commit.Committer.When.ToUniversalTime().UtcDateTime;
                string   vS          = CIBuildDescriptor.CreateSemVerZeroTimed(ciBuildName, timeRelease);
                string   vN          = CIBuildDescriptor.CreateShortFormZeroTimed(ciBuildName, timeRelease);
                if (actualBaseTag != null)
                {
                    string buildMetaData = "+v" + actualBaseTag;
                    vS += buildMetaData;
                    vN += buildMetaData;
                }
                ciBuildVersion      = SVersion.Parse(vS);
                ciBuildVersionNuGet = SVersion.Parse(vN, false);
                return(new CIReleaseInfo(ciBaseTag, 0, ciBuildVersion, ciBuildVersionNuGet, true));
            }
            Debug.Assert(ciVersionMode == CIBranchVersionMode.LastReleaseBased && actualBaseTag != null);
            CIBuildDescriptor ci = new CIBuildDescriptor {
                BranchName = ciBuildName, BuildIndex = info.BelowDepth
            };

            if (!ci.IsValidForShortForm)
            {
                errors.AppendLine("Due to ShortForm (NuGet V2 compliance) limitation, the branch name must not be longer than 8 characters. ");
                errors.Append("Adds a VersionName attribute to the branch element in RepositoryInfo.xml with a shorter name: ")
                .AppendLine()
                .Append($@"<Branch Name=""{ci.BranchName}"" VersionName=""{ci.BranchName.Substring( 0, 8 )}"" ... />.")
                .AppendLine();
            }
            else
            {
                ciBuildVersion      = SVersion.Parse(actualBaseTag.ToString(CSVersionFormat.Normalized, ci));
                ciBuildVersionNuGet = SVersion.Parse(actualBaseTag.ToString(CSVersionFormat.NuGetPackage, ci), false);
            }
            Debug.Assert(ciBuildVersion == null || errors.Length == 0);
            return(ciBuildVersion != null
                    ? new CIReleaseInfo(ciBaseTag, info.BelowDepth, ciBuildVersion, ciBuildVersionNuGet, false)
                    : null);
        }
示例#5
0
            BasicCommitInfo ReadParents(Commit c)
            {
                BasicCommitInfo current = null;

                foreach (var p in c.Parents)
                {
                    var d = GetInfo(p);
                    if (current == null || (d != null && d.IsBetterThan(current)))
                    {
                        current = d;
                    }
                }
                return(current);
            }
        internal bool IsBetterThan(BasicCommitInfo other)
        {
            int cmp = MaxCommit.ThisTag.CompareTo(other.MaxCommit.ThisTag);

            return(cmp == 0 ? BelowDepth > other.BelowDepth : cmp > 0);
        }