Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions core/common/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ func ToShortRemote(remote string) string {
// requestOptions is folded into the key when any of its fields affect computation
// (today: extra_exclude_files_regex). Empty/nil ⇒ legacy path unchanged.
func GetGraphByTreeHash(remote, treehash string, requestOptions *tangopb.RequestOptions) string {
return filepath.Join(ToShortRemote(remote), treehash) + HashRequestOptions(requestOptions)
return filepath.Join("graph", ToShortRemote(remote), treehash) + HashRequestOptions(requestOptions)
}

// GetTreehashCachePath returns the cache path for the treehash mapping.
// The git treehash is purely a function of git state, so requestOptions is not
// part of this key.
func GetTreehashCachePath(buildDescription *tangopb.BuildDescription) string {
return filepath.Join(ToShortRemote(buildDescription.Remote), fmt.Sprintf("treehash-map-%s", buildDescription.BaseSha), getReqsHash(buildDescription.Requests)) + "-" + buildDescription.Strategy.String()
return filepath.Join("treehash", ToShortRemote(buildDescription.Remote), fmt.Sprintf("treehash-map-%s", buildDescription.BaseSha), GetReqsHash(buildDescription.Requests)) + "-" + buildDescription.Strategy.String()
}

// GetComparedTargetsCachePath returns the cache path for a compared target graph result.
Expand All @@ -84,10 +84,10 @@ func GetChangedTargetsAndEdgesCachePath(remote, treehash1, treehash2 string, req
return filepath.Join("compared-targets-and-edges", ToShortRemote(remote), treehash1, treehash2) + HashRequestOptions(requestOptions)
}

// getReqsHash returns a fixed-length MD5 hash of the sorted request URLs.
// GetReqsHash returns a fixed-length MD5 hash of the sorted request URLs.
// Each URL's bytes are fed into the digest individually (no separator), matching
// the Java MessageDigest.update(str.getBytes()) per-string behavior.
func getReqsHash(requests []*tangopb.Request) string {
func GetReqsHash(requests []*tangopb.Request) string {
if len(requests) == 0 {
return ""
}
Expand Down
6 changes: 3 additions & 3 deletions core/common/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func TestGetGraphByTreeHash(t *testing.T) {

// Nil/empty options ⇒ legacy path (regression: cache compatibility).
got := GetGraphByTreeHash(remote, treehash, nil)
assert.Equal(t, filepath.Join("uber/tango", treehash), got)
assert.Equal(t, filepath.Join("graph", "uber/tango", treehash), got)
assert.Equal(t, got, GetGraphByTreeHash(remote, treehash, &pb.RequestOptions{}))

// Non-empty options ⇒ suffix appended; different lists ⇒ different keys.
Expand Down Expand Up @@ -94,7 +94,7 @@ func TestGetTreehashCachePath(t *testing.T) {
h := md5.New()
h.Write([]byte("custom://foo/bar"))
h.Write([]byte("github://org/repo/pull/1"))
want := filepath.Join("uber/tango", "treehash-map-deadbeef", fmt.Sprintf("%x", h.Sum(nil))) + "-" + pb.COMPUTATION_STRATEGY_INVALID.String()
want := filepath.Join("treehash", "uber/tango", "treehash-map-deadbeef", fmt.Sprintf("%x", h.Sum(nil))) + "-" + pb.COMPUTATION_STRATEGY_INVALID.String()
assert.Equal(t, want, got)
}

Expand Down Expand Up @@ -136,7 +136,7 @@ func TestGetReqsHash(t *testing.T) {
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
assert.Equal(t, tt.want, getReqsHash(tt.in))
assert.Equal(t, tt.want, GetReqsHash(tt.in))
})
}
}
Expand Down
Loading