Share helpers that were copy-pasted across packages · Entire

Share helpers that were copy-pasted across packages

bd56544main·

Soph·2w ago·10 files·+163 added/-228 removed

- closeOnceReadCloser existed verbatim in the bootstrap, incremental, and replicate strategies; move it to gitproto as CloseOnce next to LimitPackReader (all strategies already depend on gitproto) and add the unit test it never had. - The byte formatter existed three times: syncer.formatBytes and bootstrap.humanBytes were identical, and gitproto.humanizeBytes was a slightly cruder variant (fixed one-decimal output, capped at GB). Keep the precision-tiered implementation as gitproto.HumanBytes and use it everywhere; pack-encode progress now formats like the rest of the progress output. - runSync and runReplicate carried the same plan-classification switch; extract classifyPlans. Replicate derives its relay subset from the returned push plans. - auth.Method duplicated gitproto.AuthMethod (identical single-method interfaces); alias it so the contract is declared once.

Co-Authored-By: Claude Fable 5 noreply@anthropic.com

Sessions

96d8a7027ab3View transcript

[?
/goal simplify this repo, make sure to de-slop it continue until you are happy, make sure to backfill tests and validate any significant change. The output of this should be a PR with green CI, reviewClaude Code·Opus 4.8[1m]·1 step](/content/gh/entireio/git-sync/session/1e0a84da-d36b-4e8a-925c-b32310479358#timeline-96d8a7027ab3/index.html)

Changes

10

2 unmodified lines

import (
    "context"
    "fmt"
    "net/http"
    "net/url"
    "os/exec"
    "strings"

transporthttp "github.com/go-git/go-git/v6/plumbing/transport/http"

"entire.io/entire/git-sync/internal/gitproto"
)

const defaultGitUsername = "git"

// Method authorizes outbound HTTP requests for a remote. It is satisfied
// by *transporthttp.BasicAuth and *transporthttp.TokenAuth, whose Authorizer
// methods replaced the Method interface that go-git removed in v6 alpha.2.
type Method interface {
    Authorizer(req *http.Request) error
}
// Method authorizes outbound HTTP requests for a remote. It aliases
// gitproto.AuthMethod so values returned by Resolve flow into gitproto
// connection constructors without conversion.
type Method = gitproto.AuthMethod

// Endpoint holds the authentication-related fields for a remote.
type Endpoint struct {
    ... // Further implementation details
}

LimitPackReader

// LimitPackReader wraps a ReadCloser with a byte limit. Shared across strategies.
func LimitPackReader(r io.ReadCloser, maxBytes int64) io.ReadCloser {
    if maxBytes <= 0 {
        return r
    }
    ... // Further implementation details
}

humanBytes

// humanizeBytes renders n in IEC units with one decimal place for KB+
func humanizeBytes(n int64) string {
    // Implementation details
}

ClassifyPlans Function

// classifyPlans splits planned actions into pushable plans, tallying skips and
// blocks into result.
func classifyPlans(plans []BranchPlan, dryRun bool, result *Result) []BranchPlan {
    // Implementation details
}

This is just a summary; detailed changes continue throughout the file.