private static bool IsCommitIdMismatch(Version version, VersionOptions versionOptions, Commit commit) { Requires.NotNull(version, nameof(version)); Requires.NotNull(versionOptions, nameof(versionOptions)); Requires.NotNull(commit, nameof(commit)); // The version.Revision MAY represent the first 2 bytes of the git commit ID, but not if 3 integers were specified in version.json, // since in that case the 4th integer is the version height. But we won't know till we read the version.json file, so for now, var position = versionOptions.GitCommitIdPosition; if (position.HasValue && position.Value <= SemanticVersion.Position.Revision) { // prepare for it to be the commit ID. // The revision is a 16-bit unsigned integer, but is not allowed to be 0xffff. // So if the value is 0xfffe, consider that the actual last bit is insignificant // since the original git commit ID could have been either 0xffff or 0xfffe. var expectedCommitIdLeadingValue = SemanticVersion.ReadVersionPosition(version, position.Value); if (expectedCommitIdLeadingValue != -1) { ushort objectIdLeadingValue = (ushort)expectedCommitIdLeadingValue; ushort objectIdMask = (ushort)(objectIdLeadingValue == MaximumBuildNumberOrRevisionComponent ? 0xfffe : 0xffff); // Accept a big endian match or a little endian match. // Nerdbank.GitVersioning up to v3.4 would produce versions based on the endianness of the CPU it ran on (typically little endian). // Starting with v3.5, it deterministically used big endian. In order for `nbgv get-commits` to match on versions computed before and after the change, // we match on either endian setting. return(!(commit.Id.StartsWith(objectIdLeadingValue, bigEndian: true, objectIdMask) || commit.Id.StartsWith(objectIdLeadingValue, bigEndian: false, objectIdMask))); } } // It's not a mismatch, since for this commit, the commit ID wasn't recorded in the 4-integer version. return(false); }
private static bool CommitMatchesVersion(this Commit commit, Version expectedVersion, SemanticVersion.Position comparisonPrecision, GitWalkTracker tracker) { Requires.NotNull(commit, nameof(commit)); Requires.NotNull(expectedVersion, nameof(expectedVersion)); var commitVersionData = tracker.GetVersion(commit); var semVerFromFile = commitVersionData?.Version; if (semVerFromFile is null) { return(false); } for (SemanticVersion.Position position = SemanticVersion.Position.Major; position <= comparisonPrecision; position++) { int expectedValue = SemanticVersion.ReadVersionPosition(expectedVersion, position); int actualValue = SemanticVersion.ReadVersionPosition(semVerFromFile.Version, position); if (expectedValue != actualValue) { return(false); } } return(true); }
private static bool IsCommitIdMismatch(Version version, VersionOptions versionOptions, Commit commit) { Requires.NotNull(version, nameof(version)); Requires.NotNull(versionOptions, nameof(versionOptions)); Requires.NotNull(commit, nameof(commit)); // The version.Revision MAY represent the first 2 bytes of the git commit ID, but not if 3 integers were specified in version.json, // since in that case the 4th integer is the version height. But we won't know till we read the version.json file, so for now, var position = versionOptions.GitCommitIdPosition; if (position.HasValue && position.Value <= SemanticVersion.Position.Revision) { // prepare for it to be the commit ID. // The revision is a 16-bit unsigned integer, but is not allowed to be 0xffff. // So if the value is 0xfffe, consider that the actual last bit is insignificant // since the original git commit ID could have been either 0xffff or 0xfffe. var expectedCommitIdLeadingValue = SemanticVersion.ReadVersionPosition(version, position.Value); if (expectedCommitIdLeadingValue != -1) { ushort objectIdLeadingValue = (ushort)expectedCommitIdLeadingValue; ushort objectIdMask = (ushort)(objectIdLeadingValue == MaximumBuildNumberOrRevisionComponent ? 0xfffe : 0xffff); return(!commit.Id.StartsWith(objectIdLeadingValue, objectIdMask)); } } // It's not a mismatch, since for this commit, the commit ID wasn't recorded in the 4-integer version. return(false); }
private static bool IsVersionHeightMismatch(Version version, VersionOptions versionOptions, Commit commit, GitWalkTracker tracker) { Requires.NotNull(version, nameof(version)); Requires.NotNull(versionOptions, nameof(versionOptions)); Requires.NotNull(commit, nameof(commit)); // The version.Build or version.Revision MAY represent the version height. var position = versionOptions.VersionHeightPosition; if (position.HasValue && position.Value <= SemanticVersion.Position.Revision) { int expectedVersionHeight = SemanticVersion.ReadVersionPosition(version, position.Value); var actualVersionOffset = versionOptions.VersionHeightOffsetOrDefault; var actualVersionHeight = GetCommitHeight(commit, tracker, c => CommitMatchesVersion(c, version, position.Value - 1, tracker)); return(expectedVersionHeight != actualVersionHeight + actualVersionOffset); } // It's not a mismatch, since for this commit, the version height wasn't recorded in the 4-integer version. return(false); }