<commit_before>package gps

import (
	"fmt"
	"regexp"
	"strings"

	"github.com/Masterminds/semver"
)

var regfrom = regexp.MustCompile(`^(\w*) from (\w*) ([0-9\.]*)`)

// nvSplit splits an "info" string on " " into the pair of name and
// version/constraint, and returns each individually.
//
// This is for narrow use - panics if there are less than two resulting items in
// the slice.
func nvSplit(info string) (id ProjectIdentifier, version string) {
	if strings.Contains(info, " from ") {
		parts := regfrom.FindStringSubmatch(info)
		info = parts[1] + " " + parts[3]
		id.NetworkName = parts[2]
	}

	s := strings.SplitN(info, " ", 2)
	if len(s) < 2 {
		panic(fmt.Sprintf("Malformed name/version info string '%s'", info))
	}

	id.ProjectRoot, version = ProjectRoot(s[0]), s[1]
	if id.NetworkName == "" {
		id.NetworkName = string(id.ProjectRoot)
	}
	return
}

// nvrSplit splits an "info" string on " " into the triplet of name,
// version/constraint, and revision, and returns each individually.
//
// It will work fine if only name and version/constraint are provided.
//
// This is for narrow use - panics if there are less than two resulting items in
// the slice.
func nvrSplit(info string) (id ProjectIdentifier, version string, revision Revision) {
	if strings.Contains(info, " from ") {
		parts := regfrom.FindStringSubmatch(info)
		info = parts[1] + " " + parts[3]
		id.NetworkName = parts[2]
	}

	s := strings.SplitN(info, " ", 3)
	if len(s) < 2 {
		panic(fmt.Sprintf("Malformed name/version info string '%s'", info))
	}

	id.ProjectRoot, version = ProjectRoot(s[0]), s[1]
	if id.NetworkName == "" {
		id.NetworkName = string(id.ProjectRoot)
	}

	if len(s) == 3 {
		revision = Revision(s[2])
	}
	return
}

// mkAtom splits the input string on a space, and uses the first two elements as
// the project identifier and version, respectively.
//
// The version segment may have a leading character indicating the type of
// version to create:
//
//  p: create a "plain" (non-semver) version.
//  b: create a branch version.
//  r: create a revision.
//
// No prefix is assumed to indicate a semver version.
//
// If a third space-delimited element is provided, it will be interepreted as a
// revision, and used as the underlying version in a PairedVersion. No prefix
// should be provided in this case. It is an error (and will panic) to try to
// pass a revision with an underlying revision.
func mkAtom(info string) atom {
	// if info is "root", special case it to use the root "version"
	if info == "root" {
		return atom{
			id: ProjectIdentifier{
				ProjectRoot: ProjectRoot("root"),
				NetworkName: "root",
			},
			v: rootRev,
		}
	}

	id, ver, rev := nvrSplit(info)

	var v Version
	switch ver[0] {
	case 'r':
		if rev != "" {
			panic("Cannot pair a revision with a revision")
		}<commit_msg>Don't put a network name on root in mkAtom<commit_after>package gps

import (
	"fmt"
	"regexp"
	"strings"

	"github.com/Masterminds/semver"
)

var regfrom = regexp.MustCompile(`^(\w*) from (\w*) ([0-9\.]*)`)

// nvSplit splits an "info" string on " " into the pair of name and
// version/constraint, and returns each individually.
//
// This is for narrow use - panics if there are less than two resulting items in
// the slice.
func nvSplit(info string) (id ProjectIdentifier, version string) {
	if strings.Contains(info, " from ") {
		parts := regfrom.FindStringSubmatch(info)
		info = parts[1] + " " + parts[3]
		id.NetworkName = parts[2]
	}

	s := strings.SplitN(info, " ", 2)
	if len(s) < 2 {
		panic(fmt.Sprintf("Malformed name/version info string '%s'", info))
	}

	id.ProjectRoot, version = ProjectRoot(s[0]), s[1]
	if id.NetworkName == "" {
		id.NetworkName = string(id.ProjectRoot)
	}
	return
}

// nvrSplit splits an "info" string on " " into the triplet of name,
// version/constraint, and revision, and returns each individually.
//
// It will work fine if only name and version/constraint are provided.
//
// This is for narrow use - panics if there are less than two resulting items in
// the slice.
func nvrSplit(info string) (id ProjectIdentifier, version string, revision Revision) {
	if strings.Contains(info, " from ") {
		parts := regfrom.FindStringSubmatch(info)
		info = parts[1] + " " + parts[3]
		id.NetworkName = parts[2]
	}

	s := strings.SplitN(info, " ", 3)
	if len(s) < 2 {
		panic(fmt.Sprintf("Malformed name/version info string '%s'", info))
	}

	id.ProjectRoot, version = ProjectRoot(s[0]), s[1]
	if id.NetworkName == "" {
		id.NetworkName = string(id.ProjectRoot)
	}

	if len(s) == 3 {
		revision = Revision(s[2])
	}
	return
}

// mkAtom splits the input string on a space, and uses the first two elements as
// the project identifier and version, respectively.
//
// The version segment may have a leading character indicating the type of
// version to create:
//
//  p: create a "plain" (non-semver) version.
//  b: create a branch version.
//  r: create a revision.
//
// No prefix is assumed to indicate a semver version.
//
// If a third space-delimited element is provided, it will be interepreted as a
// revision, and used as the underlying version in a PairedVersion. No prefix
// should be provided in this case. It is an error (and will panic) to try to
// pass a revision with an underlying revision.
func mkAtom(info string) atom {
	// if info is "root", special case it to use the root "version"
	if info == "root" {
		return atom{
			id: ProjectIdentifier{
				ProjectRoot: ProjectRoot("root"),
			},
			v: rootRev,
		}
	}

	id, ver, rev := nvrSplit(info)

	var v Version
	switch ver[0] {
	case 'r':
		if rev != "" {
			panic("Cannot pair a revision with a revision")
		}
{'fraction_non_alphanumeric': 0.13112136266855925, 'fraction_numerical': 0.00674237047551455, 'mean_word_length': 3.3936087295401403, 'pattern_counts': {'":': 0, '<': 7, '<?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': '4469817', 'n_tokens_mistral': 1918, 'n_tokens_neox': 1824, 'n_words': 672}