Skip to content

Commit aab2b74

Browse files
committed
Fixes oid vs ref on trees
1 parent 60ee143 commit aab2b74

File tree

6 files changed

+27
-22
lines changed

6 files changed

+27
-22
lines changed

src/env/node/git/git.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -539,8 +539,8 @@ export class Git {
539539
);
540540
}
541541

542-
async cat_file__size(repoPath: string, object: string): Promise<number> {
543-
const data = await this.git<string>({ cwd: repoPath }, 'cat-file', '-s', object);
542+
async cat_file__size(repoPath: string, oid: string): Promise<number> {
543+
const data = await this.git<string>({ cwd: repoPath }, 'cat-file', '-s', oid);
544544
return data.length ? parseInt(data.trim(), 10) : 0;
545545
}
546546

@@ -1343,13 +1343,13 @@ export class Git {
13431343

13441344
async log__find_object(
13451345
repoPath: string,
1346-
objectId: string,
1346+
oid: string,
13471347
ref: string,
13481348
ordering: 'date' | 'author-date' | 'topo' | null,
13491349
file?: string,
13501350
cancellation?: CancellationToken,
13511351
) {
1352-
const params = ['log', '-n1', '--no-renames', '--format=%H', `--find-object=${objectId}`, ref];
1352+
const params = ['log', '-n1', '--no-renames', '--format=%H', `--find-object=${oid}`, ref];
13531353

13541354
if (ordering) {
13551355
params.push(`--${ordering}-order`);

src/env/node/git/localGitProvider.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4844,25 +4844,26 @@ export class LocalGitProvider implements GitProvider, Disposable {
48444844
const [result] = parseGitLsFiles(data);
48454845
if (result == null) return undefined;
48464846

4847-
const size = await this.git.cat_file__size(repoPath, result.object);
4847+
const size = await this.git.cat_file__size(repoPath, result.oid);
48484848
return {
4849-
commitSha: ref,
4849+
ref: ref,
4850+
oid: result.oid,
48504851
path: relativePath,
48514852
size: size,
48524853
type: 'blob',
48534854
};
48544855
}
48554856

48564857
const data = await this.git.ls_tree(root, ref, relativePath);
4857-
return parseGitTree(data)[0];
4858+
return parseGitTree(data, ref)[0];
48584859
}
48594860

48604861
@log()
48614862
async getTreeForRevision(repoPath: string, ref: string): Promise<GitTreeEntry[]> {
48624863
if (repoPath == null) return [];
48634864

48644865
const data = await this.git.ls_tree(repoPath, ref);
4865-
return parseGitTree(data);
4866+
return parseGitTree(data, ref);
48664867
}
48674868

48684869
@log({ args: { 1: false } })

src/git/fsProvider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ export class GitFileSystemProvider implements FileSystemProvider, Disposable {
142142
const trees = await this.container.git.getTreeForRevision(repoPath, ref);
143143

144144
// Add a fake root folder so that searches will work
145-
searchTree.set('~', { commitSha: '', path: '~', size: 0, type: 'tree' });
145+
searchTree.set('~', { ref: '', oid: '', path: '~', size: 0, type: 'tree' });
146146
for (const item of trees) {
147147
searchTree.set(`~/${item.path}`, item);
148148
}

src/git/models/tree.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
export interface GitTreeEntry {
2-
commitSha: string;
2+
ref: string;
3+
oid: string;
34
path: string;
45
size: number;
56
type: 'blob' | 'tree';
67
}
78

89
export interface GitLsFilesEntry {
910
mode: string;
11+
oid: string;
1012
path: string;
11-
object: string;
1213
stage: number;
1314
}

src/git/parsers/treeParser.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ import type { GitLsFilesEntry, GitTreeEntry } from '../models/tree';
44
const treeRegex = /(?:.+?)\s+(.+?)\s+(.+?)\s+(.+?)\s+(.+)/gm;
55
const filesRegex = /^(\S+)\s+(\S+)\s+(\S+)\s+(.*)$/gm;
66

7-
export function parseGitTree(data: string | undefined): GitTreeEntry[] {
7+
export function parseGitTree(data: string | undefined, ref: string): GitTreeEntry[] {
88
using sw = maybeStopWatch(`Git.parseTree`, { log: false, logLevel: 'debug' });
99

1010
const trees: GitTreeEntry[] = [];
1111
if (!data) return trees;
1212

1313
let type;
14-
let sha;
14+
let oid;
1515
let size;
1616
let filePath;
1717

@@ -20,11 +20,12 @@ export function parseGitTree(data: string | undefined): GitTreeEntry[] {
2020
match = treeRegex.exec(data);
2121
if (match == null) break;
2222

23-
[, type, sha, size, filePath] = match;
23+
[, type, oid, size, filePath] = match;
2424

2525
trees.push({
26+
ref: ref,
2627
// Stops excessive memory usage -- https://bugs.chromium.org/p/v8/issues/detail?id=2869
27-
commitSha: sha == null || sha.length === 0 ? '' : ` ${sha}`.substr(1),
28+
oid: oid == null || oid.length === 0 ? '' : ` ${oid}`.substr(1),
2829
// Stops excessive memory usage -- https://bugs.chromium.org/p/v8/issues/detail?id=2869
2930
path: filePath == null || filePath.length === 0 ? '' : ` ${filePath}`.substr(1),
3031
size: Number(size) || 0,
@@ -46,23 +47,23 @@ export function parseGitLsFiles(data: string | undefined): GitLsFilesEntry[] {
4647

4748
let filePath;
4849
let mode;
49-
let object;
50+
let oid;
5051
let stage;
5152

5253
let match;
5354
do {
5455
match = filesRegex.exec(data);
5556
if (match == null) break;
5657

57-
[, mode, object, stage, filePath] = match;
58+
[, mode, oid, stage, filePath] = match;
5859

5960
files.push({
6061
// Stops excessive memory usage -- https://bugs.chromium.org/p/v8/issues/detail?id=2869
61-
path: filePath == null || filePath.length === 0 ? '' : ` ${filePath}`.substr(1),
62+
mode: mode == null || mode.length === 0 ? '' : ` ${mode}`.substr(1),
6263
// Stops excessive memory usage -- https://bugs.chromium.org/p/v8/issues/detail?id=2869
63-
object: object == null || object.length === 0 ? '' : ` ${object}`.substr(1),
64+
oid: oid == null || oid.length === 0 ? '' : ` ${oid}`.substr(1),
6465
// Stops excessive memory usage -- https://bugs.chromium.org/p/v8/issues/detail?id=2869
65-
mode: mode == null || mode.length === 0 ? '' : ` ${mode}`.substr(1),
66+
path: filePath == null || filePath.length === 0 ? '' : ` ${filePath}`.substr(1),
6667
stage: parseInt(stage, 10),
6768
});
6869
} while (true);

src/plus/integrations/providers/github/githubGitProvider.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2740,8 +2740,9 @@ export class GitHubGitProvider implements GitProvider, Disposable {
27402740
if (stats == null) return undefined;
27412741

27422742
return {
2743+
ref: ref,
2744+
oid: '',
27432745
path: this.getRelativePath(uri, repoPath),
2744-
commitSha: ref,
27452746
size: stats.size,
27462747
type: (stats.type & FileType.Directory) === FileType.Directory ? 'tree' : 'blob',
27472748
};
@@ -2772,8 +2773,9 @@ export class GitHubGitProvider implements GitProvider, Disposable {
27722773
// const stats = await workspace.fs.stat(uri);
27732774

27742775
result.push({
2776+
ref: ref,
2777+
oid: '',
27752778
path: this.getRelativePath(path, uri),
2776-
commitSha: ref,
27772779
size: 0, // stats?.size,
27782780
type: (type & FileType.Directory) === FileType.Directory ? 'tree' : 'blob',
27792781
});

0 commit comments

Comments
 (0)