mirror of
https://github.com/microsoft/vscode.git
synced 2026-07-08 15:55:15 +01:00
AgentHost - use git-blob only for the file content (#319901)
* AgentHost - use `git-blob` only for the file content * Fix unit tests * refactor: simplify return structure in parseGitDiffRawNumstat function
This commit is contained in:
@@ -788,27 +788,32 @@ export function parseGitDiffRawNumstat(output: string, repositoryRoot: URI, sess
|
||||
|
||||
return changes.map(change => {
|
||||
const stats = numStats.get(change.newPath ?? change.oldPath ?? '');
|
||||
const hasBefore = change.kind !== FileEditKind.Create;
|
||||
const hasAfter = change.kind !== FileEditKind.Delete;
|
||||
|
||||
const before = change.kind !== FileEditKind.Create && change.oldPath
|
||||
? {
|
||||
uri: URI.joinPath(repositoryRoot, change.oldPath).toString(),
|
||||
content: { uri: buildGitBlobUri(sessionUri, beforeRef, change.oldPath) },
|
||||
}
|
||||
: undefined;
|
||||
|
||||
const after = change.kind !== FileEditKind.Delete && change.newPath
|
||||
? {
|
||||
uri: URI.joinPath(repositoryRoot, change.newPath).toString(),
|
||||
content: afterRef !== undefined
|
||||
? { uri: buildGitBlobUri(sessionUri, afterRef, change.newPath) }
|
||||
: { uri: URI.joinPath(repositoryRoot, change.newPath).toString() }
|
||||
}
|
||||
: undefined;
|
||||
|
||||
const diff = {
|
||||
added: stats?.added ?? 0,
|
||||
removed: stats?.removed ?? 0
|
||||
};
|
||||
|
||||
return {
|
||||
...(hasBefore && change.oldPath ? {
|
||||
before: {
|
||||
uri: URI.joinPath(repositoryRoot, change.oldPath).toString(),
|
||||
content: { uri: buildGitBlobUri(sessionUri, beforeRef, change.oldPath) },
|
||||
},
|
||||
} : {}),
|
||||
...(hasAfter && change.newPath ? {
|
||||
after: afterRef !== undefined
|
||||
? {
|
||||
uri: buildGitBlobUri(sessionUri, afterRef, change.newPath),
|
||||
content: { uri: buildGitBlobUri(sessionUri, afterRef, change.newPath) },
|
||||
}
|
||||
: {
|
||||
uri: URI.joinPath(repositoryRoot, change.newPath).toString(),
|
||||
content: { uri: URI.joinPath(repositoryRoot, change.newPath).toString() },
|
||||
},
|
||||
} : {}),
|
||||
diff: { added: stats?.added ?? 0, removed: stats?.removed ?? 0 },
|
||||
...(before ? { before } : {}),
|
||||
...(after ? { after } : {}),
|
||||
diff
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
@@ -246,11 +246,11 @@ suite('AgentHostGitService', () => {
|
||||
assert.deepStrictEqual(diffs, [
|
||||
{
|
||||
before: { uri: 'file:///repo/modified.ts', content: { uri: buildGitBlobUri(sessionUri, sha, 'modified.ts') } },
|
||||
after: { uri: buildGitBlobUri(sessionUri, toSha, 'modified.ts'), content: { uri: buildGitBlobUri(sessionUri, toSha, 'modified.ts') } },
|
||||
after: { uri: 'file:///repo/modified.ts', content: { uri: buildGitBlobUri(sessionUri, toSha, 'modified.ts') } },
|
||||
diff: { added: 5, removed: 2 },
|
||||
},
|
||||
{
|
||||
after: { uri: buildGitBlobUri(sessionUri, toSha, 'added.ts'), content: { uri: buildGitBlobUri(sessionUri, toSha, 'added.ts') } },
|
||||
after: { uri: 'file:///repo/added.ts', content: { uri: buildGitBlobUri(sessionUri, toSha, 'added.ts') } },
|
||||
diff: { added: 10, removed: 0 },
|
||||
},
|
||||
{
|
||||
@@ -259,7 +259,7 @@ suite('AgentHostGitService', () => {
|
||||
},
|
||||
{
|
||||
before: { uri: 'file:///repo/old/path.ts', content: { uri: buildGitBlobUri(sessionUri, sha, 'old/path.ts') } },
|
||||
after: { uri: buildGitBlobUri(sessionUri, toSha, 'new/path.ts'), content: { uri: buildGitBlobUri(sessionUri, toSha, 'new/path.ts') } },
|
||||
after: { uri: 'file:///repo/new/path.ts', content: { uri: buildGitBlobUri(sessionUri, toSha, 'new/path.ts') } },
|
||||
diff: { added: 3, removed: 3 },
|
||||
},
|
||||
]);
|
||||
|
||||
Reference in New Issue
Block a user