diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2020-12-21 08:53:20 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2021-01-06 12:55:59 +0300 |
commit | ced7db2422eae476589608386842fc3fc63c33b7 (patch) | |
tree | d6e9c18d06b628a75e763b0cf8b4e064fc42df23 | |
parent | 9d6087b7a19c59784fec3e3aebb6a85e07c272ca (diff) |
git: Convert `ReceivePackConfig()` to use command options
Now that it's possible to specify command-specific options which always
get applied, let's convert the `ReceivePackConfig()` function and move
it into the the "receive-pack" `gitCommand` structure.
-rw-r--r-- | internal/git/receivepack.go | 22 | ||||
-rw-r--r-- | internal/git/subcommand.go | 16 | ||||
-rw-r--r-- | internal/gitaly/service/smarthttp/inforefs.go | 3 | ||||
-rw-r--r-- | internal/gitaly/service/smarthttp/receive_pack.go | 6 | ||||
-rw-r--r-- | internal/gitaly/service/ssh/receive_pack.go | 6 |
5 files changed, 23 insertions, 30 deletions
diff --git a/internal/git/receivepack.go b/internal/git/receivepack.go deleted file mode 100644 index 67390908d..000000000 --- a/internal/git/receivepack.go +++ /dev/null @@ -1,22 +0,0 @@ -package git - -// ReceivePackConfig contains config options we want to enforce when -// receiving a push with git-receive-pack. -func ReceivePackConfig() []GlobalOption { - return []GlobalOption{ - // In case the repository belongs to an object pool, we want to prevent - // Git from including the pool's refs in the ref advertisement. We do - // this by rigging core.alternateRefsCommand to produce no output. - // Because Git itself will append the pool repository directory, the - // command ends with a "#". The end result is that Git runs `/bin/sh -c 'exit 0 # /path/to/pool.git`. - ConfigPair{Key: "core.alternateRefsCommand", Value: "exit 0 #"}, - - // In the past, there was a bug in git that caused users to - // create commits with invalid timezones. As a result, some - // histories contain commits that do not match the spec. As we - // fsck received packfiles by default, any push containing such - // a commit will be rejected. As this is a mostly harmless - // issue, we add the following flag to ignore this check. - ConfigPair{Key: "receive.fsck.badTimezone", Value: "ignore"}, - } -} diff --git a/internal/git/subcommand.go b/internal/git/subcommand.go index e10f370be..06cd5f291 100644 --- a/internal/git/subcommand.go +++ b/internal/git/subcommand.go @@ -105,6 +105,22 @@ var gitCommands = map[string]gitCommand{ }, "receive-pack": gitCommand{ flags: 0, + opts: []GlobalOption{ + // In case the repository belongs to an object pool, we want to prevent + // Git from including the pool's refs in the ref advertisement. We do + // this by rigging core.alternateRefsCommand to produce no output. + // Because Git itself will append the pool repository directory, the + // command ends with a "#". The end result is that Git runs `/bin/sh -c 'exit 0 # /path/to/pool.git`. + ConfigPair{Key: "core.alternateRefsCommand", Value: "exit 0 #"}, + + // In the past, there was a bug in git that caused users to + // create commits with invalid timezones. As a result, some + // histories contain commits that do not match the spec. As we + // fsck received packfiles by default, any push containing such + // a commit will be rejected. As this is a mostly harmless + // issue, we add the following flag to ignore this check. + ConfigPair{Key: "receive.fsck.badTimezone", Value: "ignore"}, + }, }, "remote": gitCommand{ flags: scNoEndOfOptions, diff --git a/internal/gitaly/service/smarthttp/inforefs.go b/internal/gitaly/service/smarthttp/inforefs.go index 65b3afbca..9d2c2edb1 100644 --- a/internal/gitaly/service/smarthttp/inforefs.go +++ b/internal/gitaly/service/smarthttp/inforefs.go @@ -48,13 +48,12 @@ func (s *server) handleInfoRefs(ctx context.Context, service string, req *gitaly return err } - var globalOpts []git.GlobalOption cmdOpts := []git.CmdOpt{git.WithGitProtocol(ctx, req)} if service == "receive-pack" { - globalOpts = append(globalOpts, git.ReceivePackConfig()...) cmdOpts = append(cmdOpts, git.WithRefTxHook(ctx, req.Repository, config.Config)) } + var globalOpts []git.GlobalOption if service == "upload-pack" { globalOpts = append(globalOpts, git.UploadPackFilterConfig()...) } diff --git a/internal/gitaly/service/smarthttp/receive_pack.go b/internal/gitaly/service/smarthttp/receive_pack.go index abb9f4453..f3f2bfb05 100644 --- a/internal/gitaly/service/smarthttp/receive_pack.go +++ b/internal/gitaly/service/smarthttp/receive_pack.go @@ -43,9 +43,9 @@ func (s *server) PostReceivePack(stream gitalypb.SmartHTTPService_PostReceivePac return err } - globalOpts := git.ReceivePackConfig() - for _, o := range req.GitConfigOptions { - globalOpts = append(globalOpts, git.ValueFlag{"-c", o}) + globalOpts := make([]git.GlobalOption, len(req.GitConfigOptions)) + for i, o := range req.GitConfigOptions { + globalOpts[i] = git.ValueFlag{"-c", o} } cmd, err := git.SafeBareCmd(ctx, nil, globalOpts, diff --git a/internal/gitaly/service/ssh/receive_pack.go b/internal/gitaly/service/ssh/receive_pack.go index cf6a5d2e4..4db9501ac 100644 --- a/internal/gitaly/service/ssh/receive_pack.go +++ b/internal/gitaly/service/ssh/receive_pack.go @@ -61,9 +61,9 @@ func (s *server) sshReceivePack(stream gitalypb.SSHService_SSHReceivePackServer, return err } - globalOpts := git.ReceivePackConfig() - for _, o := range req.GitConfigOptions { - globalOpts = append(globalOpts, git.ValueFlag{"-c", o}) + globalOpts := make([]git.GlobalOption, len(req.GitConfigOptions)) + for i, o := range req.GitConfigOptions { + globalOpts[i] = git.ValueFlag{"-c", o} } cmd, err := git.SafeBareCmd(ctx, nil, globalOpts, |