Preflight large GitHub sources for batched bootstrap · Entire
Preflight large GitHub sources for batched bootstrap
06fd2be→main·
Soph·3mo ago·2 files·+186 added/-0 removed
Sessions
a69904c9f963View transcript
[?
can you look at the changes in this branch, I want to run the smoke test against a local entire using the linux repo. I did it run once before and it seems no matter what I do it just finishs quicklyCodex·GPT-5.4·1 step](/content/gh/entireio/git-sync/session/019d7739-95cb-79e3-9de4-3cbe15400b87#timeline-a69904c9f963/index.html)
Changes
2
internal/syncer
Msyncer.go+96
Msyncer_test.go+90
43 unmodified lines
44
45
46
47
48
49
50
51
52
53
54
893 unmodified lines
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
60 unmodified lines
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
43 unmodified lines
defaultAutoBatchMaxPackBytes = 512 * 1024 * 1024
entireCLIClientID = "entire-cli"
githubLargeRepoThresholdKB = 1536 * 1024
)
var bodyLimitPattern = regexp.MustCompile(`body exceeded size limit ([0-9]+)`)
var githubRepoAPIBaseURL = "https://api.github.com"
func githubBootstrapBatchMaxPackBytes(ctx context.Context, cfg Config, sourceConn *transportConn, sourceService *sourceRefService) (int64, bool) {
if cfg.BatchMaxPackBytes > 0 {
return 0, false
}
if sourceConn == nil || sourceConn.endpoint == nil {
return 0, false
}
if sourceService == nil || sourceService.protocol != protocolModeV2 || !fetchCapabilitySupports(sourceService.v2, "filter") {
return 0, false
}
repoSizeKB, ok := lookupGitHubRepoSizeKB(ctx, sourceConn)
if !ok || repoSizeKB < githubLargeRepoThresholdKB {
return 0, false
}
batchLimit := int64(defaultAutoBatchMaxPackBytes)
if cfg.MaxPackBytes > 0 && cfg.MaxPackBytes < batchLimit {
batchLimit = cfg.MaxPackBytes
}
if batchLimit <= 0 {
return 0, false
}
return batchLimit, true
}
func lookupGitHubRepoSizeKB(ctx context.Context, sourceConn *transportConn) (int64, bool) {
owner, repo, ok := githubOwnerRepo(sourceConn)
if !ok {
return 0, false
}
apiURL := strings.TrimRight(githubRepoAPIBaseURL, "/") + "/repos/" + owner + "/" + repo
req, err := http.NewRequestWithContext(ctx, http.MethodGet, apiURL, nil)
if err != nil {
return 0, false
}
req.Header.Set("Accept", "application/vnd.github+json")
req.Header.Set("X-GitHub-Api-Version", "2022-11-28")
req.Header.Set("User-Agent", capability.DefaultAgent())
req.Header.Set(statsPhaseHdr, "github repo metadata")
resp, err := sourceConn.http.Do(req)
if err != nil {
return 0, false
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return 0, false
}
var payload struct {
Size int64 `json:"size"`
}
if err := json.NewDecoder(resp.Body).Decode(&payload); err != nil {
return 0, false
}
if payload.Size <= 0 {
return 0, false
}
return payload.Size, true
}
func githubOwnerRepo(sourceConn *transportConn) (string, string, bool) {
if sourceConn == nil || sourceConn.endpoint == nil {
return "", "", false
}
ep := sourceConn.endpoint
if ep.Protocol != "http" && ep.Protocol != "https" {
return "", "", false
}
if !strings.EqualFold(ep.Host, "github.com") {
return "", "", false
}
path := strings.Trim(ep.Path, "/")
if strings.HasSuffix(path, ".git") {
path = strings.TrimSuffix(path, ".git")
}
parts := strings.Split(path, "/")
if len(parts) != 2 || parts[0] == "" || parts[1] == "" {
return "", "", false
}
return parts[0], parts[1], true
}
func isTargetBodyLimitError(err error) bool {
if err == nil {
return false
}