From a148d8a6706a4f63f6057389421757ff45139812 Mon Sep 17 00:00:00 2001 From: Camden Cheek Date: Fri, 2 Aug 2024 14:11:32 -0600 Subject: [PATCH] Web: fix git blame for files that have `/stream/` in their path (#64230) The URL path for streaming blame is ambiguous when the file path contains `/stream/`. The pattern looks like `/blame/@/stream/file/path.txt`. However, if the file contains `/stream/`, the revision is matched greedily up until the last stream, so we end up with a revision that looks like `81af3g/stream/my/path`, which is in invalid revision that results in a 404. This makes the URL pattern unambiguous by adding a `/-/` element after the revision, which is not allowed in a revision name and acts as a path separator. So now, the pattern looks like `/blame/@/-/stream/file/path.txt`. Note, this is a public-facing breaking change, but I don't think it really matters since I don't expect any customers use our streaming blame API --- client/web/src/repo/blame/shared.ts | 4 ++-- cmd/frontend/internal/httpapi/httpapi.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/client/web/src/repo/blame/shared.ts b/client/web/src/repo/blame/shared.ts index a52225d6b1b..d901181573a 100644 --- a/client/web/src/repo/blame/shared.ts +++ b/client/web/src/repo/blame/shared.ts @@ -147,10 +147,10 @@ function fetchBlameHunks(repoName: string, revision: string, filePath: string): function fetchRawBlameHunks(repoName: string, revision: string, filePath: string): Observable { const repoAndRevisionPath = `/${repoName}${revision ? `@${revision}` : ''}` return new Observable(subscriber => { - fetchEventSource(`/.api/blame${repoAndRevisionPath}/stream/${filePath}`, { + fetchEventSource(`/.api/blame${repoAndRevisionPath}/-/stream/${filePath}`, { method: 'GET', headers: { - 'X-Requested-With': 'Sourcegraph', + ...window.context.xhrHeaders, 'X-Sourcegraph-Should-Trace': new URLSearchParams(window.location.search).get('trace') || 'false', }, async onopen(response) { diff --git a/cmd/frontend/internal/httpapi/httpapi.go b/cmd/frontend/internal/httpapi/httpapi.go index 30be44e02ea..08dd82608a1 100644 --- a/cmd/frontend/internal/httpapi/httpapi.go +++ b/cmd/frontend/internal/httpapi/httpapi.go @@ -160,7 +160,7 @@ func NewHandler( m.Path("/scip/upload").Methods("POST").Handler(handlers.NewCodeIntelUploadHandler(true)) m.Path("/scip/upload").Methods("HEAD").Handler(noopHandler) m.Path("/compute/stream").Methods("GET", "POST").Handler(handlers.NewComputeStreamHandler()) - m.Path("/blame/" + routevar.Repo + routevar.RepoRevSuffix + "/stream/{Path:.*}").Methods("GET").Handler(handleStreamBlame(logger, db, gitserver.NewClient("http.blamestream"))) + m.Path("/blame/" + routevar.Repo + routevar.RepoRevSuffix + "/-/stream/{Path:.*}").Methods("GET").Handler(handleStreamBlame(logger, db, gitserver.NewClient("http.blamestream"))) // Set up the src-cli version cache handler (this will effectively be a // no-op anywhere other than dot-com). m.Path("/src-cli/versions/{rest:.*}").Methods("GET", "POST").Handler(releasecache.NewHandler(logger))