Git - 💄 remove duplicated code (#203609)

This commit is contained in:
Ladislau Szomoru 2024-01-27 17:16:16 +01:00 committed by GitHub
parent a19b2d5fb0
commit 0d22ba354b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -994,13 +994,10 @@ function parseGitStashes(raw: string): Stash[] {
return result;
}
// TODO@lszomoru - adopt in diffFiles()
function parseGitChanges(repositoryRoot: string, raw: string): Change[] {
let index = 0;
const result: Change[] = [];
const segments = raw.trim()
.split('\x00')
.filter(s => s);
const segments = raw.trim().split('\x00').filter(s => s);
segmentsLoop:
while (index < segments.length - 1) {
@ -1492,70 +1489,7 @@ export class Repository {
return [];
}
const entries = gitResult.stdout.split('\x00');
let index = 0;
const result: Change[] = [];
entriesLoop:
while (index < entries.length - 1) {
const change = entries[index++];
const resourcePath = entries[index++];
if (!change || !resourcePath) {
break;
}
const originalUri = Uri.file(path.isAbsolute(resourcePath) ? resourcePath : path.join(this.repositoryRoot, resourcePath));
let status: Status = Status.UNTRACKED;
// Copy or Rename status comes with a number, e.g. 'R100'. We don't need the number, so we use only first character of the status.
switch (change[0]) {
case 'M':
status = Status.MODIFIED;
break;
case 'A':
status = Status.INDEX_ADDED;
break;
case 'D':
status = Status.DELETED;
break;
// Rename contains two paths, the second one is what the file is renamed/copied to.
case 'R': {
if (index >= entries.length) {
break;
}
const newPath = entries[index++];
if (!newPath) {
break;
}
const uri = Uri.file(path.isAbsolute(newPath) ? newPath : path.join(this.repositoryRoot, newPath));
result.push({
uri,
renameUri: uri,
originalUri,
status: Status.INDEX_RENAMED
});
continue;
}
default:
// Unknown status
break entriesLoop;
}
result.push({
status,
originalUri,
uri: originalUri,
renameUri: originalUri,
});
}
return result;
return parseGitChanges(this.repositoryRoot, gitResult.stdout);
}
async getMergeBase(ref1: string, ref2: string): Promise<string | undefined> {