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

add no-dup-mode to skip already imported tags

parent 339aa90e
......@@ -26,6 +26,7 @@ var (
gitCommitterEmail string
modulePrefix string
rpmPrefix string
noDupMode bool
)
var root = &cobra.Command{
......@@ -87,6 +88,7 @@ func mn(_ *cobra.Command, _ []string) {
GitCommitterEmail: gitCommitterEmail,
ModulePrefix: modulePrefix,
Authenticator: authenticator,
NoDupMode: noDupMode,
})
}
......@@ -106,6 +108,7 @@ func main() {
root.Flags().StringVar(&gitCommitterEmail, "git-committer-email", "mustafa+distrobuild@bycrates.com", "Email of committer")
root.Flags().StringVar(&modulePrefix, "module-prefix", "https://git.centos.org/modules", "Where to retrieve modules if exists. Only used when source-rpm is a git repo")
root.Flags().StringVar(&rpmPrefix, "rpm-prefix", "https://git.centos.org/rpms", "Where to retrieve SRPM content. Only used when source-rpm is not a local file")
root.Flags().BoolVar(&noDupMode, "no-dup-mode", false, "If enabled, skips already imported tags")
if err := root.Execute(); err != nil {
log.Fatal(err)
......
......@@ -71,6 +71,7 @@ func (g *GitMode) WriteSource(md *modeData) {
match := tagImportRegex.FindStringSubmatch(md.tagBranch)
refspec := config.RefSpec(fmt.Sprintf("+refs/heads/%s:%s", match[2], md.tagBranch))
log.Printf("checking out upstream refspec %s", refspec)
err = remote.Fetch(&git.FetchOptions{
RemoteName: "upstream",
RefSpecs: []config.RefSpec{refspec},
......@@ -115,9 +116,9 @@ func (g *GitMode) WriteSource(md *modeData) {
continue
}
lineInfo := strings.Split(line, " ")
hash := lineInfo[0]
path := lineInfo[1]
lineInfo := strings.SplitN(line, " ", 2)
hash := strings.TrimSpace(lineInfo[0])
path := strings.TrimSpace(lineInfo[1])
url := fmt.Sprintf("https://git.centos.org/sources/%s/%s/%s", md.rpmFile.Name(), match[2], hash)
log.Printf("downloading %s", url)
......
......@@ -35,6 +35,7 @@ type ProcessData struct {
Authenticator *ssh.PublicKeys
Importer ImportMode
BlobStorage blob.Storage
NoDupMode bool
}
type ignoredSource struct {
......@@ -63,6 +64,40 @@ type modeData struct {
func ProcessRPM(pd *ProcessData) {
md := pd.Importer.RetrieveSource(pd)
// if no-dup-mode is enabled then skip already imported versions
var tagIgnoreList []string
if pd.NoDupMode {
repo, err := git.Init(memory.NewStorage(), memfs.New())
if err != nil {
log.Fatalf("could not init git repo: %v", err)
}
remoteUrl := fmt.Sprintf("%s/dist/%s.git", pd.UpstreamPrefix, md.rpmFile.Name())
refspec := config.RefSpec("+refs/heads/*:refs/remotes/origin/*")
remote, err := repo.CreateRemote(&config.RemoteConfig{
Name: "origin",
URLs: []string{remoteUrl},
Fetch: []config.RefSpec{refspec},
})
if err != nil {
log.Fatalf("could not create remote: %v", err)
}
list, err := remote.List(&git.ListOptions{
Auth: pd.Authenticator,
})
if err != nil {
log.Fatalf("could not list remote: %v", err)
}
for _, ref := range list {
if !strings.HasPrefix(string(ref.Name()), "refs/tags/imports") {
continue
}
tagIgnoreList = append(tagIgnoreList, string(ref.Name()))
}
}
sourceRepo := *md.repo
sourceWorktree := *md.worktree
......@@ -89,6 +124,18 @@ func ProcessRPM(pd *ProcessData) {
match := tagImportRegex.FindStringSubmatch(md.tagBranch)
md.pushBranch = "rocky" + strings.TrimPrefix(match[2], "c")
newTag := "imports/rocky" + strings.TrimPrefix(match[1], "imports/c")
shouldContinue := true
for _, ignoredTag := range tagIgnoreList {
if ignoredTag == "refs/tags/"+newTag {
log.Printf("skipping %s", ignoredTag)
shouldContinue = false
}
}
if !shouldContinue {
continue
}
// create a new remote
remoteUrl := fmt.Sprintf("%s/dist/%s.git", pd.UpstreamPrefix, rpmFile.Name())
......@@ -225,7 +272,6 @@ func ProcessRPM(pd *ProcessData) {
log.Printf("committed:\n%s", obj.String())
newTag := "imports/rocky" + strings.TrimPrefix(match[1], "imports/c")
_, err = repo.CreateTag(newTag, commit, &git.CreateTagOptions{
Tagger: &object.Signature{
Name: pd.GitCommitterName,
......
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