-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Modify Diff View FileTree to show all files
== Changes * removes Show Status button on diff * uses `git diff-tree` to generate the file tree for the diff
- Loading branch information
Showing
11 changed files
with
146 additions
and
154 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
export type File = { | ||
Name: string; | ||
NameHash: string; | ||
Status: FileStatus; | ||
IsViewed: boolean; | ||
IsSubmodule: boolean; | ||
} | ||
export type FileStatus = "added" | "modified" | "deleted" | "renamed" | "typechange"; | ||
|
||
export type Item = { | ||
name: string; | ||
path: string; | ||
isFile: boolean; | ||
file?: File; | ||
children?: Item[]; | ||
}; | ||
|
||
export function pathListToTree(fileEntries: File[]): Item[] { | ||
const pathToItem = new Map<string, Item>(); | ||
|
||
// init root node | ||
const root: Item = { name: '', path: '', isFile: false, children: [] }; | ||
pathToItem.set('', root); | ||
|
||
for (const fileEntry of fileEntries) { | ||
const [parentPath, fileName] = splitPathLast(fileEntry.Name); | ||
|
||
let parentItem = pathToItem.get(parentPath); | ||
if (!parentItem) { | ||
parentItem = constructParents(pathToItem, parentPath); | ||
} | ||
|
||
const fileItem: Item = { name: fileName, path: fileEntry.Name, isFile: true, file: fileEntry }; | ||
|
||
parentItem.children.push(fileItem); | ||
} | ||
|
||
return root.children; | ||
} | ||
|
||
|
||
function constructParents(pathToItem: Map<string, Item>, dirPath: string): Item { | ||
const [dirParentPath, dirName] = splitPathLast(dirPath); | ||
|
||
let parentItem = pathToItem.get(dirParentPath); | ||
if (!parentItem) { | ||
// if the parent node does not exist, create it | ||
parentItem = constructParents(pathToItem, dirParentPath); | ||
} | ||
|
||
const dirItem: Item = { name: dirName, path: dirPath, isFile: false, children: [] }; | ||
parentItem.children.push(dirItem); | ||
pathToItem.set(dirPath, dirItem); | ||
|
||
return dirItem; | ||
} | ||
|
||
function splitPathLast(path: string): [string, string] { | ||
const lastSlash = path.lastIndexOf('/'); | ||
return [path.substring(0, lastSlash), path.substring(lastSlash + 1)]; | ||
} | ||
|
||
export function mergeChildIfOnlyOneDir(nodes: Item[]): void { | ||
for (const node of nodes) { | ||
if (node.children) { | ||
mergeChildIfOnlyOneDir(node.children); | ||
} | ||
|
||
if (node.children?.length === 1 && node.children[0].children) { | ||
const child = node.children[0]; | ||
node.name = `${node.name}/${child.name}`; | ||
node.path = child.path; | ||
node.children = child.children; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.