Skip to content

Commit

Permalink
fixup! GitVersion: use Scalar's parsing logic
Browse files Browse the repository at this point in the history
  • Loading branch information
derrickstolee committed Feb 2, 2021
1 parent bd77b70 commit e808c51
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 17 deletions.
2 changes: 1 addition & 1 deletion GVFS/GVFS.Build/GenerateGitVersionConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ namespace GVFS.Common
{{
public static partial class GVFSConstants
{{
public static readonly GitVersion BuiltWithGitVersion = new GitVersion({0}, {1}, {2}, ""{3}"", {4}, {5});
public static readonly GitVersion SupportedGitVersion = new GitVersion({0}, {1}, {2}, ""{3}"", {4}, {5});
}}
}}",
version.Major,
Expand Down
20 changes: 4 additions & 16 deletions GVFS/GVFS.Common/Git/GitVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ namespace GVFS.Common.Git
{
public class GitVersion
{
public GitVersion(int major, int minor, int build, string platform = null, int revision = 0, int minorRevision = 0, int? rc = null)
public GitVersion(int major, int minor, int build, string platform = null, int revision = 0, int minorRevision = 0)
{
this.Major = major;
this.Minor = minor;
this.Build = build;
this.ReleaseCandidate = rc;
this.Platform = platform;
this.Revision = revision;
this.MinorRevision = minorRevision;
Expand All @@ -19,7 +18,6 @@ public GitVersion(int major, int minor, int build, string platform = null, int r
public int Major { get; private set; }
public int Minor { get; private set; }
public int Build { get; private set; }
public int? ReleaseCandidate { get; private set; }
public string Platform { get; private set; }
public int Revision { get; private set; }
public int MinorRevision { get; private set; }
Expand Down Expand Up @@ -64,7 +62,6 @@ public static bool TryParseVersion(string input, out GitVersion version)
version = null;

int major, minor, build, revision = 0, minorRevision = 0;
int? rc = null;
string platform = null;

if (string.IsNullOrWhiteSpace(input))
Expand All @@ -76,11 +73,10 @@ public static bool TryParseVersion(string input, out GitVersion version)
int numComponents = parsedComponents.Length;

// We minimally accept the official Git version number format which
// consists of three components: "major.minor.build" or "major.minor.build-rc<N>".
// consists of three components: "major.minor.build".
//
// The other supported formats are the Git for Windows and Microsoft Git
// formats which look like: "major.minor.build.platform.revision.minorRevision"
// or "major.minor.build-rc<N>.platform.revision.minorRevision".
// 0 1 2 3 4 5
// len 1 2 3 4 5 6
//
Expand All @@ -101,16 +97,8 @@ public static bool TryParseVersion(string input, out GitVersion version)
return false;
}

// Check if this is a release candidate version and if so split
// it from the build number.
string[] buildParts = parsedComponents[2].Split("-rc", StringSplitOptions.RemoveEmptyEntries);
if (buildParts.Length > 1 && TryParseComponent(buildParts[1], out int rcInt))
{
rc = rcInt;
}

// Build number
if (!TryParseComponent(buildParts[0], out build))
if (!TryParseComponent(parsedComponents[2], out build))
{
return false;
}
Expand All @@ -133,7 +121,7 @@ public static bool TryParseVersion(string input, out GitVersion version)
minorRevision = 0;
}

version = new GitVersion(major, minor, build, platform, revision, minorRevision, rc);
version = new GitVersion(major, minor, build, platform, revision, minorRevision);
return true;
}

Expand Down

0 comments on commit e808c51

Please sign in to comment.