git_operations: simplify metadata-fetch options and reuse test helper · Entire

git_operations: simplify metadata-fetch options and reuse test helper

46c209c→main·Soph·1mo ago·2 files·+11 added/-37 removed

Cleanups from /simplify review (no behavior change):

Co-Authored-By: Claude Opus 4.8 (1M context) noreply@anthropic.com

Sessions

9bf304d541d6View transcript

Changes

2

409 unmodified lines

// Does NOT --unshallow: --unshallow is a global property of the clone, so on
// shallow checkpoint repos it would also deepen unrelated branches.
func FetchMetadataBranch(ctx context.Context) error {
    return fetchMetadataFromOrigin(ctx, fetchMetadataOpts{NoFilter: true})
}

// FetchMetadataTreeOnly fetches the entire/checkpoints/v1 commit+tree graph
// remote-tracking ref connected; git fetches incrementally, so after the first
// fetch only new commits/trees travel.
func FetchMetadataTreeOnly(ctx context.Context) error {
    return fetchMetadataFromOrigin(ctx, fetchMetadataOpts{})
}

type fetchMetadataOpts struct {
    NoFilter  bool
    Unshallow bool
}

func fetchMetadataFromOrigin(ctx context.Context, fopts fetchMetadataOpts) error {
    refs := checkpoint.ResolveCommittedRefs(ctx)
    if !refs.Primary.IsBranch() {
        return fmt.Errorf("primary metadata ref %s is not a branch", refs.Primary)
    }
    refSpec := fmt.Sprintf("+refs/heads/%s:refs/remotes/origin/%s", branchName, branchName)

output, fetchErr := remote.Fetch(ctx, remote.FetchOptions{
        Remote:    fetchTarget,
        RefSpecs:  []string{refSpec},
        NoTags:    true,
        NoFilter:  fopts.NoFilter,
        Unshallow: fopts.Unshallow,
    })
    if fetchErr != nil {
        if ctx.Err() == context.DeadlineExceeded {
            // Handle deadline exceeded error
        }
    }
}

// Code blocks and additional implementations