From 6dbe110ca0d00a0ff46ff35d4a432a2955d8bb23 Mon Sep 17 00:00:00 2001 From: Allison Browne Date: Thu, 15 Aug 2024 15:11:46 -0400 Subject: [PATCH] Add depth parameter --- internal/git/localrepo/remote.go | 7 +++++++ internal/gitaly/service/repository/fetch_remote.go | 1 + proto/go/gitalypb/repository.pb.go | 9 +++++++++ proto/repository.proto | 2 ++ 4 files changed, 19 insertions(+) diff --git a/internal/git/localrepo/remote.go b/internal/git/localrepo/remote.go index 696512afb5..f21182fadf 100644 --- a/internal/git/localrepo/remote.go +++ b/internal/git/localrepo/remote.go @@ -7,6 +7,7 @@ import ( "fmt" "io" "strings" + "strconv" "gitlab.com/gitlab-org/gitaly/v16/internal/git" "gitlab.com/gitlab-org/gitaly/v16/proto/go/gitalypb" @@ -62,6 +63,8 @@ type FetchOpts struct { Stderr io.Writer // DisableTransactions will disable the reference-transaction hook and atomic transactions. DisableTransactions bool + // depth specifies the depth of the fetch operation + Depth *int32 } // FetchFailedError indicates that the fetch has failed. @@ -215,6 +218,10 @@ func (opts FetchOpts) buildFlags() []git.Option { flags = append(flags, git.Flag{Name: "--porcelain"}) } + if opts.Depth != nil { + flags = append(flags, git.ValueFlag{Name: "--depth", Value: strconv.Itoa(int(*opts.Depth))}) + } + // Even if we ask Git to not print any output and to force-update branches it will still // compute whether branches have been force-updated only to discard that information again. // Let's ask it not to given that this check can be quite expensive. diff --git a/internal/gitaly/service/repository/fetch_remote.go b/internal/gitaly/service/repository/fetch_remote.go index 36e7663663..0aef306391 100644 --- a/internal/gitaly/service/repository/fetch_remote.go +++ b/internal/gitaly/service/repository/fetch_remote.go @@ -43,6 +43,7 @@ func (s *server) fetchRemoteAtomic(ctx context.Context, req *gitalypb.FetchRemot Stderr: &stderr, Force: req.Force, Prune: !req.NoPrune, + Depth: req.Depth, Tags: localrepo.FetchOptsTagsAll, Verbose: true, // Transactions are disabled during fetch operation because no references are updated when diff --git a/proto/go/gitalypb/repository.pb.go b/proto/go/gitalypb/repository.pb.go index 9408f3690f..9b043f2e22 100644 --- a/proto/go/gitalypb/repository.pb.go +++ b/proto/go/gitalypb/repository.pb.go @@ -961,6 +961,8 @@ type FetchRemoteRequest struct { // check_tags_changed defined whether to check if any tags were modified, // returning the result in the tags_changed field of FetchRemoteResponse. CheckTagsChanged bool `protobuf:"varint,11,opt,name=check_tags_changed,json=checkTagsChanged,proto3" json:"check_tags_changed,omitempty"` + // depth specifies the depth of the fetch operation. + Depth *int32 `protobuf:"varint,12,opt,name=depth,json=depth,proto3" json:"depth,omitempty"` } func (x *FetchRemoteRequest) Reset() { @@ -1058,6 +1060,13 @@ func (x *FetchRemoteRequest) GetCheckTagsChanged() bool { return false } +func (x *FetchRemoteRequest) GetDepth() *int32 { + if x != nil { + return x.Depth + } + return nil +} + // FetchRemoteResponse is a response for the FetchRemote RPC. type FetchRemoteResponse struct { state protoimpl.MessageState diff --git a/proto/repository.proto b/proto/repository.proto index d021f4499c..b3ff09ba20 100644 --- a/proto/repository.proto +++ b/proto/repository.proto @@ -582,6 +582,8 @@ message FetchRemoteRequest { // check_tags_changed defined whether to check if any tags were modified, // returning the result in the tags_changed field of FetchRemoteResponse. bool check_tags_changed = 11; + // depth specifies the depth of the fetch operation. + int32 depth = 12; reserved 2; reserved "remote"; -- GitLab