Skip to content

Commit 0703af1

Browse files
yiling.jiYiling-J
authored andcommitted
Merge branch 'fix/lfs_tree_same_oid' into 'main'
Fix tree v2 API same oid lfs info missing See merge request product/starhub/starhub-server!871
1 parent ac80551 commit 0703af1

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

builder/git/gitserver/gitaly/file.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ func (c *Client) getBlobInfo(ctx context.Context, repo *gitalypb.Repository, pat
385385
if err != nil {
386386
return nil, err
387387
}
388-
oidFiles := map[string]*types.File{}
388+
oidFiles := map[string][]*types.File{}
389389
for {
390390
listBlobResp, err := listBlobsStream.Recv()
391391
if err != nil {
@@ -421,7 +421,7 @@ func (c *Client) getBlobInfo(ctx context.Context, repo *gitalypb.Repository, pat
421421
LfsRelativePath: LfsRelativePath,
422422
}
423423
if listBlobResp.Oid != "" && fileSize < lfsMaxPointerSize {
424-
oidFiles[listBlobResp.Oid] = file
424+
oidFiles[listBlobResp.Oid] = append(oidFiles[listBlobResp.Oid], file)
425425
}
426426
files = append(files, file)
427427
}
@@ -454,12 +454,13 @@ func (c *Client) getBlobInfo(ctx context.Context, repo *gitalypb.Repository, pat
454454
for _, pointer := range pointers {
455455
p, _ := ReadPointerFromBuffer(pointer.Data)
456456
if p.Valid() {
457-
file := oidFiles[string(pointer.Oid)]
458-
file.Size = p.Size
459-
file.Lfs = true
460-
file.SHA = p.Oid
461-
file.LfsRelativePath = p.RelativePath()
462-
file.LfsPointerSize = int(pointer.Size)
457+
for _, file := range oidFiles[string(pointer.Oid)] {
458+
file.Size = p.Size
459+
file.Lfs = true
460+
file.SHA = p.Oid
461+
file.LfsRelativePath = p.RelativePath()
462+
file.LfsPointerSize = int(pointer.Size)
463+
}
463464
}
464465
}
465466
}

builder/git/gitserver/gitaly/file_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,7 @@ func TestGitalyFile_GetTree(t *testing.T) {
590590
{Entries: []*gitalypb.TreeEntry{
591591
{Path: []byte(prefix + "a")},
592592
{Path: []byte(prefix + "b")},
593+
{Path: []byte(prefix + "c")},
593594
}, PaginationCursor: &gitalypb.PaginationCursor{NextCursor: "nc"}},
594595
},
595596
}, nil)
@@ -598,12 +599,14 @@ func TestGitalyFile_GetTree(t *testing.T) {
598599
RevisionPaths: []*gitalypb.GetBlobsRequest_RevisionPath{
599600
{Revision: "main", Path: []byte(prefix + "a")},
600601
{Revision: "main", Path: []byte(prefix + "b")},
602+
{Revision: "main", Path: []byte(prefix + "c")},
601603
},
602604
Limit: 0,
603605
}).Return(&MockGrpcStreamClient[*gitalypb.GetBlobsResponse]{
604606
data: []*gitalypb.GetBlobsResponse{
605607
{Path: []byte(prefix + "a"), Mode: 1, Oid: "o1"},
606608
{Path: []byte(prefix + "b"), Mode: 1, Oid: "o2"},
609+
{Path: []byte(prefix + "c"), Mode: 1, Oid: "o1"},
607610
},
608611
}, nil)
609612

@@ -643,6 +646,12 @@ size 507607173`
643646
LfsPointerSize: 1234,
644647
},
645648
{Name: "b", Path: prefix + "b", Type: "dir", Mode: "1", SHA: "o2"},
649+
{Name: "c", Path: prefix + "c", Type: "dir", Mode: "1",
650+
SHA: "a4f0e7e96b4f6af4a1b597c2fc4a42ec9a997c64ab7da96760c40582a0ac27a5",
651+
Lfs: true, Size: 507607173,
652+
LfsRelativePath: "a4/f0/e7e96b4f6af4a1b597c2fc4a42ec9a997c64ab7da96760c40582a0ac27a5",
653+
LfsPointerSize: 1234,
654+
},
646655
}, tree.Files)
647656
require.Equal(t, "nc", tree.Cursor)
648657
})

0 commit comments

Comments
 (0)