Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gitserver: grpc: port GetBehindAhead from client to gitcli backend #62212

Conversation

ggilmore
Copy link
Contributor

@ggilmore ggilmore commented Apr 26, 2024

Part of #62101

This PR ports the GetBehindAhead implementation from the gitserver client to the new gitserver.Backend interface.

Here is the original implementation from the client for reference:

// GetBehindAhead returns the behind/ahead commit counts information for right vs. left (both Git
// revspecs).
func (c *clientImplementor) GetBehindAhead(ctx context.Context, repo api.RepoName, left, right string) (_ *gitdomain.BehindAhead, err error) {
	ctx, _, endObservation := c.operations.getBehindAhead.With(ctx, &err, observation.Args{
		MetricLabelValues: []string{c.scope},
		Attrs: []attribute.KeyValue{
			repo.Attr(),
			attribute.String("left", left),
			attribute.String("right", right),
		},
	})
	defer endObservation(1, observation.Args{})

	if err := checkSpecArgSafety(left); err != nil {
		return nil, err
	}
	if err := checkSpecArgSafety(right); err != nil {
		return nil, err
	}

	cmd := c.gitCommand(repo, "rev-list", "--count", "--left-right", fmt.Sprintf("%s...%s", left, right))
	out, err := cmd.Output(ctx)
	if err != nil {
		return nil, err
	}
	behindAhead := strings.Split(strings.TrimSuffix(string(out), "\n"), "\t")
	b, err := strconv.ParseUint(behindAhead[0], 10, 0)
	if err != nil {
		return nil, err
	}
	a, err := strconv.ParseUint(behindAhead[1], 10, 0)
	if err != nil {
		return nil, err
	}
	return &gitdomain.BehindAhead{Behind: uint32(b), Ahead: uint32(a)}, nil
}

Test plan

New unit tests

Copy link
Contributor Author

ggilmore commented Apr 26, 2024

This stack of pull requests is managed by Graphite. Learn more about stacking.

Join @ggilmore and the rest of your teammates on Graphite Graphite

