Commit aa600cd5 authored by Mustafa Gezen's avatar Mustafa Gezen
Browse files

Only import latest version of each stream/release by default

parent b18468ed
......@@ -71,13 +71,24 @@ func (g *GitMode) RetrieveSource(pd *data.ProcessData) *data.ModeData {
var branches remoteTargetSlice
latestTags := map[string]*remoteTarget{}
tagAdd := func(tag *object.Tag) error {
if strings.HasPrefix(tag.Name, fmt.Sprintf("imports/%s%d", pd.ImportBranchPrefix, pd.Version)) {
log.Printf("tag: %s", tag.Name)
branches = append(branches, remoteTarget{
remote: fmt.Sprintf("refs/tags/%s", tag.Name),
when: tag.Tagger.When,
})
refSpec := fmt.Sprintf("refs/tags/%s", tag.Name)
if tagImportRegex.MatchString(refSpec) {
match := tagImportRegex.FindStringSubmatch(refSpec)
exists := latestTags[match[2]]
if exists != nil && exists.when.After(tag.Tagger.When) {
return nil
}
latestTags[match[2]] = &remoteTarget{
remote: refSpec,
when: tag.Tagger.When,
}
}
}
return nil
}
......@@ -88,7 +99,7 @@ func (g *GitMode) RetrieveSource(pd *data.ProcessData) *data.ModeData {
}
_ = tagIter.ForEach(tagAdd)
if len(branches) == 0 {
if len(latestTags) == 0 {
list, err := remote.List(&git.ListOptions{})
if err != nil {
log.Fatalf("could not list upstream: %v", err)
......@@ -110,6 +121,11 @@ func (g *GitMode) RetrieveSource(pd *data.ProcessData) *data.ModeData {
}
}
for _, branch := range latestTags {
log.Printf("tag: %s", strings.TrimPrefix(branch.remote, "refs/tags/"))
branches = append(branches, *branch)
}
sort.Sort(branches)
var sortedBranches []string
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment