ADR-00050: A working tree holds a directory the view names, or one holding what is placed in it¶
| Field | Value |
|---|---|
| Status | accepted |
| Date | 2026-12-01 |
Context and Problem Statement¶
Revision 2738 set one rule for which directories an instance under a view holds: every directory the view keeps belongs in the working tree whatever it holds, as a file the view keeps does, and a directory the view excludes stands only as the parent of what is created below it. Clone, sync, branch switch, merge, sync --view, reset, layer add and link add follow it, and so do status --scan, lore dirty and lore stage, which take a missing kept directory for a deletion.
A view keeps a directory in two ways. It names it, with a rule such as !/Engine/Content/, and the author asks for that directory whatever the view does to its contents. Or no rule excludes it, and it is kept only implicitly: a view that leaves out files by pattern, such as /Plugins/**/*.uasset, excludes files and no directory, so every directory those files sit in is kept. Revision 2738 left out a directory the walk enters only because a re-inclusion could match below it, and holding nothing kept, but it created every kept directory, so under that pattern each of those directories was created and left empty. On a large production view of 1.1 million files, 3.2 of the 3.94 million directories in the working tree were empty for that reason. Each one costs an inode on disk and work in every operation that walks the working tree: a copy-on-write clone of the instance took 248 seconds, the first status --scan 107 seconds and an instance delete about 390 seconds. On a synthetic tree of 16,000 leaf directories holding 8,000 kept files under /Plugins/**/*.uasset, latest main at revision 2892 still creates 16,082 directories.
Creating every kept directory also puts on disk the names of folders the view gives no reason to show. A directory holding only content the view leaves out, such as a folder named for an unannounced platform, appears in the working tree, where file indexers, backups, logs and every tool that lists the tree read its name.
The question was which directories a working tree under a view holds.
Decision Drivers¶
- Directory count in a working tree drives the cost of clone, scan, copy-on-write instance clone and instance delete, and a pattern view can make most of the tree's directories empty.
- A view that names a directory asks for it, and gets it whatever the view does to what it holds.
- The working tree shows only names the view places or names, so a view that leaves out a subtree doesn't spread the names of the folders in it to the disk.
- One rule that every operation creating directories and every walk reporting a missing one agree on, so
statuslists no change after a clone, sync or switch. - An empty directory the revision tracks stays visible: a user who commits an empty directory gets it back.
- No change to the revision, the protocol or any stored format.
Considered Options¶
- Every directory the view keeps, whatever it holds (revision 2738).
- A directory only for what is placed in it, and for itself only where the view keeps it and the revision holds it empty.
- A directory for what is placed in it, and for itself where the view keeps it and either names it or the revision holds it empty.
- The rule of revision 2738, with a view option that leaves out kept directories holding nothing kept.
Decision Outcome¶
Chosen option: "A directory for what is placed in it, and for itself where the view keeps it and either names it or the revision holds it empty", because it removes the empty directories a pattern view leaves, keeps every directory a view asks for by name and every empty directory the revision tracks, and needs no option to learn. The second option dropped named directories too, so !/Engine/Content/ followed by /Engine/Content/* gave no Engine/Content.
A directory stands in the working tree where something is placed below it: a file the view keeps, a link or layer mount, or a directory that stands. A directory stands for itself where the view keeps it and either a rule of the view names it or the revision holds it empty. A directory the view excludes stands only as the parent of what is placed below it, named or not.
A rule names a directory where it is a re-inclusion that targets directories and matches the directory's path, and no exclusion after it matches the directory itself; below an excluded parent, only a rule a walk reads there counts: one at or after the line that decided the parent, and not a name rule (FilterInstance::names_directory_below). A rule targets directories where it ends in /, or where it is a path of literal components:
!/Engine/Content/and!/Engine/ContentnameEngine/Content.!/Plugins/*/names each directory directly inPlugins,!/Plugins/**/every directory below it, and!Content/every directory namedContent. A trailing/restricts a rule to directories, so every directory such a glob matches is one the author wrote a rule for.!/Plugins/**,!/Plugins/*,!Contentand!/Plugins/**/*.uassetname no directory. They match files as well as directories, and a rule written to bring back files says nothing about the directories they sit in.- The subtree companion
!<path>/**a path re-inclusion adds names nothing, so!/Engine/Content/namesEngine/Contentand not the directories below it. !/a/followed by**names nothing: the later exclusion takesaout, and a later re-inclusion that keeps it, such as!/*, names it only if it targets directories itself.
Filter::creates_directory is the rule, given the verdicts at the directory, its path and whether the revision holds it empty. It reads the view's lines only for a kept directory that holds entries, through the line index where the view has one, runs a glob only for a re-inclusion that targets directories, and folds the parent's verdict, through the filter's memo of ancestors, only where such a rule matches. Every walk asks it:
- Clone, the sync realize, reset, layer add and link add create a directory for itself as they reach it; any other directory is created as the parent of the first entry written below it.
status --scan,lore dirtyandlore stagetake a missing directory for a deletion where the view creates it for itself, and otherwise only where an entry below it was on disk. A missing named directory is therefore a deletion, as under revision 2738, and a missing implicitly kept one isn't.- A sync, branch switch or
sync --viewremoves a directory its deletes leave empty, unless the view creates it for itself: the diff marks a delete in a directory the target holds empty and the view keeps (change::Flags::KeptBeside), the realize keeps a directory the view names whatever its deletes leave in it, and where a change of view, of naming or of emptiness changes whether the view creates a paired directory, the diff adds or deletes it alone. - A merge, cherry-pick, revert,
sync --reset, a sync with--root-fileand a change of a link's pin remove only the emptied directories the view excludes, since the walks that find their changes don't say whether the view creates a directory for itself. Where a merge, cherry-pick or revert deletes or moves away the last entry of a directory the view keeps, and the view leaves that entry out, the realize looks the directory up in the target revision and creates it where the revision holds it empty, as nothing was on disk to keep. Async --viewkeeps, in a link's tree, the nearest directory the view keeps above a delete there, so as to keep the link's mount, which the realize can't tell from the directories below it. - SWFS lists the directories of the revision it serves, so its realize keeps every emptied directory the view keeps, and removes an emptied directory the view excludes only as it did before this decision.
Consequences¶
- Good, because the working tree holds no directory a pattern view leaves empty: on the 1.1-million-file view, 3.2 million fewer directories, a copy-on-write instance clone in 116 seconds rather than 248, the first
status --scanin 39 seconds rather than 107, and an instance delete in about 150 seconds rather than about 390. On the synthetic tree, 8,082 directories rather than 16,082. - Good, because a view that names a directory gets it whatever it holds:
!/Engine/Content/followed by/Engine/Content/*gives an emptyEngine/Content, as under revision 2738. - Good, because the working tree shows only names the view places or names. Under
/Plugins/**/*.uasset, a folder holding only.uassetfiles, such as one named for an unannounced platform, isn't created, so file indexers, backups, logs and tools that list the tree don't see its name; a directory the view excludes, such asEngine/Secretunder/*,!/Engine/**and/Engine/Secret/, stays off the disk with the folders in it, as under revision 2738. This is not an access-control boundary: the client still receives every name in the revision's tree data, andlorecommands that read the tree show them. It keeps the names off the disk. - Good, because without a view nothing changes: every directory holding an entry holds something placed.
- Bad, because a directory the view keeps only implicitly, holding only what the view excludes, isn't there to put new files in: a user who wants it writes a rule naming it.
- Bad, because a glob naming directories, such as
!/Plugins/**/, creates every directory it matches, empty or not, as revision 2738 did for every kept directory. - Bad, because a merge, cherry-pick, revert,
sync --reset, sync with--root-fileor link pin change that deletes the last kept file in a directory the view keeps and doesn't name leaves the directory in place, and so does async --viewfor the nearest such directory above a delete in a link's tree. - Bad, because a walk that drops the deletes of entries the view leaves out, as a sync with
--root-fileand a change of a link's pin can, doesn't create a kept directory its changes leave empty in the revision, andstatus --scanthen lists it as deleted untillore resetcreates it. - Bad, because a sync, branch switch or
sync --viewunder any view tries onermdirfor each directory above its deletes that nothing marks as staying. - Neutral, because an instance created under the earlier rule keeps its empty directories: a scan doesn't list a directory that stands on disk and in the revision.
More Information¶
FUSE and SWFS instances list the directories of the served revision under the view's tree exclusion, so the directories they show don't follow this rule. On SWFS, clone and sync record fewer directory intents, and its realize removes no emptied directory the view keeps. The how-to Write view filters and ignore files describes the rule for users.