Type target relay capability checks · Entire
Type target relay capability checks
Sessions
e062e0d13a64View transcript
Changes
5
internal
gitproto
- Atarget_features.go+35
- Atarget_features_test.go+31
planner
- Mplanner_test.go+7/-21
- Mrelay.go+6/-7
syncer
- Msyncer.go+3/-2
package gitproto
import (
"github.com/go-git/go-git/v6/plumbing/protocol/packp"
"github.com/go-git/go-git/v6/plumbing/protocol/packp/capability"
)
// TargetFeatures summarizes the receive-pack capabilities relevant to strategy
// selection and push behavior.
type TargetFeatures struct {
Known bool `json:"known"`
DeleteRefs bool `json:"delete_refs"`
NoThin bool `json:"no_thin"`
OFSDelta bool `json:"ofs_delta"`
ReportStatus bool `json:"report_status"`
Sideband bool `json:"sideband"`
Sideband64k bool `json:"sideband64k"`
}
// TargetFeaturesFromAdvRefs derives the target-side feature summary from a
// receive-pack advertisement.
func TargetFeaturesFromAdvRefs(adv *packp.AdvRefs) TargetFeatures {
if adv == nil || adv.Capabilities == nil {
return TargetFeatures{}
}
return TargetFeatures{
Known: true,
DeleteRefs: adv.Capabilities.Supports(capability.DeleteRefs),
NoThin: adv.Capabilities.Supports(capability.Capability("no-thin")),
OFSDelta: adv.Capabilities.Supports(capability.OFSDelta),
ReportStatus: adv.Capabilities.Supports(capability.ReportStatus),
Sideband: adv.Capabilities.Supports(capability.Sideband),
Sideband64k: adv.Capabilities.Supports(capability.Sideband64k),
}
}
package gitproto
import (
"testing"
"github.com/go-git/go-git/v6/plumbing/protocol/packp"
"github.com/go-git/go-git/v6/plumbing/protocol/packp/capability"
)
func TestTargetFeaturesFromAdvRefs(t *testing.T) {
adv := packp.NewAdvRefs()
_ = adv.Capabilities.Set(capability.DeleteRefs)
_ = adv.Capabilities.Set(capability.Capability("no-thin"))
_ = adv.Capabilities.Set(capability.OFSDelta)
_ = adv.Capabilities.Set(capability.ReportStatus)
_ = adv.Capabilities.Set(capability.Sideband64k)
got := TargetFeaturesFromAdvRefs(adv)
if !got.Known || !got.DeleteRefs || !got.NoThin || !got.OFSDelta || !got.ReportStatus || !got.Sideband64k {
t.Fatalf("unexpected target features: %+v", got)
}
if got.Sideband {
t.Fatalf("unexpected sideband feature: %+v", got)
}
}
func TestTargetFeaturesFromAdvRefsNil(t *testing.T) {
if got := TargetFeaturesFromAdvRefs(nil); got != (TargetFeatures{}) {
t.Fatalf("expected zero features for nil adv, got %+v", got)
}
}
// CanIncrementalRelay checks whether all plans are eligible for the incremental
// relay fast-path (fast-forward branch updates + new tag creates).
func CanIncrementalRelay(force, prune, dryRun bool, plans []BranchPlan, targetFeatures gitproto.TargetFeatures) (bool, string) {
if force || prune || dryRun {
return false, "incremental-disabled-by-force-prune-or-dry-run"
}
if len(plans) == 0 {
return false, "incremental-no-plans"
}
if !targetFeatures.Known {
return false, "incremental-missing-target-capabilities"
}
// additional logic...
}
// RelayFallbackReason returns the reason why relay was not used.
func RelayFallbackReason(force, prune, dryRun bool, plans []BranchPlan, targetFeatures gitproto.TargetFeatures) string {
if ok, reason := CanIncrementalRelay(force, prune, dryRun, plans, targetFeatures); ok {
return reason
}
// additional logic...
}