sourcegraph/cmd/gitserver/internal/git/gitcli
Geoffrey Gilmore e19c22d0a9
gitserver: grpc: port GetBehindAhead from client to gitcli backend (#62212)
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:

```go
// 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
2024-05-02 11:25:54 -07:00
..
archivereader_test.go gitserver: Completely remove Archive path validation (#61985) 2024-04-18 16:04:28 +02:00
archivereader.go gitserver: Completely remove Archive path validation (#61985) 2024-04-18 16:04:28 +02:00
blame_test.go Improve git blame performance and fix previous commit location when file was renamed (#61577) 2024-04-05 11:26:21 +02:00
blame.go Improve git blame performance and fix previous commit location when file was renamed (#61577) 2024-04-05 11:26:21 +02:00
BUILD.bazel chore: Break dependency of internal/trace on conf (#62177) 2024-04-30 21:12:39 +02:00
clibackend.go Search: add rev:at.time() for searching a repo at a point in time (#61513) 2024-04-12 15:14:16 -06:00
command.go chore: Break dependency of internal/trace on conf (#62177) 2024-04-30 21:12:39 +02:00
config_test.go gitserver: Convert MergeBase client call to server-side (#58583) 2024-01-24 08:27:49 +01:00
config.go gitserver: Move observability to gitcli layer (#60393) 2024-02-15 17:48:46 +01:00
contributors_test.go gitserver: Convert ContributorCounts to gRPC (#61958) 2024-04-18 15:40:05 +02:00
contributors.go gitserver: Convert ContributorCounts to gRPC (#61958) 2024-04-18 15:40:05 +02:00
diff_test.go gitserver: Migrate Diff to gRPC call (#61938) 2024-04-18 15:14:14 +02:00
diff.go gitserver: Migrate Diff to gRPC call (#61938) 2024-04-18 15:14:14 +02:00
exec_test.go gitserver: Convert MergeBase client call to server-side (#58583) 2024-01-24 08:27:49 +01:00
exec.go gitserver: Convert ContributorCounts to gRPC (#61958) 2024-04-18 15:40:05 +02:00
head_test.go Replace all traditional for-loops (#60988) 2024-03-11 16:05:47 +02:00
head.go gitserver: Move observability to gitcli layer (#60393) 2024-02-15 17:48:46 +01:00
mergebase_test.go gitserver: Normalize revisionnotfound errors (#60392) 2024-02-14 15:08:58 +01:00
mergebase.go gitserver: Move observability to gitcli layer (#60393) 2024-02-15 17:48:46 +01:00
metrics.go gitserver: Convert MergeBase client call to server-side (#58583) 2024-01-24 08:27:49 +01:00
object_test.go gitserver: Modernize GetObject (#60537) 2024-02-15 21:09:48 +01:00
object.go gitserver: Modernize GetObject (#60537) 2024-02-15 21:09:48 +01:00
odb_test.go gitserver: grpc: port GetBehindAhead from client to gitcli backend (#62212) 2024-05-02 11:25:54 -07:00
odb.go gitserver: grpc: port GetBehindAhead from client to gitcli backend (#62212) 2024-05-02 11:25:54 -07:00
refs_test.go gitserver: Serve Refs via gRPC method (#60323) 2024-04-16 14:28:25 +02:00
refs.go gitserver: Serve Refs via gRPC method (#60323) 2024-04-16 14:28:25 +02:00
resolverevision_test.go gitserver: Migrate ResolveRevision to gRPC (#60495) 2024-02-15 20:16:30 +01:00
resolverevision.go gitserver: Modernize GetObject (#60537) 2024-02-15 21:09:48 +01:00
revattime_test.go Search: add rev:at.time() for searching a repo at a point in time (#61513) 2024-04-12 15:14:16 -06:00
revattime.go Search: add rev:at.time() for searching a repo at a point in time (#61513) 2024-04-12 15:14:16 -06:00
util_test.go Search: add rev:at.time() for searching a repo at a point in time (#61513) 2024-04-12 15:14:16 -06:00
util.go gitserver: Convert MergeBase client call to server-side (#58583) 2024-01-24 08:27:49 +01:00