MCPcopy Create free account
hub / github.com/cloudflare/artifact-fs / batchResolveSizes

Method batchResolveSizes

internal/gitstore/gitstore.go:370–429  ·  view source on GitHub ↗
(ctx context.Context, repo model.RepoConfig, nodes []model.BaseNode, oids []string, index map[string][]int)

Source from the content-addressed store, hash-verified

368 return model.PreparedSource{}, errors.New("source ref must be a canonical refs/... name")
369 }
370 if _, err := runGit(ctx, "", "check-ref-format", requirement.Ref); err != nil {
371 return model.PreparedSource{}, fmt.Errorf("invalid source ref %q", requirement.Ref)
372 }
373 if requirement.RequiredCommit == "" {
374 return model.PreparedSource{}, errors.New("required commit is required")
375 }
376 if requirement.Depth < 0 {
377 return model.PreparedSource{}, errors.New("history depth must not be negative")
378 }
379
380 prepared := model.PreparedSource{Ref: requirement.Ref, Commit: requirement.RequiredCommit, Verified: true}
381 if cfg.AcquiredRef == requirement.Ref && strings.EqualFold(cfg.AcquiredCommit, requirement.RequiredCommit) {
382 available, err := requiredCommitAvailable(ctx, cfg.GitDir, requirement.RequiredCommit)
383 if err != nil {
384 return model.PreparedSource{}, err
385 }
386 if available {
387 if err := prepareFixedHEAD(ctx, cfg.GitDir, requirement.RequiredCommit, false); err != nil {
388 return model.PreparedSource{}, err
389 }
390 return prepared, nil
391 }
392 }
393
394 parent := filepath.Dir(cfg.GitDir)
395 if err := os.MkdirAll(parent, 0o755); err != nil {
396 return model.PreparedSource{}, err
397 }
398 safeURL, credHelper, err := credentialEnv(cfg.RemoteURL)
399 if err != nil {
400 return model.PreparedSource{}, err
401 }
402 env := append(nonInteractiveGitEnv(), credHelper...)
403 var candidateGitDir string
404 attempt := func() error {
405 if candidateGitDir != "" {
406 _ = os.RemoveAll(candidateGitDir)
407 }
408 candidateGitDir, err = os.MkdirTemp(parent, ".source-*")
409 if err != nil {
410 return fmt.Errorf("mktemp source dir: %w", err)
411 }
412 initArgs := []string{"init", "--bare"}
413 if len(requirement.RequiredCommit) == 64 {
414 initArgs = append(initArgs, "--object-format=sha256")
415 }
416 initArgs = append(initArgs, candidateGitDir)
417 if _, err := runGitWithEnv(ctx, "", env, initArgs...); err != nil {
418 return err
419 }
420 // The Git directory is exposed through the mount's .git file, so Git
421 // must treat callers in the mounted directory as worktree operations.
422 if _, err := runGitWithEnv(ctx, candidateGitDir, env, "config", "core.bare", "false"); err != nil {
423 return err
424 }
425 if err := configureArtifactWorktree(ctx, candidateGitDir); err != nil {
426 return err
427 }

Callers 1

BuildTreeIndexMethod · 0.95

Calls 7

RedactStringFunction · 0.92
applyBatchCheckLineFunction · 0.85
ScanMethod · 0.80
WaitMethod · 0.80
StringMethod · 0.80
StartMethod · 0.45
CloseMethod · 0.45

Tested by

no test coverage detected