Skip to content

Commit 0d22ba3

Browse files
authored
Git - 💄 remove duplicated code (microsoft#203609)
1 parent a19b2d5 commit 0d22ba3

File tree

1 file changed

+2
-68
lines changed

1 file changed

+2
-68
lines changed

extensions/git/src/git.ts

Lines changed: 2 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -994,13 +994,10 @@ function parseGitStashes(raw: string): Stash[] {
994994
return result;
995995
}
996996

997-
// TODO@lszomoru - adopt in diffFiles()
998997
function parseGitChanges(repositoryRoot: string, raw: string): Change[] {
999998
let index = 0;
1000999
const result: Change[] = [];
1001-
const segments = raw.trim()
1002-
.split('\x00')
1003-
.filter(s => s);
1000+
const segments = raw.trim().split('\x00').filter(s => s);
10041001

10051002
segmentsLoop:
10061003
while (index < segments.length - 1) {
@@ -1492,70 +1489,7 @@ export class Repository {
14921489
return [];
14931490
}
14941491

1495-
const entries = gitResult.stdout.split('\x00');
1496-
let index = 0;
1497-
const result: Change[] = [];
1498-
1499-
entriesLoop:
1500-
while (index < entries.length - 1) {
1501-
const change = entries[index++];
1502-
const resourcePath = entries[index++];
1503-
if (!change || !resourcePath) {
1504-
break;
1505-
}
1506-
1507-
const originalUri = Uri.file(path.isAbsolute(resourcePath) ? resourcePath : path.join(this.repositoryRoot, resourcePath));
1508-
let status: Status = Status.UNTRACKED;
1509-
1510-
// 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.
1511-
switch (change[0]) {
1512-
case 'M':
1513-
status = Status.MODIFIED;
1514-
break;
1515-
1516-
case 'A':
1517-
status = Status.INDEX_ADDED;
1518-
break;
1519-
1520-
case 'D':
1521-
status = Status.DELETED;
1522-
break;
1523-
1524-
// Rename contains two paths, the second one is what the file is renamed/copied to.
1525-
case 'R': {
1526-
if (index >= entries.length) {
1527-
break;
1528-
}
1529-
1530-
const newPath = entries[index++];
1531-
if (!newPath) {
1532-
break;
1533-
}
1534-
1535-
const uri = Uri.file(path.isAbsolute(newPath) ? newPath : path.join(this.repositoryRoot, newPath));
1536-
result.push({
1537-
uri,
1538-
renameUri: uri,
1539-
originalUri,
1540-
status: Status.INDEX_RENAMED
1541-
});
1542-
1543-
continue;
1544-
}
1545-
default:
1546-
// Unknown status
1547-
break entriesLoop;
1548-
}
1549-
1550-
result.push({
1551-
status,
1552-
originalUri,
1553-
uri: originalUri,
1554-
renameUri: originalUri,
1555-
});
1556-
}
1557-
1558-
return result;
1492+
return parseGitChanges(this.repositoryRoot, gitResult.stdout);
15591493
}
15601494

15611495
async getMergeBase(ref1: string, ref2: string): Promise<string | undefined> {

0 commit comments

Comments
 (0)