mirror of
https://github.com/rocky-linux/srpmproc.git
synced 2024-06-02 08:10:17 +00:00
Cleaned up formatting w/ gofmt
(no functional changes) -Skip G.
This commit is contained in:
parent
f339965767
commit
ca54976b8a
|
@ -56,8 +56,8 @@ var (
|
||||||
basicPassword string
|
basicPassword string
|
||||||
packageVersion string
|
packageVersion string
|
||||||
packageRelease string
|
packageRelease string
|
||||||
taglessMode bool
|
taglessMode bool
|
||||||
altLookAside bool
|
altLookAside bool
|
||||||
)
|
)
|
||||||
|
|
||||||
var root = &cobra.Command{
|
var root = &cobra.Command{
|
||||||
|
@ -97,7 +97,7 @@ func mn(_ *cobra.Command, _ []string) {
|
||||||
TaglessMode: taglessMode,
|
TaglessMode: taglessMode,
|
||||||
AltLookAside: altLookAside,
|
AltLookAside: altLookAside,
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -147,9 +147,8 @@ func main() {
|
||||||
root.Flags().StringVar(&basicPassword, "basic-password", "", "Basic auth password")
|
root.Flags().StringVar(&basicPassword, "basic-password", "", "Basic auth password")
|
||||||
root.Flags().StringVar(&packageVersion, "package-version", "", "Package version to fetch")
|
root.Flags().StringVar(&packageVersion, "package-version", "", "Package version to fetch")
|
||||||
root.Flags().StringVar(&packageRelease, "package-release", "", "Package release to fetch")
|
root.Flags().StringVar(&packageRelease, "package-release", "", "Package release to fetch")
|
||||||
root.Flags().BoolVar(&taglessMode, "taglessmode", false, "Tagless mode: If set, pull the latest commit from a branch, and determine version info from spec file (aka upstream versions aren't tagged)")
|
root.Flags().BoolVar(&taglessMode, "taglessmode", false, "Tagless mode: If set, pull the latest commit from a branch, and determine version info from spec file (aka upstream versions aren't tagged)")
|
||||||
root.Flags().BoolVar(&altLookAside, "altlookaside", false, "If set, uses the new CentOS Stream lookaside pattern (https://<SITE_PREFIX>/<RPM_NAME>/<FILE_NAME>/<SHA_VERSION>/<SHA_SUM>/<FILE_NAME>)")
|
root.Flags().BoolVar(&altLookAside, "altlookaside", false, "If set, uses the new CentOS Stream lookaside pattern (https://<SITE_PREFIX>/<RPM_NAME>/<FILE_NAME>/<SHA_VERSION>/<SHA_SUM>/<FILE_NAME>)")
|
||||||
|
|
||||||
|
|
||||||
if err := root.Execute(); err != nil {
|
if err := root.Execute(); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
|
|
226
pkg/modes/git.go
226
pkg/modes/git.go
|
@ -125,52 +125,46 @@ func (g *GitMode) RetrieveSource(pd *data.ProcessData) (*data.ModeData, error) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// In case of "tagless mode", we need to get the head ref of the branch instead
|
||||||
// In case of "tagless mode", we need to get the head ref of the branch instead
|
// This is a kind of alternative implementation of the above tagAdd assignment
|
||||||
// This is a kind of alternative implementation of the above tagAdd assignment
|
refAdd := func(tag *object.Tag) error {
|
||||||
refAdd := func(tag *object.Tag) error {
|
|
||||||
if strings.HasPrefix(tag.Name, fmt.Sprintf("refs/heads/%s%d%s", pd.ImportBranchPrefix, pd.Version, pd.BranchSuffix)) {
|
if strings.HasPrefix(tag.Name, fmt.Sprintf("refs/heads/%s%d%s", pd.ImportBranchPrefix, pd.Version, pd.BranchSuffix)) {
|
||||||
pd.Log.Printf("Tagless mode: Identified tagless commit for import: %s\n", tag.Name)
|
pd.Log.Printf("Tagless mode: Identified tagless commit for import: %s\n", tag.Name)
|
||||||
refSpec := fmt.Sprintf(tag.Name)
|
refSpec := fmt.Sprintf(tag.Name)
|
||||||
|
|
||||||
|
|
||||||
// We split the string by "/", the branch name we're looking for to pass to latestTags is always last
|
// We split the string by "/", the branch name we're looking for to pass to latestTags is always last
|
||||||
// (ex: "refs/heads/c9s" ---> we want latestTags[c9s]
|
// (ex: "refs/heads/c9s" ---> we want latestTags[c9s]
|
||||||
_tmpRef := strings.Split(refSpec, "/")
|
_tmpRef := strings.Split(refSpec, "/")
|
||||||
_branchName := _tmpRef[(len(_tmpRef) - 1)]
|
_branchName := _tmpRef[(len(_tmpRef) - 1)]
|
||||||
|
|
||||||
// In the case of "strict branch mode" on, the branch name must match *exactly* with our prefix-version-suffix (like "c8" cannot also match "c8-beta")
|
// In the case of "strict branch mode" on, the branch name must match *exactly* with our prefix-version-suffix (like "c8" cannot also match "c8-beta")
|
||||||
// If it doesn't, bail out without adding this branch
|
// If it doesn't, bail out without adding this branch
|
||||||
if pd.StrictBranchMode == true && _branchName != fmt.Sprintf("%s%d%s", pd.ImportBranchPrefix, pd.Version, pd.BranchSuffix) {
|
if pd.StrictBranchMode == true && _branchName != fmt.Sprintf("%s%d%s", pd.ImportBranchPrefix, pd.Version, pd.BranchSuffix) {
|
||||||
return nil
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
latestTags[_branchName] = &remoteTarget{
|
||||||
|
remote: refSpec,
|
||||||
|
when: tag.Tagger.When,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
latestTags[_branchName] = &remoteTarget{
|
|
||||||
remote: refSpec,
|
|
||||||
when: tag.Tagger.When,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tagIter, err := repo.TagObjects()
|
||||||
tagIter, err := repo.TagObjects()
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("could not get tag objects: %v", err)
|
return nil, fmt.Errorf("could not get tag objects: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// tagless mode means we use "refAdd" (add commit by reference)
|
// tagless mode means we use "refAdd" (add commit by reference)
|
||||||
// normal mode means we can rely on "tagAdd" (the tag should be present for us in the source repo)
|
// normal mode means we can rely on "tagAdd" (the tag should be present for us in the source repo)
|
||||||
if pd.TaglessMode == true {
|
if pd.TaglessMode == true {
|
||||||
_ = tagIter.ForEach(refAdd)
|
_ = tagIter.ForEach(refAdd)
|
||||||
} else {
|
} else {
|
||||||
_ = tagIter.ForEach(tagAdd)
|
_ = tagIter.ForEach(tagAdd)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
listOpts := &git.ListOptions{
|
listOpts := &git.ListOptions{
|
||||||
Auth: pd.Authenticator,
|
Auth: pd.Authenticator,
|
||||||
}
|
}
|
||||||
|
@ -196,21 +190,20 @@ func (g *GitMode) RetrieveSource(pd *data.ProcessData) (*data.ModeData, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Call refAdd instead of tagAdd in the case of TaglessMode enabled
|
// Call refAdd instead of tagAdd in the case of TaglessMode enabled
|
||||||
if pd.TaglessMode == true {
|
if pd.TaglessMode == true {
|
||||||
_ = refAdd(&object.Tag{
|
_ = refAdd(&object.Tag{
|
||||||
Name: string(ref.Name()),
|
Name: string(ref.Name()),
|
||||||
Tagger: commit.Committer,
|
Tagger: commit.Committer,
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
_ = tagAdd(&object.Tag{
|
_ = tagAdd(&object.Tag{
|
||||||
Name: strings.TrimPrefix(string(ref.Name()), "refs/tags/"),
|
Name: strings.TrimPrefix(string(ref.Name()), "refs/tags/"),
|
||||||
Tagger: commit.Committer,
|
Tagger: commit.Committer,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, branch := range latestTags {
|
for _, branch := range latestTags {
|
||||||
|
@ -223,7 +216,7 @@ func (g *GitMode) RetrieveSource(pd *data.ProcessData) (*data.ModeData, error) {
|
||||||
for _, branch := range branches {
|
for _, branch := range branches {
|
||||||
sortedBranches = append(sortedBranches, branch.remote)
|
sortedBranches = append(sortedBranches, branch.remote)
|
||||||
}
|
}
|
||||||
|
|
||||||
return &data.ModeData{
|
return &data.ModeData{
|
||||||
Name: filepath.Base(pd.RpmLocation),
|
Name: filepath.Base(pd.RpmLocation),
|
||||||
Repo: repo,
|
Repo: repo,
|
||||||
|
@ -234,73 +227,68 @@ func (g *GitMode) RetrieveSource(pd *data.ProcessData) (*data.ModeData, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *GitMode) WriteSource(pd *data.ProcessData, md *data.ModeData) error {
|
func (g *GitMode) WriteSource(pd *data.ProcessData, md *data.ModeData) error {
|
||||||
|
|
||||||
remote, err := md.Repo.Remote("upstream")
|
remote, err := md.Repo.Remote("upstream")
|
||||||
|
|
||||||
if err != nil && pd.TaglessMode == false {
|
if err != nil && pd.TaglessMode == false {
|
||||||
return fmt.Errorf("could not get upstream remote: %v", err)
|
return fmt.Errorf("could not get upstream remote: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
var refspec config.RefSpec
|
var refspec config.RefSpec
|
||||||
var branchName string
|
var branchName string
|
||||||
|
|
||||||
fmt.Printf("pd.AltLookaside == %v , pd.CdnUrl == %s \n", pd.AltLookAside, pd.CdnUrl)
|
// In the case of tagless mode, we already have the transformed repo sitting in the worktree,
|
||||||
|
// and don't need to perform any checkout or fetch operations
|
||||||
|
if pd.TaglessMode == false {
|
||||||
|
if strings.HasPrefix(md.TagBranch, "refs/heads") {
|
||||||
|
refspec = config.RefSpec(fmt.Sprintf("+%s:%s", md.TagBranch, md.TagBranch))
|
||||||
|
branchName = strings.TrimPrefix(md.TagBranch, "refs/heads/")
|
||||||
|
} else {
|
||||||
|
match := misc.GetTagImportRegex(pd).FindStringSubmatch(md.TagBranch)
|
||||||
|
branchName = match[2]
|
||||||
|
refspec = config.RefSpec(fmt.Sprintf("+refs/heads/%s:%s", branchName, md.TagBranch))
|
||||||
|
fmt.Println("Found branchname that does not start w/ refs/heads :: ", branchName)
|
||||||
|
}
|
||||||
|
pd.Log.Printf("checking out upstream refspec %s", refspec)
|
||||||
|
|
||||||
// In the case of tagless mode, we already have the transformed repo sitting in the worktree,
|
fetchOpts := &git.FetchOptions{
|
||||||
// and don't need to perform any checkout or fetch operations
|
Auth: pd.Authenticator,
|
||||||
if pd.TaglessMode == false {
|
RemoteName: "upstream",
|
||||||
if strings.HasPrefix(md.TagBranch, "refs/heads") {
|
RefSpecs: []config.RefSpec{refspec},
|
||||||
refspec = config.RefSpec(fmt.Sprintf("+%s:%s", md.TagBranch, md.TagBranch))
|
Tags: git.AllTags,
|
||||||
branchName = strings.TrimPrefix(md.TagBranch, "refs/heads/")
|
Force: true,
|
||||||
} else {
|
}
|
||||||
match := misc.GetTagImportRegex(pd).FindStringSubmatch(md.TagBranch)
|
err = remote.Fetch(fetchOpts)
|
||||||
branchName = match[2]
|
if err != nil && err != git.NoErrAlreadyUpToDate {
|
||||||
refspec = config.RefSpec(fmt.Sprintf("+refs/heads/%s:%s", branchName, md.TagBranch))
|
if err == transport.ErrInvalidAuthMethod || err == transport.ErrAuthenticationRequired {
|
||||||
fmt.Println("Found branchname that does not start w/ refs/heads :: ", branchName)
|
fetchOpts.Auth = nil
|
||||||
}
|
err = remote.Fetch(fetchOpts)
|
||||||
pd.Log.Printf("checking out upstream refspec %s", refspec)
|
if err != nil && err != git.NoErrAlreadyUpToDate {
|
||||||
|
return fmt.Errorf("could not fetch upstream: %v", err)
|
||||||
|
}
|
||||||
fetchOpts := &git.FetchOptions{
|
} else {
|
||||||
Auth: pd.Authenticator,
|
return fmt.Errorf("could not fetch upstream: %v", err)
|
||||||
RemoteName: "upstream",
|
}
|
||||||
RefSpecs: []config.RefSpec{refspec},
|
}
|
||||||
Tags: git.AllTags,
|
|
||||||
Force: true,
|
|
||||||
}
|
|
||||||
err = remote.Fetch(fetchOpts)
|
|
||||||
if err != nil && err != git.NoErrAlreadyUpToDate {
|
|
||||||
if err == transport.ErrInvalidAuthMethod || err == transport.ErrAuthenticationRequired {
|
|
||||||
fetchOpts.Auth = nil
|
|
||||||
err = remote.Fetch(fetchOpts)
|
|
||||||
if err != nil && err != git.NoErrAlreadyUpToDate {
|
|
||||||
return fmt.Errorf("could not fetch upstream: %v", err)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return fmt.Errorf("could not fetch upstream: %v", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
err = md.Worktree.Checkout(&git.CheckoutOptions{
|
err = md.Worktree.Checkout(&git.CheckoutOptions{
|
||||||
Branch: plumbing.ReferenceName(md.TagBranch),
|
Branch: plumbing.ReferenceName(md.TagBranch),
|
||||||
Force: true,
|
Force: true,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("could not checkout source from git: %v", err)
|
return fmt.Errorf("could not checkout source from git: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_, err = md.Worktree.Add(".")
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("could not add Worktree: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if pd.TaglessMode == true {
|
||||||
|
branchName = fmt.Sprintf("%s%d%s", pd.ImportBranchPrefix, pd.Version, pd.BranchSuffix)
|
||||||
|
}
|
||||||
|
|
||||||
_, err = md.Worktree.Add(".")
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("could not add Worktree: %v", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if pd.TaglessMode == true {
|
|
||||||
branchName = fmt.Sprintf("%s%d%s", pd.ImportBranchPrefix, pd.Version, pd.BranchSuffix)
|
|
||||||
}
|
|
||||||
|
|
||||||
metadataPath := ""
|
metadataPath := ""
|
||||||
ls, err := md.Worktree.Filesystem.ReadDir(".")
|
ls, err := md.Worktree.Filesystem.ReadDir(".")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -358,32 +346,32 @@ func (g *GitMode) WriteSource(pd *data.ProcessData, md *data.ModeData) error {
|
||||||
body = fromBlobStorage
|
body = fromBlobStorage
|
||||||
pd.Log.Printf("downloading %s from blob storage", hash)
|
pd.Log.Printf("downloading %s from blob storage", hash)
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
url := ""
|
url := ""
|
||||||
// Alternate lookaside logic: if enabled, we pull from a new URL pattern
|
// Alternate lookaside logic: if enabled, we pull from a new URL pattern
|
||||||
if pd.AltLookAside == false {
|
if pd.AltLookAside == false {
|
||||||
url = fmt.Sprintf("%s/%s/%s/%s", pd.CdnUrl, md.Name, branchName, hash)
|
url = fmt.Sprintf("%s/%s/%s/%s", pd.CdnUrl, md.Name, branchName, hash)
|
||||||
} else {
|
} else {
|
||||||
// We first need the hash algorithm based on length of hash:
|
// We first need the hash algorithm based on length of hash:
|
||||||
hashType := "sha512"
|
hashType := "sha512"
|
||||||
switch len(hash) {
|
switch len(hash) {
|
||||||
case 128:
|
case 128:
|
||||||
hashType = "sha512"
|
hashType = "sha512"
|
||||||
case 64:
|
case 64:
|
||||||
hashType = "sha256"
|
hashType = "sha256"
|
||||||
case 40:
|
case 40:
|
||||||
hashType = "sha1"
|
hashType = "sha1"
|
||||||
case 32:
|
case 32:
|
||||||
hashType = "md5"
|
hashType = "md5"
|
||||||
}
|
}
|
||||||
|
|
||||||
// need the name of the file without "SOURCES/":
|
// need the name of the file without "SOURCES/":
|
||||||
fileName := strings.Split(path, "/")[1]
|
fileName := strings.Split(path, "/")[1]
|
||||||
|
|
||||||
// Alt. lookaside url is of the form: <cdn> / <name> / <filename> / <hashtype> / <hash> / <filename>
|
// Alt. lookaside url is of the form: <cdn> / <name> / <filename> / <hashtype> / <hash> / <filename>
|
||||||
url = fmt.Sprintf("%s/%s/%s/%s/%s/%s", pd.CdnUrl, md.Name, fileName, hashType, hash, fileName)
|
url = fmt.Sprintf("%s/%s/%s/%s/%s/%s", pd.CdnUrl, md.Name, fileName, hashType, hash, fileName)
|
||||||
}
|
}
|
||||||
|
|
||||||
pd.Log.Printf("downloading %s", url)
|
pd.Log.Printf("downloading %s", url)
|
||||||
|
|
||||||
req, err := http.NewRequest("GET", url, nil)
|
req, err := http.NewRequest("GET", url, nil)
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user