Skip to content

ADR-00047: A node's mode holds Lore's own flags in its top three bits

Field Value
Status accepted
Date 2026-11-29

Context and Problem Statement

The successor locks proposal lets a file carry an unmergeability decision of its own, which wins over the repository's extension list, and leaves where the node record holds it to the implementation. The decision is a property of the file in a revision: it has to enter the directory hash, count as a change, survive an edit, a move and a merge as the file ID does, and cost nothing to read beside the record.

The 16-bit mode of a node held the executable bit Lore reads in bit 0, while the revision tree API's callers stored their own mode there, such as POSIX permission bits. The record's one spare word, _unused, carries no contract, so nothing guarantees it is zero in data written by other builds.

The question was where in the record the decision lives, and how its bits stay apart from the bits the API's callers own.

Decision Drivers

  • No format version change and no migration: every existing node reads as carrying no decision.
  • The decision is part of the tree's identity, so a change of it alone changes the revision.
  • Every path that carries a node's mode, through committing, staging, moving and merging, carries the decision with no extra step.
  • A caller of the revision tree API can't write the decision by accident, and a mode it reads back can be written back.

Considered Options

  • The spare word _unused, renamed and typed as flags.
  • The top bits of mode, reserved for Lore.
  • A flag of the next node format, NodeFlagsV2.

Decision Outcome

Chosen option: "The top bits of mode, reserved for Lore", because mode already enters the directory hash and travels with a node wherever its content does, so every copy of a record carries the decision, and nothing has written its top bits, so every existing node reads as carrying none.

mode divides into two parts:

  • Bits 0 to 12 are the caller's. The revision tree API stores them as given. Lore reads bit 0 as the executable bit, the only bit the working tree holds.
  • Bits 13 to 15 are Lore's (NodeFileMode::RESERVED). Bits 14 and 15 hold the unmergeability decision: UnmergeableSet where the file carries one, and UnmergeableValue for unmergeable. Bit 13 is reserved for a symbolic link flag.

The rules that follow:

  • Rebuilding a mode from the working tree (mode_from_observed), and rewriting a node with content the working tree holds (Rewrite::Dirty), take the executable bit from the disk and keep the record's own decision. Writing a file to the disk writes the executable bit alone.
  • A change of the executable bit or of the decision is a change of the file (mode_changed), at the same address a modify. A comparison against the disk compares the executable bit alone (executable_changed).
  • A merge takes the decision, both flags together, from the side that changes it, and the target's where neither does; where both change it to different ones, it takes the stronger, ranked by the resolved state: unmergeable over mergeable over auto. The rest of the mode travels with the executable bit, from the side that changes that bit (merged_mode). The decision never stages a file as a conflict.
  • A resolve of a conflicted file takes the chosen side's content and keeps the whole mode the merge staged, so only an explicit change sets a decision after a merge.
  • The revision tree API refuses an entry setting any of bits 13 to 15, keeps the node's own on a modify and on a restore, and reports a mode without them.

Consequences

  • Good, because no format version moves and no data migrates: a node written by any earlier build holds zero in the top bits and reads as auto.
  • Good, because the decision enters the directory hash, the diff and the merge where the executable bit already did; only the rebuilds of a mode from the working tree, the merge and the revision tree API handle it on their own.
  • Good, because reading the decision costs nothing beyond the record a caller already holds.
  • Bad, because a caller of the revision tree API that stores values in bits 13 to 15 is refused, and a mode it reads leaves them out.
  • Bad, because a build that rebuilds a mode from the executable bit alone, as builds before this decision do, drops the decision when it modifies the file, so the extension list stays the dependable declaration until every client keeps the decision.
  • Bad, because Lore holds three bits of mode, all allocated, so a further flag needs a place of its own.

Pros and Cons of the Options

The spare word _unused

  • Good, because it leaves mode to the caller.
  • Bad, because nothing declares the word zero, so a node an earlier build wrote non-zero would read as a decision nobody made, which only a scan of every repository rules out.
  • Bad, because every path that copies a record field by field, as merging and the fast-forward merge do, needs to carry the word too, and the directory hash needs it added.

A flag of the next node format

  • Bad, because nothing writes that format: the code only reads and converts it, so the decision would wait for the next format version.

More Information

NodeFileMode in lore-revision/src/state/block.rs defines the flags, lore-revision/src/util/fs.rs the comparisons and the rebuild from the disk, lore-revision/src/change.rs the merge, and lore-revision/src/unmergeable.rs the decision against the extension list.