# git: Add tree view support to Git Panel \(\#44089\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/9e628505f3c5aaee9cf59546af1d7c86111914d2)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: 9e628505f3c5aaee9cf59546af1d7c86111914d2

Requested commit: 9e628505f3c5aaee9cf59546af1d7c86111914d2

Commit: 9e628505f3c5aaee9cf59546af1d7c86111914d2

Tree: 3b24b3822fd2d8f065c819963ffb6da2bdd2bcc6

Author: Xipeng Jin

Committer: GitHub

## Message

```
git: Add tree view support to Git Panel (#44089)

Closes #35803

This PR adds tree view support to the git panel UI as an additional
setting and moves git entry checkboxes to the right. Tree view only
supports sorting by paths behavior since sorting by status can become
noisy, due to having to duplicate directories that have entries with
different statuses.

### Tree vs Flat View
<img width="358" height="250" alt="image"
src="https://github.com/user-attachments/assets/c6b95d57-12fc-4c5e-8537-ee129963e50c"
/>
<img width="362" height="152" alt="image"
src="https://github.com/user-attachments/assets/0a69e00f-3878-4807-ae45-65e2d54174fc"
/>


#### Architecture changes

Before this PR, `GitPanel::entries` represented all entries and all
visible entries because both sets were equal to one another. However,
this equality isn't true for tree view, because entries can be
collapsed. To fix this, `TreeState` was added as a logical indices field
that is used to filter out non-visible entries. A benefit of this field
is that it could be used in the future to implement searching in the
GitPanel.

Another significant thing this PR changed was adding a HashMap field
`entries_by_indices` on `GitPanel`. We did this because `entry_by_path`
used binary search, which becomes overly complicated to implement for
tree view. The performance of this function matters because it's a hot
code path, so a linear search wasn't ideal either. The solution was
using a hash map to improve time complexity from O(log n) to O(1), where
n is the count of entries.

#### Follow-ups
In the future, we could use `ui::ListItem` to render entries in the tree
view to improve UI consistency.
 
Release Notes:

- Added tree view for Git panel. Users are able to switch between Flat
and Tree view in Git panel.

---------

Co-authored-by: Anthony Eid <anthony@zed.dev>
Co-authored-by: Remco Smits <djsmits12@gmail.com>
```

## Parents

- [3a84ec38acaf1f1b884570ba0b31dc6771c4f8f7](https://git.cafe/gitcafe/zed/commit/3a84ec38acaf1f1b884570ba0b31dc6771c4f8f7?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/9e628505f3c5aaee9cf59546af1d7c86111914d2?format=markdown)
