Welcome to mirror list, hosted at ThFree Co, Russian Federation.

http_push.go « stats « git « internal - gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8601720e33de22c0913035cd72bcc7cdb479b163 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package stats

import (
	"context"
	"fmt"
	"io"

	"gitlab.com/gitlab-org/gitaly/v15/internal/git"
)

// HTTPPush hosts information about a typical HTTP-based push.
type HTTPPush struct {
	// SendPack is the upload of the packfile performed as part of the clone.
	SendPack HTTPSendPack
}

// PushCommand is a command updating remote references.
type PushCommand struct {
	// Reference is the reference that shall be updated.
	Reference git.ReferenceName
	// OldOID is the expected state of the reference before being updated.
	OldOID git.ObjectID
	// NewOID is the expected state of the reference after being updated.
	NewOID git.ObjectID
}

// PerformHTTPPush emulates a git-push(1) over the HTTP protocol.
func PerformHTTPPush(
	ctx context.Context,
	url, user, password string,
	objectHash git.ObjectHash,
	commands []PushCommand,
	packfile io.Reader,
	interactive bool,
) (HTTPPush, error) {
	printInteractive := func(format string, a ...interface{}) {
		if interactive {
			// Ignore any errors returned by this given that we only use it as a
			// debugging aid to write to stdout.
			fmt.Printf(format, a...)
		}
	}

	sendPack, err := performHTTPSendPack(ctx, url, user, password, objectHash,
		commands, packfile, printInteractive)
	if err != nil {
		return HTTPPush{}, ctxErr(ctx, err)
	}

	return HTTPPush{
		SendPack: sendPack,
	}, nil
}