Sort file tree paths
Your task
A code review tool draws the file tree of a changeset. entries holds one path per touched item, and a directory always ends with a slash while a file never does. Return the same entries in the order the tree draws them. Order by path segments, splitting each path on the slash, rather than by the raw string. Segments compare as ordinary text, character by character, so capitals come before lowercase and 'v10' comes before 'v2'. When one path's segments are the leading segments of another, the shorter path comes first, which is what puts a directory immediately ahead of everything inside it. No name is both a file and a directory, so exactly one order satisfies the rule. An empty changeset returns an empty list.
Examples
order_tree_entries(entries: list[str]) -> list[str]Example 1
Input
order_tree_entries(["src.md", "src/", "src/app.ts", "src/app/", "src/app/main.ts", "README.md"])Output
["README.md", "src/", "src/app/", "src/app/main.ts", "src/app.ts", "src.md"]Example 2
Input
order_tree_entries(["docs/guide.md", "docs/", "docs/api/", "docs/api/v1.md", "LICENSE"])Output
["LICENSE", "docs/", "docs/api/", "docs/api/v1.md", "docs/guide.md"]