Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 21 additions & 21 deletions cmd/frontend/db/schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -374,13 +374,13 @@ Indexes:
Column | Type | Modifiers
---------------+---------+-----------------------------------------------------------
id | integer | not null default nextval('lsif_commits_id_seq'::regclass)
repository | text | not null
commit | text | not null
parent_commit | text |
repository_id | integer | not null
Indexes:
"lsif_commits_pkey" PRIMARY KEY, btree (id)
"lsif_commits_repo_commit_parent_commit_unique" UNIQUE, btree (repository, commit, parent_commit)
"lsif_commits_parent_commit" btree (repository, parent_commit)
"lsif_commits_repository_id_commit_parent_commit_unique" UNIQUE, btree (repository_id, commit, parent_commit)
"lsif_commits_repository_id_parent_commit" btree (repository_id, parent_commit)
Check constraints:
"lsif_commits_commit_valid_chars" CHECK (commit ~ '^[a-z0-9]{40}$'::text)
"lsif_commits_parent_commit_valid_chars" CHECK (parent_commit ~ '^[a-z0-9]{40}$'::text)
Expand Down Expand Up @@ -424,30 +424,30 @@ Foreign-key constraints:

# Table "public.lsif_uploads"
```
Column | Type | Modifiers
--------------------+--------------------------+---------------------------------------------------------
id | integer | not null default nextval('lsif_dumps_id_seq'::regclass)
repository | text | not null
commit | text | not null
root | text | not null default ''::text
visible_at_tip | boolean | not null default false
uploaded_at | timestamp with time zone | not null default now()
filename | text | not null
state | lsif_upload_state | not null default 'queued'::lsif_upload_state
failure_summary | text |
failure_stacktrace | text |
started_at | timestamp with time zone |
finished_at | timestamp with time zone |
tracing_context | text | not null
Column | Type | Modifiers
---------------------------+--------------------------+---------------------------------------------------------
id | integer | not null default nextval('lsif_dumps_id_seq'::regclass)
repository_name_at_upload | text | not null
commit | text | not null
root | text | not null default ''::text
visible_at_tip | boolean | not null default false
uploaded_at | timestamp with time zone | not null default now()
filename | text | not null
state | lsif_upload_state | not null default 'queued'::lsif_upload_state
failure_summary | text |
failure_stacktrace | text |
started_at | timestamp with time zone |
finished_at | timestamp with time zone |
tracing_context | text | not null
repository_id | integer | not null
Indexes:
"lsif_uploads_pkey" PRIMARY KEY, btree (id)
"lsif_uploads_repository_commit_root" UNIQUE, btree (repository, commit, root) WHERE state = 'completed'::lsif_upload_state
"lsif_uploads_repository_id_commit_root" UNIQUE, btree (repository_id, commit, root) WHERE state = 'completed'::lsif_upload_state
"lsif_uploads_state" btree (state)
"lsif_uploads_uploaded_at" btree (uploaded_at)
"lsif_uploads_visible_repository_commit" btree (repository, commit) WHERE visible_at_tip
"lsif_uploads_visible_repository_id_commit" btree (repository_id, commit) WHERE visible_at_tip
Check constraints:
"lsif_uploads_commit_valid_chars" CHECK (commit ~ '^[a-z0-9]{40}$'::text)
"lsif_uploads_repository_check" CHECK (repository <> ''::text)
Referenced by:
TABLE "lsif_packages" CONSTRAINT "lsif_packages_dump_id_fkey" FOREIGN KEY (dump_id) REFERENCES lsif_uploads(id) ON DELETE CASCADE
TABLE "lsif_references" CONSTRAINT "lsif_references_dump_id_fkey" FOREIGN KEY (dump_id) REFERENCES lsif_uploads(id) ON DELETE CASCADE
Expand Down
5 changes: 3 additions & 2 deletions cmd/frontend/graphqlbackend/codeintel.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

graphql "github.com/graph-gophers/graphql-go"
"github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil"
"github.com/sourcegraph/sourcegraph/internal/api"
)

// NewCodeIntelResolver will be set by enterprise
Expand Down Expand Up @@ -34,7 +35,6 @@ type LSIFRepositoryUploadsQueryArgs struct {
type LSIFUploadResolver interface {
ID() graphql.ID
ProjectRoot(ctx context.Context) (*GitTreeEntryResolver, error)
InputRepoName() string
InputCommit() string
InputRoot() string
State() string
Expand Down Expand Up @@ -64,7 +64,8 @@ type LSIFQueryResolver interface {
}

type LSIFQueryArgs struct {
RepoName string
RepoID api.RepoID
RepoName api.RepoName
Commit GitObjectID
Path string
UploadID int64
Expand Down
3 changes: 2 additions & 1 deletion cmd/frontend/graphqlbackend/git_tree_entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,8 @@ func (r *GitTreeEntryResolver) LSIF(ctx context.Context) (LSIFQueryResolver, err
}

return EnterpriseResolvers.codeIntelResolver.LSIF(ctx, &LSIFQueryArgs{
RepoName: r.Repository().Name(),
RepoID: r.Repository().Type().ID,
RepoName: r.Repository().Type().Name,
Commit: r.Commit().OID(),
Path: r.Path(),
})
Expand Down
3 changes: 0 additions & 3 deletions cmd/frontend/graphqlbackend/schema.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions cmd/frontend/graphqlbackend/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -4169,9 +4169,6 @@ type LSIFUpload implements Node {
# The project for which this upload provides code intelligence.
projectRoot: GitTree

# The original repository name supplied at upload time.
inputRepoName: String!

# The original 40-character commit commit supplied at upload time.
inputCommit: String!

Expand Down
40 changes: 28 additions & 12 deletions enterprise/internal/codeintel/lsifserver/client/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,19 @@ import (

"github.com/sourcegraph/go-lsp"
"github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend"
"github.com/sourcegraph/sourcegraph/internal/api"
"github.com/sourcegraph/sourcegraph/internal/lsif"
)

func (c *Client) Exists(ctx context.Context, args *struct {
RepoName string
RepoID api.RepoID
RepoName api.RepoName
Commit string
Path string
}) (*lsif.LSIFUpload, error) {
query := queryValues{}
query.Set("repository", args.RepoName)
query.SetInt("repositoryId", int64(args.RepoID))
query.Set("repositoryName", string(args.RepoName))
query.Set("commit", args.Commit)
query.Set("path", args.Path)

Expand All @@ -39,15 +42,17 @@ func (c *Client) Exists(ctx context.Context, args *struct {
}

func (c *Client) Upload(ctx context.Context, args *struct {
RepoName string
RepoID api.RepoID
RepoName api.RepoName
Commit graphqlbackend.GitObjectID
Root string
Blocking *bool
MaxWait *int32
Body io.ReadCloser
}) (int64, bool, error) {
query := queryValues{}
query.Set("repository", args.RepoName)
query.SetInt("repositoryId", int64(args.RepoID))
query.Set("repositoryName", string(args.RepoName))
query.Set("commit", string(args.Commit))
query.Set("root", args.Root)
query.SetOptionalBool("blocking", args.Blocking)
Expand All @@ -70,10 +75,12 @@ func (c *Client) Upload(ctx context.Context, args *struct {
}

return payload.ID, meta.statusCode == http.StatusAccepted, nil

}

func (c *Client) Definitions(ctx context.Context, args *struct {
RepoName string
RepoID api.RepoID
RepoName api.RepoName
Commit graphqlbackend.GitObjectID
Path string
Line int32
Expand All @@ -82,7 +89,8 @@ func (c *Client) Definitions(ctx context.Context, args *struct {
}) ([]*lsif.LSIFLocation, string, error) {
return c.locationQuery(ctx, &struct {
Operation string
RepoName string
RepoID api.RepoID
RepoName api.RepoName
Commit graphqlbackend.GitObjectID
Path string
Line int32
Expand All @@ -92,6 +100,7 @@ func (c *Client) Definitions(ctx context.Context, args *struct {
Cursor *string
}{
Operation: "definitions",
RepoID: args.RepoID,
RepoName: args.RepoName,
Commit: args.Commit,
Path: args.Path,
Expand All @@ -102,7 +111,8 @@ func (c *Client) Definitions(ctx context.Context, args *struct {
}

func (c *Client) References(ctx context.Context, args *struct {
RepoName string
RepoID api.RepoID
RepoName api.RepoName
Commit graphqlbackend.GitObjectID
Path string
Line int32
Expand All @@ -113,7 +123,8 @@ func (c *Client) References(ctx context.Context, args *struct {
}) ([]*lsif.LSIFLocation, string, error) {
return c.locationQuery(ctx, &struct {
Operation string
RepoName string
RepoID api.RepoID
RepoName api.RepoName
Commit graphqlbackend.GitObjectID
Path string
Line int32
Expand All @@ -123,6 +134,7 @@ func (c *Client) References(ctx context.Context, args *struct {
Cursor *string
}{
Operation: "references",
RepoID: args.RepoID,
RepoName: args.RepoName,
Commit: args.Commit,
Path: args.Path,
Expand All @@ -136,7 +148,8 @@ func (c *Client) References(ctx context.Context, args *struct {

func (c *Client) locationQuery(ctx context.Context, args *struct {
Operation string
RepoName string
RepoID api.RepoID
RepoName api.RepoName
Commit graphqlbackend.GitObjectID
Path string
Line int32
Expand All @@ -146,7 +159,8 @@ func (c *Client) locationQuery(ctx context.Context, args *struct {
Cursor *string
}) ([]*lsif.LSIFLocation, string, error) {
query := queryValues{}
query.Set("repository", args.RepoName)
query.SetInt("repositoryId", int64(args.RepoID))
query.Set("repositoryName", string(args.RepoName))
query.Set("commit", string(args.Commit))
query.Set("path", args.Path)
query.SetInt("line", int64(args.Line))
Expand All @@ -173,15 +187,17 @@ func (c *Client) locationQuery(ctx context.Context, args *struct {
}

func (c *Client) Hover(ctx context.Context, args *struct {
RepoName string
RepoID api.RepoID
RepoName api.RepoName
Commit graphqlbackend.GitObjectID
Path string
Line int32
Character int32
UploadID int64
}) (string, lsp.Range, error) {
query := queryValues{}
query.Set("repository", args.RepoName)
query.SetInt("repositoryId", int64(args.RepoID))
query.Set("repositoryName", string(args.RepoName))
query.Set("commit", string(args.Commit))
query.Set("path", args.Path)
query.SetInt("line", int64(args.Line))
Expand Down
7 changes: 4 additions & 3 deletions enterprise/internal/codeintel/lsifserver/client/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ package client
import (
"context"
"fmt"
"net/url"
"strings"

"github.com/sourcegraph/sourcegraph/internal/api"
"github.com/sourcegraph/sourcegraph/internal/lsif"
)

func (c *Client) GetUploads(ctx context.Context, args *struct {
RepoName string
RepoID api.RepoID
RepoName api.RepoName
Query *string
State *string
IsLatestForRepo *bool
Expand All @@ -27,7 +28,7 @@ func (c *Client) GetUploads(ctx context.Context, args *struct {
}

req := &lsifRequest{
path: fmt.Sprintf("/uploads/%s", url.PathEscape(args.RepoName)),
path: fmt.Sprintf("/uploads/repository/%d", args.RepoID),
cursor: args.Cursor,
query: query,
}
Expand Down
22 changes: 13 additions & 9 deletions enterprise/internal/codeintel/lsifserver/proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/sourcegraph/sourcegraph/cmd/frontend/backend"
"github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend"
"github.com/sourcegraph/sourcegraph/cmd/frontend/httpapi"
"github.com/sourcegraph/sourcegraph/cmd/frontend/types"
"github.com/sourcegraph/sourcegraph/enterprise/internal/codeintel/lsifserver"
"github.com/sourcegraph/sourcegraph/enterprise/internal/codeintel/lsifserver/client"
"github.com/sourcegraph/sourcegraph/internal/api"
Expand Down Expand Up @@ -43,7 +44,8 @@ func uploadProxyHandler(p *httputil.ReverseProxy) func(http.ResponseWriter, *htt
root := q.Get("root")
ctx := r.Context()

if !ensureRepoAndCommitExist(ctx, w, repoName, commit) {
repo, ok := ensureRepoAndCommitExist(ctx, w, repoName, commit)
if !ok {
return
}

Expand All @@ -55,14 +57,16 @@ func uploadProxyHandler(p *httputil.ReverseProxy) func(http.ResponseWriter, *htt
}

uploadID, queued, err := client.DefaultClient.Upload(ctx, &struct {
RepoName string
RepoID api.RepoID
RepoName api.RepoName
Commit graphqlbackend.GitObjectID
Root string
Blocking *bool
MaxWait *int32
Body io.ReadCloser
}{
RepoName: repoName,
RepoID: repo.ID,
RepoName: repo.Name,
Commit: graphqlbackend.GitObjectID(commit),
Root: root,
Body: r.Body,
Expand Down Expand Up @@ -90,29 +94,29 @@ func uploadProxyHandler(p *httputil.ReverseProxy) func(http.ResponseWriter, *htt
}
}

func ensureRepoAndCommitExist(ctx context.Context, w http.ResponseWriter, repoName, commit string) bool {
func ensureRepoAndCommitExist(ctx context.Context, w http.ResponseWriter, repoName, commit string) (*types.Repo, bool) {
repo, err := backend.Repos.GetByName(ctx, api.RepoName(repoName))
if err != nil {
if errcode.IsNotFound(err) {
http.Error(w, fmt.Sprintf("unknown repository %q", repoName), http.StatusNotFound)
return false
return nil, false
}

http.Error(w, err.Error(), http.StatusInternalServerError)
return false
return nil, false
}

if _, err := backend.Repos.ResolveRev(ctx, repo, commit); err != nil {
if gitserver.IsRevisionNotFound(err) {
http.Error(w, fmt.Sprintf("unknown commit %q", commit), http.StatusNotFound)
return false
return nil, false
}

http.Error(w, err.Error(), http.StatusInternalServerError)
return false
return nil, false
}

return true
return repo, true
}

func enforceAuth(ctx context.Context, w http.ResponseWriter, r *http.Request, repoName string) bool {
Expand Down
Loading