Skip to content

Commit

Permalink
handle duplicate project/version by linking
Browse files Browse the repository at this point in the history
  • Loading branch information
dmgk committed May 3, 2020
1 parent 0087562 commit 58499fe
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
6 changes: 5 additions & 1 deletion parser/parser_online_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ func TestUniqueProjectAndTag(t *testing.T) {
# github.com/ugorji/go v1.1.7`

expected := `GH_TUPLE= json-iterator:go:v1.1.7:json_iterator_go/vendor/github.com/json-iterator/go \
ugorji:go:23ab95ef5dc3:ugorji_go/vendor/github.com/ugorji/go`
ugorji:go:v1.1.7:ugorji_go
post-extract:
@${MKDIR} ${WRKSRC}/vendor/github.com/ugorji
@${RLN} ${WRKSRC_json_iterator_go} ${WRKSRC}/vendor/github.com/ugorji/go`

tt, err := Read(strings.NewReader(given))
if err != nil {
Expand Down
32 changes: 17 additions & 15 deletions tuple/tuple.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ func fixGithubProjectsAndTags(s Slice) error {
}

key := func(i int) string {
return fmt.Sprintf("%T:%s:%s:%s", s[i].source, s[i].account, s[i].project, s[i].version)
return fmt.Sprintf("%T:%s:%s:%s", s[i].source, s[i].project, s[i].version, s[i].account)
}
sort.Slice(s, func(i, j int) bool {
return key(i) < key(j)
Expand All @@ -340,20 +340,24 @@ func fixGithubProjectsAndTags(s Slice) error {
continue
}

if t.account != prevTuple.account {
// different Account, same Project and Version
if t.project == prevTuple.project && t.version == prevTuple.version {
hash, err := apis.GithubGetCommit(t.account, t.project, t.version)
if err != nil {
return DuplicateProjectAndTag(t.String())
}
if len(hash) < 12 {
return errors.New("unexpectedly short Githib commit hash")
}
debug.Printf("[fixGithubProjectsAndTags] translated Github tag %q to %q\n", t.version, hash[:12])
t.version = hash[:12]
if t.project == prevTuple.project && t.version == prevTuple.version && t.module == prevTuple.module {
// same Project and Version, different Account
if t.account != prevTuple.account {
// hash, err := apis.GithubGetCommit(t.account, t.project, t.version)
// if err != nil {
// return DuplicateProjectAndTag(t.String())
// }
// if len(hash) < 12 {
// return errors.New("unexpectedly short Githib commit hash")
// }
// debug.Printf("[fixGithubProjectsAndTags] translated Github tag %q to %q\n", t.version, hash[:12])
// t.version = hash[:12]

// dont bother with replacing tag with commit hash, just link to prev tuple
t.makeLinkedAs(prevTuple)
}
}
prevTuple = t
}

return nil
Expand Down Expand Up @@ -408,8 +412,6 @@ func fixSubdirs(s Slice) {
debug.Printf("[fixSubdirs] hiding %s/%s@%s (parent %s@%s)\n", t.pkg, t.module, t.version, prevSubdir, prevVersion)
t.hidden = true
}
} else {
prevSubdir = t.subdir
}
prevSubdir, prevVersion = currentSubdir, currentVersion
}
Expand Down

0 comments on commit 58499fe

Please sign in to comment.