Drop redundant protocol/mode defaulting from both clients · Entire

Drop redundant protocol/mode defaulting from both clients

9afed7d→main·

Soph·2w ago·2 files·+8 added/-36 removed

syncer.newSession already normalizes an empty protocol mode to auto and an empty operation mode to sync (and rejects unknown values), so the protocolString/operationModeString helpers in the stable and unstable clients were a third copy of the same defaulting. Pass the request values through unchanged.

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

Sessions

2c0d78a8a805View 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-2c0d78a8a805/index.html)

Changes

2

92 unmodified lines

93
94
95
96
96
97
98
99
26 unmodified lines

126
127
128
129
129
130
131
132
133
134
134
135
136
137
65 unmodified lines

203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
206
207
208

92 unmodified lines

AllRefs:            req.AllRefs,
        ExcludeRefPrefixes: append([]string(nil), req.ExcludeRefPrefixes...),
        ShowStats:          req.CollectStats,
        ProtocolMode:       protocolString(req.Protocol),
        ProtocolMode:       string(req.Protocol),
        }
    if req.Target != nil {
        targetAuth, err := c.authFor(ctx, *req.Target, TargetRole)
26 unmodified lines

IncludeTags:            req.Policy.IncludeTags,
        DryRun:                 dryRun,
        ShowStats:              req.CollectStats,
        Mode:                   operationModeString(req.Policy.Mode),
        Mode:                   string(req.Policy.Mode),
        ForceWithLease:         req.Policy.ForceWithLease,
        ForceBlind:             req.Policy.ForceBlind,
        Prune:                  req.Policy.Prune,
        BestEffort:             req.Policy.BestEffort,
        ProtocolMode:           protocolString(req.Policy.Protocol),
        ProtocolMode:           string(req.Policy.Protocol),
        MaterializedMaxObjects: syncer.DefaultMaterializedMaxObjects,
    }, nil
}

Mclient.go+3/-17

232 unmodified lines

233
234
235
236
236
237
238
239
32 unmodified lines

272
273
274
275
275
276
277
278
2 unmodified lines

281
282
283
284
284
285
286
287
24 unmodified lines

312
313
314
315
315
316
317
318
15 unmodified lines

334
335
336
337
337
338
339
340
17 unmodified lines

358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
361
362
363

232 unmodified lines

ShowStats:          req.Options.CollectStats,
        MeasureMemory:      req.Options.MeasureMemory,
        Progress:           req.Options.Progress,
        ProtocolMode:       protocolString(req.Protocol),
        ProtocolMode:       string(req.Protocol),
        Verbose:            req.Options.Verbose,
    }
    if req.Target != nil {
32 unmodified lines

ShowStats:              req.Options.CollectStats,
        MeasureMemory:          req.Options.MeasureMemory,
        Progress:               req.Options.Progress,
        Mode:                   operationModeString(req.Policy.Mode),
        Mode:                   string(req.Policy.Mode),
        ForceWithLease:         req.Policy.ForceWithLease,
        ForceBlind:             req.Policy.ForceBlind,
        Prune:                  req.Policy.Prune,
2 unmodified lines

TargetMaxPackBytes:     req.Options.TargetMaxPackBytes,
        TargetMaxRefUpdates:    req.Options.TargetMaxRefUpdates,
        MaterializedMaxObjects: maxObjects,
        ProtocolMode:           protocolString(req.Policy.Protocol),
        ProtocolMode:           string(req.Policy.Protocol),
        Verbose:                req.Options.Verbose,
        BootstrapStrategy:      req.Options.BootstrapStrategy,
    }, nil
24 unmodified lines

MaxPackBytes:        req.Options.MaxPackBytes,
        TargetMaxPackBytes:  req.Options.TargetMaxPackBytes,
        TargetMaxRefUpdates: req.Options.TargetMaxRefUpdates,
        ProtocolMode:        protocolString(req.Protocol),
        ProtocolMode:        string(req.Protocol),
        Verbose:             req.Options.Verbose,
        BootstrapStrategy:   req.Options.BootstrapStrategy,
    }, nil
15 unmodified lines

ShowStats:          req.Options.CollectStats,
        MeasureMemory:      req.Options.MeasureMemory,
        Progress:           req.Options.Progress,
        ProtocolMode:       protocolString(req.Protocol),
        ProtocolMode:       string(req.Protocol),
        Verbose:            req.Options.Verbose,
    }, nil
}

return syncerEndpoint(endpoint, auth), nil
}

func protocolString(mode ProtocolMode) string {
    if mode == "" {
        return string(ProtocolAuto)
    }
    return string(mode)
}

func operationModeString(mode OperationMode) string {
    if mode == "" {
        return string(ModeSync)
    }
    return string(mode)
}

func validateOperationMode(mode OperationMode) error {
    switch mode {
    case "", ModeSync, ModeReplicate: