1
>
/*---------------------------------------------------------------------------------------------
gitDiffContent.ts
2
>
* Copyright (c) Microsoft Corporation. All rights reserved.
3
>
* Licensed under the MIT License. See License.txt in the project root for license information.
4
>
*--------------------------------------------------------------------------------------------*/
5
>
6
>
import { URI } from '../../../base/common/uri.js';
7
>
8
>
const GIT_BLOB_SCHEME = 'git-blob';
9
>
10
>
interface IGitBlobUriQuery {
11
>
readonly sessionUri: string;
12
>
readonly sha: string;
13
>
readonly repoRelativePath: string;
14
>
}
15
>
16
>
/**
17
>
* Builds a `git-blob:` URI that references a file blob at a specific git
18
>
* commit, scoped to a given session. Resolved by reading the session's
19
>
* working directory and shelling out to `git show <sha>:<path>`.
20
>
*
21
>
* The URI path is the absolute working-tree path so resource labels show a
22
>
* recognizable file path and so the "before" side lines up with the
23
>
* working-tree "after" side in diff editors. The session URI, SHA, and
24
>
* repository-relative path needed to fetch the blob are carried in the
25
>
* query.
26
>
*
27
>
* @param sessionUri Session the blob belongs to; used to find the working
28
>
* directory.
29
>
* @param sha Git commit/ref the blob is read from.
30
>
* @param repoRelativePath Repository-relative path passed to `git show`.
31
>
* @param absolutePath Absolute working-tree path used as the display path.
32
>
*/
33
>
export function buildGitBlobUri(sessionUri: string, sha: string, repoRelativePath: string, absolutePath: string): string {
34
return URI.from({
35
scheme: GIT_BLOB_SCHEME,