Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

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

Merged
ggilmore merged 4 commits into
mainfrom
04-26-gitserver_grpc_port_getbehindahead_from_client_to_gitcli_backend
May 2, 2024
Merged

gitserver: grpc: port GetBehindAhead from client to gitcli backend#62212
ggilmore merged 4 commits into
mainfrom
04-26-gitserver_grpc_port_getbehindahead_from_client_to_gitcli_backend

Conversation

@ggilmore

@ggilmore ggilmore commented Apr 26, 2024

Copy link
Copy Markdown
Contributor

Part of https://github.com/sourcegraph/sourcegraph/issues/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

ggilmore commented Apr 26, 2024

Copy link
Copy Markdown
Contributor Author

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
Comment thread cmd/gitserver/internal/git/iface.go Outdated
Comment thread cmd/gitserver/internal/git/gitcli/odb_test.go Outdated
Comment thread cmd/gitserver/internal/git/gitcli/odb_test.go Outdated
Comment thread cmd/gitserver/internal/git/gitcli/odb.go Outdated
Comment thread cmd/gitserver/internal/git/gitcli/odb.go Outdated
@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 thread cmd/gitserver/internal/git/iface.go Outdated
Comment on lines 334 to 340

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

<3 for diagram!

@graphite-app

graphite-app Bot commented May 2, 2024

Copy link
Copy Markdown

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)

@graphite-app

graphite-app Bot commented May 2, 2024

Copy link
Copy Markdown

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
@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 https://github.com/sourcegraph/sourcegraph/issues/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 https://github.com/sourcegraph/sourcegraph/issues/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 subscribe to this conversation on GitHub. Already have an account? Sign in.

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.

2 participants