mirror of
https://github.com/rocky-linux/srpmproc.git
synced 2024-09-27 20:34:09 +00:00
add no-dup-mode to skip already imported tags
This commit is contained in:
parent
339aa90e37
commit
dbc948a453
@ -26,6 +26,7 @@ var (
|
|||||||
gitCommitterEmail string
|
gitCommitterEmail string
|
||||||
modulePrefix string
|
modulePrefix string
|
||||||
rpmPrefix string
|
rpmPrefix string
|
||||||
|
noDupMode bool
|
||||||
)
|
)
|
||||||
|
|
||||||
var root = &cobra.Command{
|
var root = &cobra.Command{
|
||||||
@ -87,6 +88,7 @@ func mn(_ *cobra.Command, _ []string) {
|
|||||||
GitCommitterEmail: gitCommitterEmail,
|
GitCommitterEmail: gitCommitterEmail,
|
||||||
ModulePrefix: modulePrefix,
|
ModulePrefix: modulePrefix,
|
||||||
Authenticator: authenticator,
|
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(&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(&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().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 {
|
if err := root.Execute(); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
|
@ -71,6 +71,7 @@ func (g *GitMode) WriteSource(md *modeData) {
|
|||||||
|
|
||||||
match := tagImportRegex.FindStringSubmatch(md.tagBranch)
|
match := tagImportRegex.FindStringSubmatch(md.tagBranch)
|
||||||
refspec := config.RefSpec(fmt.Sprintf("+refs/heads/%s:%s", match[2], 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{
|
err = remote.Fetch(&git.FetchOptions{
|
||||||
RemoteName: "upstream",
|
RemoteName: "upstream",
|
||||||
RefSpecs: []config.RefSpec{refspec},
|
RefSpecs: []config.RefSpec{refspec},
|
||||||
@ -115,9 +116,9 @@ func (g *GitMode) WriteSource(md *modeData) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
lineInfo := strings.Split(line, " ")
|
lineInfo := strings.SplitN(line, " ", 2)
|
||||||
hash := lineInfo[0]
|
hash := strings.TrimSpace(lineInfo[0])
|
||||||
path := lineInfo[1]
|
path := strings.TrimSpace(lineInfo[1])
|
||||||
|
|
||||||
url := fmt.Sprintf("https://git.centos.org/sources/%s/%s/%s", md.rpmFile.Name(), match[2], hash)
|
url := fmt.Sprintf("https://git.centos.org/sources/%s/%s/%s", md.rpmFile.Name(), match[2], hash)
|
||||||
log.Printf("downloading %s", url)
|
log.Printf("downloading %s", url)
|
||||||
|
@ -35,6 +35,7 @@ type ProcessData struct {
|
|||||||
Authenticator *ssh.PublicKeys
|
Authenticator *ssh.PublicKeys
|
||||||
Importer ImportMode
|
Importer ImportMode
|
||||||
BlobStorage blob.Storage
|
BlobStorage blob.Storage
|
||||||
|
NoDupMode bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type ignoredSource struct {
|
type ignoredSource struct {
|
||||||
@ -63,6 +64,40 @@ type modeData struct {
|
|||||||
func ProcessRPM(pd *ProcessData) {
|
func ProcessRPM(pd *ProcessData) {
|
||||||
md := pd.Importer.RetrieveSource(pd)
|
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
|
sourceRepo := *md.repo
|
||||||
sourceWorktree := *md.worktree
|
sourceWorktree := *md.worktree
|
||||||
|
|
||||||
@ -89,6 +124,18 @@ func ProcessRPM(pd *ProcessData) {
|
|||||||
|
|
||||||
match := tagImportRegex.FindStringSubmatch(md.tagBranch)
|
match := tagImportRegex.FindStringSubmatch(md.tagBranch)
|
||||||
md.pushBranch = "rocky" + strings.TrimPrefix(match[2], "c")
|
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
|
// create a new remote
|
||||||
remoteUrl := fmt.Sprintf("%s/dist/%s.git", pd.UpstreamPrefix, rpmFile.Name())
|
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())
|
log.Printf("committed:\n%s", obj.String())
|
||||||
|
|
||||||
newTag := "imports/rocky" + strings.TrimPrefix(match[1], "imports/c")
|
|
||||||
_, err = repo.CreateTag(newTag, commit, &git.CreateTagOptions{
|
_, err = repo.CreateTag(newTag, commit, &git.CreateTagOptions{
|
||||||
Tagger: &object.Signature{
|
Tagger: &object.Signature{
|
||||||
Name: pd.GitCommitterName,
|
Name: pd.GitCommitterName,
|
||||||
|
Loading…
Reference in New Issue
Block a user