honor committed ref topology in fetches · Entire

honor committed ref topology in fetches

625223c→main·

pfleidi·1mo ago·4 files·+42 added/-12 removed

Derive metadata fetch and mirror decisions from CommittedRefs.Primary instead of re-deriving the v1 branch name at each call site.

This keeps the v1.1 mirror plumbing aligned with the shared committed-ref topology.

Sessions

9f6cdebf67e3View transcript

Changes

4

9 unmodified lines
10
11
12
13
14
15
15
16
17
18
409 unmodified lines

428
429
430
431
431
432
433
434
435
436
437
438
30 unmodified lines

469
470
471
468
472
473
474
475

9 unmodified lines

"strings"
    "time"

"github.com/entireio/cli/cmd/entire/cli/checkpoint"
    "github.com/entireio/cli/cmd/entire/cli/checkpoint/remote"
    "github.com/entireio/cli/cmd/entire/cli/logging"
    "github.com/entireio/cli/cmd/entire/cli/paths"
    "github.com/entireio/cli/cmd/entire/cli/strategy"

"github.com/go-git/go-git/v6"
409 unmodified lines

}

func fetchMetadataFromOrigin(ctx context.Context, fopts fetchMetadataOpts) error {
    branchName := paths.MetadataBranchName
    refs := checkpoint.ResolveCommittedRefs(ctx)
    if !refs.Primary.IsBranch() {
        return fmt.Errorf("primary metadata ref %s is not a branch", refs.Primary)
    }
    branchName := refs.Primary.Short()

ctx, cancel := context.WithTimeout(ctx, 2*time.Minute)
    defer cancel()
30 unmodified lines

if err != nil {
        return fmt.Errorf("branch '%s' not found on origin: %w", branchName, err)
    }
    if err := strategy.SafelyAdvanceLocalRef(ctx, repo, plumbing.NewBranchReferenceName(branchName), remoteRef.Hash()); err != nil {
    if err := strategy.SafelyAdvanceLocalRef(ctx, repo, refs.Primary, remoteRef.Hash()); err != nil {
        return fmt.Errorf("failed to advance local %s branch: %w", branchName, err)
    }
    strategy.MirrorCommittedMetadataRefBestEffort(ctx, repo)
}

Mcmd/entire/cli/git_operations.go+7/-3

6 unmodified lines

7 8 9 10 11 12 12 13 14 15 87 unmodified lines

103 104 105 106 106 107 108 109 110 111 108 112 113 114 115 116 113 117 118 119 120 41 unmodified lines

162 163 164 161 165 166 167 168 5 unmodified lines

174 175 176 173 174 177 178 179 180 181

6 unmodified lines

"strings" "time"

"github.com/entireio/cli/cmd/entire/cli/checkpoint" "github.com/entireio/cli/cmd/entire/cli/checkpoint/remote" "github.com/entireio/cli/cmd/entire/cli/logging" "github.com/entireio/cli/cmd/entire/cli/paths" "github.com/entireio/cli/cmd/entire/cli/settings"

"github.com/go-git/go-git/v6/plumbing" 87 unmodified lines

// The fetch is unfiltered (NoFilter: true) because resume needs blob content // (transcripts, metadata JSON) — not just tree objects. func FetchMetadataBranch(ctx context.Context, remoteURL string) error { branchName := paths.MetadataBranchName refs := checkpoint.ResolveCommittedRefs(ctx) if !refs.Primary.IsBranch() { return fmt.Errorf("primary metadata ref %s is not a branch", refs.Primary) } branchName := refs.Primary.Short() tmpRef := FetchTmpRefPrefix + branchName srcRef := "refs/heads/" + branchName srcRef := refs.Primary.String()

if err := fetchURLIntoTmpRef(ctx, remoteURL, srcRef, tmpRef, "metadata branch", true); err != nil { return err } if err := PromoteTmpRefSafely(ctx, plumbing.ReferenceName(tmpRef), plumbing.NewBranchReferenceName(branchName), branchName); err != nil { if err := PromoteTmpRefSafely(ctx, plumbing.ReferenceName(tmpRef), refs.Primary, branchName); err != nil { return err }

41 unmodified lines

return fmt.Errorf("fetch %s from %s failed: %w", label, redactedURL, fetchErr) }

// fetchMetadataBranchIfMissing fetches the metadata branch from a URL only if it doesn't exist locally. // fetchMetadataBranchIfMissing fetches the primary metadata ref from a URL only if it doesn't exist locally. // This avoids network calls on every push — once the branch exists locally, this is a no-op. // Fetch failures are silently swallowed (returns nil): the push will handle creating the // branch on the remote. Only fatal errors (opening repo, creating local branch) are returned. 5 unmodified lines

defer repo.Close()

// Check if branch already exists locally - if so, nothing to do branchRef := plumbing.NewBranchReferenceName(paths.MetadataBranchName) if _, err := repo.Reference(branchRef, true); err == nil { refs := checkpoint.ResolveCommittedRefs(ctx) if _, err := repo.Reference(refs.Primary, true); err == nil { return nil // Branch exists locally, skip fetch } }

Mcmd/entire/cli/strategy/checkpoint_remote.go+11/-7

11 unmodified lines

12
13
14
15
16
17
17
18
19
20
453 unmodified lines

474
475
476
477
477
478
479
480
481

11 unmodified lines

"sync"
    "time"

"github.com/entireio/cli/cmd/entire/cli/checkpoint"
    "github.com/entireio/cli/cmd/entire/cli/checkpoint/remote"
    "github.com/entireio/cli/cmd/entire/cli/logging"
    "github.com/entireio/cli/cmd/entire/cli/paths"
    "github.com/entireio/cli/cmd/entire/cli/settings"
    "github.com/entireio/cli/perf"

453 unmodified lines

}

func mirrorSyncedMetadataBranch(ctx context.Context, repo *git.Repository, branchName string) {
    if branchName != paths.MetadataBranchName {
    refs := checkpoint.ResolveCommittedRefs(ctx)
    if !refs.Primary.IsBranch() || branchName != refs.Primary.Short() {
        return
    }
    MirrorCommittedMetadataRefBestEffort(ctx, repo)
}

Mcmd/entire/cli/strategy/push_common.go+3/-2

155 unmodified lines

156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182

155 unmodified lines

assert.Equal(t, newHash, got) // Not parallel: uses t.Chdir(). func TestMirrorCommittedMetadataRef_UsesProvidedRefs(t *testing.T) { repo := setupV1CustomRefRepo(t, "1.1") head, err := repo.Head() require.NoError(t, err)

primary := plumbing.NewBranchReferenceName("entire/checkpoints/custom") mirror := plumbing.ReferenceName("refs/entire/checkpoints/custom-read") require.NoError(t, repo.Storer.SetReference(plumbing.NewHashReference(primary, head.Hash())))

require.NoError(t, MirrorCommittedMetadataRef(t.Context(), repo, checkpoint.CommittedRefs{ Primary: primary, Read: mirror, Mirror: mirror, }))

ref, err := repo.Reference(mirror, true) require.NoError(t, err) assert.Equal(t, head.Hash(), ref.Hash()) }

// Not parallel: uses t.Chdir(). func TestMirrorCommittedMetadataRef_ReplacesLocallyAheadMirror(t *testing.T) { repo := setupV1CustomRefRepo(t, "1.1")