<commit_before>package gps

import (
	"sort"

	"github.com/Masterminds/semver"
)

// Version represents one of the different types of versions used by gps.
//
// Version composes Constraint, because all versions can be used as a constraint
// (where they allow one, and only one, version - themselves), but constraints
// are not necessarily discrete versions.
//
// Version is an interface, but it contains private methods, which restricts it
// to gps's own internal implementations. We do this for the confluence of
// two reasons: the implementation of Versions is complete (there is no case in
// which we'd need other types), and the implementation relies on type magic
// under the hood, which would be unsafe to do if other dynamic types could be
// hiding behind the interface.
type Version interface {
	Constraint

	// Indicates the type of version - Revision, Branch, Version, or Semver
	Type() string
}

// PairedVersion represents a normal Version, but paired with its corresponding,
// underlying Revision.
type PairedVersion interface {
	Version

	// Underlying returns the immutable Revision that identifies this Version.
	Underlying() Revision

	// Unpair returns the surface-level UnpairedVersion that half of the pair.
	//
	// It does NOT modify the original PairedVersion
	Unpair() UnpairedVersion

	// Ensures it is impossible to be both a PairedVersion and an
	// UnpairedVersion
	_pair(int)
}

// UnpairedVersion represents a normal Version, with a method for creating a
// VersionPair by indicating the version's corresponding, underlying Revision.
type UnpairedVersion interface {
	Version
	// Is takes the underlying Revision that this UnpairedVersion corresponds
	// to and unites them into a PairedVersion.
	Is(Revision) PairedVersion
	// Ensures it is impossible to be both a PairedVersion and an
	// UnpairedVersion
	_pair(bool)
}

// types are weird
func (branchVersion) _private()  {}
func (branchVersion) _pair(bool) {}
func (plainVersion) _private()   {}
func (plainVersion) _pair(bool)  {}
func (semVersion) _private()     {}
func (semVersion) _pair(bool)    {}
func (versionPair) _private()    {}
func (versionPair) _pair(int)    {}
func (Revision) _private()       {}

// NewBranch creates a new Version to represent a floating version (in
// general, a branch).
func NewBranch(body string) UnpairedVersion {
	return branchVersion{
		name: body,
		// We always set isDefault to false here, because the property is
		// specifically designed to be internal-only: only the SourceManager
		// gets to mark it. This is OK because nothing that client code is
		// responsible for needs to care about has to touch it it.
		//
		// TODO(sdboyer) ...maybe. this just ugly.
		isDefault: false,
	}
}

func newDefaultBranch(body string) UnpairedVersion {
	return branchVersion{
		name:      body,
		isDefault: true,
	}
}

// NewVersion creates a Semver-typed Version if the provided version string is
// valid semver, and a plain/non-semver version if not.
func NewVersion(body string) UnpairedVersion {
	sv, err := semver.NewVersion(body)

	if err != nil {
		return plainVersion(body)
	}
	return semVersion{sv: sv}
}

// A Revision represents an immutable versioning identifier.
type Revision string

// String converts the Revision back into a string.
func (r Revision) String() string {
	return string(r)
}

// Type indicates the type of version - for revisions, "rev".
func (r Revision) Type() string {
	return "rev"
}

// Matches is the Revision acting as a constraint; it checks to see if the provided
// version is the same Revision as itself.
func (r Revision) Matches(v Version) bool {<commit_msg>s/rev/revision/ for Revision.Type()<commit_after>package gps

import (
	"sort"

	"github.com/Masterminds/semver"
)

// Version represents one of the different types of versions used by gps.
//
// Version composes Constraint, because all versions can be used as a constraint
// (where they allow one, and only one, version - themselves), but constraints
// are not necessarily discrete versions.
//
// Version is an interface, but it contains private methods, which restricts it
// to gps's own internal implementations. We do this for the confluence of
// two reasons: the implementation of Versions is complete (there is no case in
// which we'd need other types), and the implementation relies on type magic
// under the hood, which would be unsafe to do if other dynamic types could be
// hiding behind the interface.
type Version interface {
	Constraint

	// Indicates the type of version - Revision, Branch, Version, or Semver
	Type() string
}

// PairedVersion represents a normal Version, but paired with its corresponding,
// underlying Revision.
type PairedVersion interface {
	Version

	// Underlying returns the immutable Revision that identifies this Version.
	Underlying() Revision

	// Unpair returns the surface-level UnpairedVersion that half of the pair.
	//
	// It does NOT modify the original PairedVersion
	Unpair() UnpairedVersion

	// Ensures it is impossible to be both a PairedVersion and an
	// UnpairedVersion
	_pair(int)
}

// UnpairedVersion represents a normal Version, with a method for creating a
// VersionPair by indicating the version's corresponding, underlying Revision.
type UnpairedVersion interface {
	Version
	// Is takes the underlying Revision that this UnpairedVersion corresponds
	// to and unites them into a PairedVersion.
	Is(Revision) PairedVersion
	// Ensures it is impossible to be both a PairedVersion and an
	// UnpairedVersion
	_pair(bool)
}

// types are weird
func (branchVersion) _private()  {}
func (branchVersion) _pair(bool) {}
func (plainVersion) _private()   {}
func (plainVersion) _pair(bool)  {}
func (semVersion) _private()     {}
func (semVersion) _pair(bool)    {}
func (versionPair) _private()    {}
func (versionPair) _pair(int)    {}
func (Revision) _private()       {}

// NewBranch creates a new Version to represent a floating version (in
// general, a branch).
func NewBranch(body string) UnpairedVersion {
	return branchVersion{
		name: body,
		// We always set isDefault to false here, because the property is
		// specifically designed to be internal-only: only the SourceManager
		// gets to mark it. This is OK because nothing that client code is
		// responsible for needs to care about has to touch it it.
		//
		// TODO(sdboyer) ...maybe. this just ugly.
		isDefault: false,
	}
}

func newDefaultBranch(body string) UnpairedVersion {
	return branchVersion{
		name:      body,
		isDefault: true,
	}
}

// NewVersion creates a Semver-typed Version if the provided version string is
// valid semver, and a plain/non-semver version if not.
func NewVersion(body string) UnpairedVersion {
	sv, err := semver.NewVersion(body)

	if err != nil {
		return plainVersion(body)
	}
	return semVersion{sv: sv}
}

// A Revision represents an immutable versioning identifier.
type Revision string

// String converts the Revision back into a string.
func (r Revision) String() string {
	return string(r)
}

// Type indicates the type of version - for revisions, "revision".
func (r Revision) Type() string {
	return "revision"
}

// Matches is the Revision acting as a constraint; it checks to see if the provided
// version is the same Revision as itself.
func (r Revision) Matches(v Version) bool {
{'fraction_non_alphanumeric': 0.08168859649122807, 'fraction_numerical': 0.0, 'mean_word_length': 3.8038183015141542, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5230536', 'n_tokens_mistral': 2079, 'n_tokens_neox': 1994, 'n_words': 916}