/// <summary> /// Computes whether the given version belongs to the set of predecessors. /// This currently does no more than calling <see cref="GetDirectSuccessors(bool)"/> and checking the existence of /// the given <paramref name="previous"/> version. If this need an optimized implementation this can be done but /// for the moment, this is the safest (and easiest) way to do this. /// </summary> /// <param name="previous">Previous version. Can be null.</param> /// <returns>True if previous is actually a direct predecessor.</returns> public bool IsDirectPredecessor(CSVersion?previous) { if (!IsValid) { return(false); } long num = _orderedVersion.Number; if (previous == null) { return(FirstPossibleVersions.Contains(this)); } if (previous._orderedVersion.Number >= num) { return(false); } if (previous._orderedVersion.Number == num - 1L) { return(true); } // Major bump greater than 1: previous can not be a direct predecessor. if (Major > previous.Major + 1) { return(false); } foreach (var succ in previous.GetDirectSuccessors()) { var delta = succ._orderedVersion.Number - _orderedVersion.Number; if (delta == 0) { return(true); } if (delta > 0) { break; } } return(false); }
/// <summary> /// Computes whether the given version belongs to the set or predecessors. /// </summary> /// <param name="previous">Previous version. Can be null.</param> /// <returns>True if previous is actually a direct predecessor.</returns> public bool IsDirectPredecessor(ReleaseTagVersion previous) { if (!IsValid) { return(false); } long num = _orderedVersion.Number; if (previous == null) { return(FirstPossibleVersions.Contains(this)); } if (previous._orderedVersion.Number >= num) { return(false); } if (previous._orderedVersion.Number == num - 1L) { return(true); } // Major bump greater than 1: previous can not be a direct predecessor. if (Major > previous.Major + 1) { return(false); } // Major bump of 1: if we are the first major (Major.0.0) or one of its first prerelases (Major.0.0-alpha or Major.0.0-rc), this is fine. if (Major != previous.Major) { return(Minor == 0 && Patch == 0 && PreReleaseNumber == 0 && PreReleasePatch == 0); } Debug.Assert(Major == previous.Major); // Minor bump greater than 1: previous can not be a direct predecessor. if (Minor > previous.Minor + 1) { return(false); } // Minor bump of 1: if we are the first minor (Major.Minor.0) or one of its first prerelases (Major.Minor.0-alpha or Major.Minor.0-rc), this is fine. if (Minor != previous.Minor) { return(Patch == 0 && PreReleaseNumber == 0 && PreReleasePatch == 0); } Debug.Assert(Major == previous.Major && Minor == previous.Minor); // Patch bump greater than 1: previous can not be a direct predecessor. if (Patch > previous.Patch + 1) { return(false); } // Patch bump of 1: // - if previous is a prelease, it can not be a direct predecessor (4.3.2 nor any 4.3.2-* pre releases can be reached from any 4.3.1-* versions). // - if we are the first minor (Major.Minor.Patch) or one of its first prerelases (Major.Minor.Patch-alpha or Major.Minor.Patch-rc), this is fine: // a 4.3.1 can give bearth to 4.3.2 or 4.3.2-alpha or -rc. if (Patch != previous.Patch) { if (previous.IsPreRelease) { return(false); } return(PreReleaseNumber == 0 && PreReleasePatch == 0); } Debug.Assert(Major == previous.Major && Minor == previous.Minor && Patch == previous.Patch); Debug.Assert(previous.IsPreRelease, "if previous was not a prerelease, this and previous would be equal."); // If this is not a prerelease, it is fine: one can always bump from a prerelease version to its release version. if (!IsPreRelease) { return(true); } Debug.Assert(IsPreRelease && previous.IsPreRelease, "Both are now necessarily pre releases."); Debug.Assert(PreReleaseNameIdx >= previous.PreReleaseNameIdx, "This pre release name is grater or the same as the previous one (otherwise previous would be greater than this: this has been handled at the beginning of this function)."); // If we are a fix, there is one alternative: // 1 - the previous is the one just before us. // 2 - the previous is not the one just before us. // Case 1 has been handled at the top of this function (oredered version + 1): if this is a fix, previous can not be a direct predecessor here. if (PreReleasePatch > 0) { return(false); } // This is not a fix. // If this is a numbered prerelease, the previous must have the same PreReleaseName. if (PreReleaseNumber > 0) { if (previous.PreReleaseNameIdx == PreReleaseNameIdx) { Debug.Assert(PreReleaseNumber > previous.PreReleaseNumber, "Otherwise previous would be greater than this: this has been handled at the beginning of this function."); return(true); } return(false); } // This is not a fix nor a numbered release: by design, this is a direct predecesor (bump from a prerelease name to a greater one). return(true); }