Drop redundant protocol/mode defaulting from both clients · Entire

Drop redundant protocol/mode defaulting from both clients

835ff84·

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

Changes

2

92 unmodified lines

93
94
95
96
96
97
98
99
25 unmodified lines

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

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

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)
25 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
    }
}

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:

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 gitsync.ProtocolMode) string {
    if mode == "" {
        return string(gitsync.ProtocolAuto)
    }
    return string(mode)
}

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

func syncerEndpoint(endpoint gitsync.Endpoint, auth gitsync.EndpointAuth) syncer.Endpoint {
    return syncer.Endpoint{
        URL:                    endpoint.URL,