@github-actions github-actions bot added team/product-platform team/source Tickets under the purview of Source - the one Source to graph it all labels Apr 26, 2024
@ggilmore ggilmore force-pushed the 04-24-gitserver_grpc_switch_clientimplementor_to_use_grpc_for_firstevercommit branch from 4c62a2d to 0b1fc2f Compare April 26, 2024 20:50
@ggilmore ggilmore force-pushed the 04-26-gitserver_grpc_port_getbehindahead_from_client_to_gitcli_backend branch from c9d4412 to e20d95c Compare April 26, 2024 20:50
@ggilmore ggilmore marked this pull request as ready for review April 26, 2024 21:10
@ggilmore ggilmore force-pushed the 04-24-gitserver_grpc_switch_clientimplementor_to_use_grpc_for_firstevercommit branch from 0b1fc2f to ee4923f Compare April 26, 2024 21:12
@ggilmore ggilmore force-pushed the 04-26-gitserver_grpc_port_getbehindahead_from_client_to_gitcli_backend branch from e20d95c to 5b77abc Compare April 26, 2024 21:13
@ggilmore ggilmore force-pushed the 04-24-gitserver_grpc_switch_clientimplementor_to_use_grpc_for_firstevercommit branch from ee4923f to f8bcb2d Compare April 26, 2024 21:19
@ggilmore ggilmore force-pushed the 04-26-gitserver_grpc_port_getbehindahead_from_client_to_gitcli_backend branch from 5b77abc to a20dd1b Compare April 26, 2024 21:19
@ggilmore ggilmore force-pushed the 04-24-gitserver_grpc_switch_clientimplementor_to_use_grpc_for_firstevercommit branch from f8bcb2d to 9e83fa2 Compare April 29, 2024 19:20
@ggilmore ggilmore force-pushed the 04-26-gitserver_grpc_port_getbehindahead_from_client_to_gitcli_backend branch from a20dd1b to 85215bf Compare April 29, 2024 19:20
@ggilmore ggilmore force-pushed the 04-26-gitserver_grpc_port_getbehindahead_from_client_to_gitcli_backend branch from 85215bf to ec4200b Compare April 30, 2024 05:16
@ggilmore ggilmore force-pushed the 04-24-gitserver_grpc_switch_clientimplementor_to_use_grpc_for_firstevercommit branch from 9e83fa2 to 5848e61 Compare April 30, 2024 05:19
@ggilmore ggilmore force-pushed the 04-26-gitserver_grpc_port_getbehindahead_from_client_to_gitcli_backend branch from ec4200b to 9cff9f2 Compare April 30, 2024 05:19
cmd/gitserver/internal/git/iface.go Outdated Show resolved Hide resolved
cmd/gitserver/internal/git/gitcli/odb_test.go Outdated Show resolved Hide resolved
cmd/gitserver/internal/git/gitcli/odb_test.go Outdated Show resolved Hide resolved
cmd/gitserver/internal/git/gitcli/odb.go Outdated Show resolved Hide resolved
cmd/gitserver/internal/git/gitcli/odb.go Outdated Show resolved Hide resolved
@ggilmore ggilmore force-pushed the 04-24-gitserver_grpc_switch_clientimplementor_to_use_grpc_for_firstevercommit branch from 5848e61 to e3f21ba Compare April 30, 2024 17:03
@ggilmore ggilmore force-pushed the 04-26-gitserver_grpc_port_getbehindahead_from_client_to_gitcli_backend branch from 9cff9f2 to e70c2b0 Compare April 30, 2024 17:03
@ggilmore ggilmore force-pushed the 04-24-gitserver_grpc_switch_clientimplementor_to_use_grpc_for_firstevercommit branch from e3f21ba to 1cbf637 Compare April 30, 2024 17:14
@ggilmore ggilmore force-pushed the 04-26-gitserver_grpc_port_getbehindahead_from_client_to_gitcli_backend branch from e70c2b0 to 2cc3609 Compare April 30, 2024 17:14
Comment on lines +334 to +340
// This is the commit graph we are creating
//
// +-----> 3 -----> 4 (branch1)
// |
// |
// 0 ----> 1 ----> 2 -----> 5 -----> 6 (master)
//
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<3 for diagram!

Copy link

graphite-app bot commented May 2, 2024

TV gif. Ty Burrell as Phil on Modern Family bites his lip as he gives a thumbs up, then points at us as he says, 'Yeah.' (Added via Giphy)

Copy link

graphite-app bot commented May 2, 2024

Graphite Automations

"Post a GIF when PR approved" took an action on this PR • (05/02/24)

1 gif was posted to this PR based on Geoffrey Gilmore's automation.

@ggilmore ggilmore force-pushed the 04-26-gitserver_grpc_port_getbehindahead_from_client_to_gitcli_backend branch from 3c51a0a to 16b66bb Compare May 2, 2024 17:43
@ggilmore ggilmore force-pushed the 04-26-gitserver_grpc_port_getbehindahead_from_client_to_gitcli_backend branch from 16b66bb to e036062 Compare May 2, 2024 18:04
@ggilmore ggilmore merged commit e19c22d into main May 2, 2024
15 checks passed
@ggilmore ggilmore deleted the 04-26-gitserver_grpc_port_getbehindahead_from_client_to_gitcli_backend branch May 2, 2024 18:25
ggilmore added a commit that referenced this pull request May 3, 2024
)

Part of #62101

This PR implements the server-side gRPC implementation of GetBehindAhead, and hooks it up to the new git Backend implementation from #62212.

## Test plan

Unit tests
burmudar pushed a commit that referenced this pull request May 6, 2024
)

Part of #62101

This PR implements the server-side gRPC implementation of GetBehindAhead, and hooks it up to the new git Backend implementation from #62212.

## Test plan

Unit tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla-signed team/product-platform team/source Tickets under the purview of Source - the one Source to graph it all
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants