mirror of
https://github.com/rocky-linux/srpmproc.git
synced 2024-06-02 08:10:17 +00:00
stop relying on alphabetical order for branches and use tagged date instead
This commit is contained in:
parent
1ce1a19a4f
commit
5705879dcc
|
@ -6,6 +6,7 @@ import (
|
||||||
"github.com/go-git/go-git/v5"
|
"github.com/go-git/go-git/v5"
|
||||||
"github.com/go-git/go-git/v5/config"
|
"github.com/go-git/go-git/v5/config"
|
||||||
"github.com/go-git/go-git/v5/plumbing"
|
"github.com/go-git/go-git/v5/plumbing"
|
||||||
|
"github.com/go-git/go-git/v5/plumbing/object"
|
||||||
"github.com/go-git/go-git/v5/storage/memory"
|
"github.com/go-git/go-git/v5/storage/memory"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
|
@ -13,8 +14,28 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type remoteTarget struct {
|
||||||
|
remote string
|
||||||
|
when time.Time
|
||||||
|
}
|
||||||
|
|
||||||
|
type remoteTargetSlice []remoteTarget
|
||||||
|
|
||||||
|
func (p remoteTargetSlice) Len() int {
|
||||||
|
return len(p)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p remoteTargetSlice) Less(i, j int) bool {
|
||||||
|
return p[i].when.Before(p[j].when)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p remoteTargetSlice) Swap(i, j int) {
|
||||||
|
p[i], p[j] = p[j], p[i]
|
||||||
|
}
|
||||||
|
|
||||||
type GitMode struct{}
|
type GitMode struct{}
|
||||||
|
|
||||||
func (g *GitMode) RetrieveSource(pd *ProcessData) *modeData {
|
func (g *GitMode) RetrieveSource(pd *ProcessData) *modeData {
|
||||||
|
@ -38,39 +59,45 @@ func (g *GitMode) RetrieveSource(pd *ProcessData) *modeData {
|
||||||
log.Fatalf("could not create remote: %v", err)
|
log.Fatalf("could not create remote: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
list, err := remote.List(&git.ListOptions{})
|
err = remote.Fetch(&git.FetchOptions{
|
||||||
|
RemoteName: "upstream",
|
||||||
|
RefSpecs: []config.RefSpec{refspec},
|
||||||
|
Tags: git.AllTags,
|
||||||
|
Force: true,
|
||||||
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("could not list remote: %v", err)
|
log.Fatalf("could not fetch upstream: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var branches []string
|
var branches remoteTargetSlice
|
||||||
|
|
||||||
for _, ref := range list {
|
tagIter, err := repo.TagObjects()
|
||||||
log.Println(ref.String())
|
if err != nil {
|
||||||
name := string(ref.Name())
|
log.Fatalf("could not get tag objects: %v", err)
|
||||||
if strings.HasPrefix(name, fmt.Sprintf("refs/tags/imports/c%d", pd.Version)) {
|
}
|
||||||
branches = append(branches, name)
|
_ = tagIter.ForEach(func(tag *object.Tag) error {
|
||||||
|
log.Printf("tag: %s", tag.Name)
|
||||||
|
if strings.HasPrefix(tag.Name, fmt.Sprintf("imports/c%d", pd.Version)) {
|
||||||
|
branches = append(branches, remoteTarget{
|
||||||
|
remote: fmt.Sprintf("refs/tags/%s", tag.Name),
|
||||||
|
when: tag.Tagger.When,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
return nil
|
||||||
|
})
|
||||||
|
sort.Sort(branches)
|
||||||
|
|
||||||
// no tags? fetch branches
|
var sortedBranches []string
|
||||||
if len(branches) == 0 {
|
for _, branch := range branches {
|
||||||
for _, ref := range list {
|
sortedBranches = append(sortedBranches, branch.remote)
|
||||||
name := string(ref.Name())
|
|
||||||
prefix := fmt.Sprintf("refs/heads/c%d", pd.Version)
|
|
||||||
if strings.HasPrefix(name, prefix) {
|
|
||||||
branches = append(branches, name)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
sort.Strings(branches)
|
|
||||||
|
|
||||||
return &modeData{
|
return &modeData{
|
||||||
repo: repo,
|
repo: repo,
|
||||||
worktree: w,
|
worktree: w,
|
||||||
rpmFile: createPackageFile(filepath.Base(pd.RpmLocation)),
|
rpmFile: createPackageFile(filepath.Base(pd.RpmLocation)),
|
||||||
fileWrites: nil,
|
fileWrites: nil,
|
||||||
branches: branches,
|
branches: sortedBranches,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user