Add source-side Git protocol v2 sync · Entire
Add source-side Git protocol v2 sync
71d6275→main·
Soph·3mo ago·3 files·+644 added/-50 removed
Sessions
3759c319aa62View transcript
Changes
3
internal/syncer
Mintegration_test.go+274
Mprotocol_v2.go+354
Msyncer.go+16/-50
7 unmodified lines
8
9
10
11
12
13
14
3 unmodified lines
18
19
20
21
22
23
24
25
26
27
28
147 unmodified lines
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
160 unmodified lines
389
390
391
392
393
394
395
11 unmodified lines
407
408
409
410
411
412
413
414
415
416
417
418
419
420
87 unmodified lines
508
509
510
511
512
513
514
515
516
517
32 unmodified lines
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
1 unmodified line
585
586
587
588
589
590
591
592
593
594
27 unmodified lines
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
68 unmodified lines
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
7 unmodified lines
"net/http"
"net/http/httptest"
"os"
"sort"
"strings"
"sync"
"testing"
3 unmodified lines
"github.com/go-git/go-billy/v5/memfs"
git "github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/plumbing"
"github.com/go-git/go-git/v5/plumbing/format/packfile"
"github.com/go-git/go-git/v5/plumbing/format/pktline"
"github.com/go-git/go-git/v5/plumbing/object"
"github.com/go-git/go-git/v5/plumbing/protocol/packp"
"github.com/go-git/go-git/v5/plumbing/revlist"
"github.com/go-git/go-git/v5/plumbing/transport"
transportclient "github.com/go-git/go-git/v5/plumbing/transport/client"
transporthttp "github.com/go-git/go-git/v5/plumbing/transport/http"
147 unmodified lines
}
func TestRun_IntegrationProtocolV2Source(t *testing.T) {
sourceRepo, sourceFS := newSourceRepo(t)
makeCommits(t, sourceRepo, sourceFS, 4)
targetRepo, err := git.Init(memory.NewStorage(), nil)
if err != nil {
t.Fatalf("init target repo: %v", err)
}
sourceServer := newSmartHTTPRepoServerV2(t, sourceRepo)
targetServer := newSmartHTTPRepoServer(t, targetRepo)
defer sourceServer.Close()
defer targetServer.Close()
result, err := Run(context.Background(), Config{
Source: Endpoint{URL: sourceServer.RepoURL()},
Target: Endpoint{URL: targetServer.RepoURL()},
ProtocolMode: protocolModeV2,
})
if err != nil {
t.Fatalf("initial v2 sync failed: %v", err)
}
if result.Protocol != protocolModeV2 {
t.Fatalf("expected protocol v2, got %s", result.Protocol)
}
assertHeadsMatch(t, sourceRepo, targetRepo, testBranch)
sourceServer.ResetMetrics()
makeCommits(t, sourceRepo, sourceFS, 1)
result, err = Run(context.Background(), Config{
Source: Endpoint{URL: sourceServer.RepoURL()},
Target: Endpoint{URL: targetServer.RepoURL()},
ProtocolMode: protocolModeV2,
})
if err != nil {
t.Fatalf("resync v2 failed: %v", err)
}
if result.Protocol != protocolModeV2 {
t.Fatalf("expected protocol v2 on resync, got %s", result.Protocol)
}
if sourceServer.Haves(serviceUploadPack, metricPack) == 0 {
t.Fatalf("expected protocol v2 fetch to advertise haves on resync")
}
}
func TestRun_IntegrationTagsPruneAndForce(t *testing.T) {
sourceRepo, sourceFS := newSourceRepo(t)
makeCommits(t, sourceRepo, sourceFS, 2)
server *httptest.Server
repo *git.Repository
repoPath string
v2 bool
mu sync.Mutex
metrics []exchangeMetric
return s
}
func newSmartHTTPRepoServerV2(t *testing.T, repo *git.Repository) *smartHTTPRepoServer {
t.Helper()
s := newSmartHTTPRepoServer(t, repo)
s.v2 = true
return s
}
func (s *smartHTTPRepoServer) Close() {
s.server.Close()
}
func (s *smartHTTPRepoServer) handleInfoRefsV2(w http.ResponseWriter, r *http.Request) {
var buf bytes.Buffer
enc := pktline.NewEncoder(&buf)
lines := []string{
"version 2\n",
"ls-refs=unborn\n",
"fetch=thin-pack\n",
"agent=test-server\n",
}
for _, line := range lines {
if err := enc.EncodeString(line); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
}
if err := enc.Flush(); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
w.Header().Set("Content-Type", fmt.Sprintf("application/x-%s-advertisement", serviceUploadPack))
if _, err := w.Write(buf.Bytes()); err != nil {
s.t.Fatalf("write v2 advertised refs: %v", err)
}
s.recordMetric(serviceUploadPack, metricInfoRefs, 0, int64(buf.Len()), 0, 0)
}
func (s *smartHTTPRepoServer) handleUploadPackV2(w http.ResponseWriter, r *http.Request, body []byte) {
req, err := decodeV2TestCommandRequest(body)
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
s.handleUploadPackV2Fetch(w, req, body)
}
func (s *smartHTTPRepoServer) handleReceivePack(w http.ResponseWriter, r *http.Request) {
body, err := io.ReadAll(r.Body)
if err != nil {
}
}
}