portOffset returns a deterministic offset in [0, 1000) derived from the worktree path. Successive callers with the same projectRoot get the same offset; different projectRoots get different offsets with high probability.
(projectRoot string)
| 309 | // worktree path. Successive callers with the same projectRoot get the same |
| 310 | // offset; different projectRoots get different offsets with high probability. |
| 311 | func portOffset(projectRoot string) int { |
| 312 | h := fnv.New64a() |
| 313 | _, _ = h.Write([]byte(projectRoot)) |
| 314 | bucket := h.Sum64() % uint64(portOffsetBuckets) |
| 315 | return int(bucket) * portOffsetStep //nolint:gosec // Bucket is less than portOffsetBuckets. |
| 316 | } |
| 317 | |
| 318 | func (c *devConfig) applyPortOffset() { |
| 319 | c.portOffset = 0 |