Skip to content

assembly-root bootstrap.py: _folded_twin compares HEAD's ref as the locale reads it with the manifest's text, so a case twin is missed under Latin-1 (TB<ff>x for tb\udcffx) and UTF-8 (CAF<c3 a9> for caf\udcc3\udca9), and the branch is made #1306

Open

Description

@brettheap

(lane openRepoShape-1, 2026-11-10T10:43:48Z)

Found by: r1300a, lane 1's reviewer of PR #1300 (for #1283), F1 of issuecomment-6764753070; measured again by w1300r, lane 1's writer of #1300's first review round. r1300a found that once #1300 compares HEAD's ref with the tracking branch as git's bytes read back (_branch_ref), _folded_twin is the one check in step (a) that still compares it with the manifest's text, and that no open issue names its misses, which #1283's fourth "Done when" box asks for. Lane 1 ruled that #1300 leaves _folded_twin as it is, since what a case twin is for a name that is not UTF-8 is a question of its own. This is that question's issue. It follows #1283.

Lane 3 places this issue, and it has no milestone here: v1.2.1 is frozen. It is in the area of #896 and #962 (case twins, both closed), of #1283 and #1300 (a name the locale reads back as other text), and of #704 and #715 (a branch that is not UTF-8).

This body is ASCII, so each non-ASCII character is written as its code point, and a printed escape is written with a backslash. <ff> and <c3 a9> name bytes. In the quoted lines, <U+2014>, <U+00FF>, <U+00E9>, <U+00C3> and <U+00A9> each stand for that one character.

What is wrong

_folded_twin in templates/assembly-root/scripts/bootstrap.py asks whether HEAD's ref is a TWIN of the tracking branch: a branch under refs/heads/ whose name is the branch's under _fold (NFC, then str.casefold()) and not byte for byte (#896, #962). It compares HEAD's ref, as _head_of decodes it (os.fsdecode of git's bytes), with the manifest's text: held != branch and _fold(held) == _fold(branch). The two sides were decoded differently. Where the locale reads a twin's bytes as other text than the manifest's surrogates, the twin is missed:

_folded_spelling asks _folded_twin of every branch under refs/heads/ before checkout -b, so it misses the same twins with HEAD elsewhere (measured below, with HEAD detached at the pin).

What the miss does. Step (a) makes the tracking branch with checkout -b beside the twin and says created. Where the twin is found, it says the leg has a twin, leaves the leg as it is, and gives the rename. On a disk that folds case (macOS APFS, Windows NTFS by default), refs/heads/CAF<c3 a9> and refs/heads/caf<c3 a9> are one loose file, which is #896's harm. Whether TB<ff>x and tb<ff>x are one file on any disk is part of the question below: APFS refuses a name that is not UTF-8 (w1283a's reading in #1300, not measured). Every run ends bootstrap ok, exit 0.

The tracking branch itself is never a false twin. HEAD on tb<ff>x for tb\udcffx, and on caf<c3 a9> for caf\udcc3\udca9, is no twin under UTF-8, Latin-1 and ASCII (measured, below).

The miss is not new. Main gives the same 15 twin answers in process (below). End to end, main misses the same twins and makes the branch beside them too. It then says could not create branch over it, #1283's false line, which #1300 turns into created. Git's refs and HEAD after each run are the same on main and at #1300's head.

What was measured

Every run below used Python 3.12.3 and git 2.43.0 on Linux, in lane 1's probe environment: a stub gh first on PATH, GIT_CONFIG_GLOBAL=/dev/null and GIT_SSH_COMMAND=false.

The trees:

In process

r1300a's twin.py loads the file and hands _folded_twin HEAD's ref as _head_of decodes it (os.fsdecode(b"refs/heads/" + raw)), with the manifest's branch, in a child under each locale. At #1300's head:

utf-8: b'tb\xffx' vs 'tb\udcffx' twin=False; b'TB\xffx' vs 'tb\udcffx' twin=True; b'caf\xc3\xa9' vs 'caf\udcc3\udca9' twin=False; b'CAF\xc3\xa9' vs 'caf\udcc3\udca9' twin=False; b'Main' vs 'main' twin=True;
iso8859-1: b'tb\xffx' vs 'tb\udcffx' twin=False; b'TB\xffx' vs 'tb\udcffx' twin=False; b'caf\xc3\xa9' vs 'caf\udcc3\udca9' twin=False; b'CAF\xc3\xa9' vs 'caf\udcc3\udca9' twin=False; b'Main' vs 'main' twin=True;
ascii: b'tb\xffx' vs 'tb\udcffx' twin=False; b'TB\xffx' vs 'tb\udcffx' twin=True; b'caf\xc3\xa9' vs 'caf\udcc3\udca9' twin=False; b'CAF\xc3\xa9' vs 'caf\udcc3\udca9' twin=True; b'Main' vs 'main' twin=True;

On main's blob the 15 answers are the same, line for line.

End to end

A probe built one scaffold's recursive clone. For each case it:

  1. copied the clone and set tracking_branch;
  2. put the spec leg on the twin at the pin (git checkout -b <the twin's bytes> <pin>), or made the twin a branch at the pin with HEAD detached there, the tracking branch itself absent;
  3. ran scripts/bootstrap.py --skip-validators once, with PYTHONIOENCODING=utf-8:strict.

These are step (a)'s lines for spec, at #1300's head; the code leg says created in every case.

HEAD on TB<ff>x, tracking_branch: "tb\udcffx". Under UTF-8 and under ASCII, the same three lines:

  [spec] spec: branch tb\udcffx does not exist (the pin is 5985a5dad55d), and the checkout is on TB\udcffx, which differs from tb\udcffx only in case
          a disk that folds case (macOS, Windows) reads TB\udcffx and tb\udcffx as one branch, so making tb\udcffx could hide the commits a branch spelled like tb\udcffx holds behind the new ref; the leg is left as it is
          rename TB\udcffx to a name that differs from tb\udcffx by more than case, its commits staying on it: `git -C spec branch -m "$(printf -- 'TB\377x')" "$(printf -- 'TB\377x-kept')"`, and run bootstrap again.

HEAD stays on TB<ff>x, and the leg's branches are TB<ff>x and main. Under Latin-1:

  [spec] spec: branch tb\udcffx created at 5985a5dad55d <U+2014> at the pin
          the leg was on TB<U+00FF>x, which keeps its commits; it is on tb\udcffx now

HEAD is on tb<ff>x, beside TB<ff>x.

HEAD on CAF<c3 a9>, tracking_branch: "caf\udcc3\udca9".

  • Under ASCII: the three twin lines, for CAF\udcc3\udca9, with the rename word "$(printf -- 'CAF\303\251')". HEAD stays on CAF<c3 a9>.
  • Under UTF-8: branch caf\udcc3\udca9 created at 5985a5dad55d <U+2014> at the pin, then the leg was on CAF<U+00E9>, which keeps its commits; it is on caf\udcc3\udca9 now. HEAD is on caf<c3 a9>, beside CAF<c3 a9>.
  • Under Latin-1: the same two lines, with the leg was on CAF<U+00C3><U+00A9>.

HEAD detached at the pin, the twin a branch at the pin (_folded_spelling).

  • tb\udcffx under UTF-8: branch tb\udcffx does not exist (the pin is 00fe64962ab1), and the leg has the branch TB\udcffx, which differs from tb\udcffx only in case, then the same two lines as above. The leg stays detached.
  • tb\udcffx under Latin-1: branch tb\udcffx created at 00fe64962ab1 <U+2014> at the pin. HEAD is on tb<ff>x, beside TB<ff>x.
  • caf\udcc3\udca9 under ASCII: ... and the leg has the branch CAF\udcc3\udca9, which differs from caf\udcc3\udca9 only in case, and the leg stays detached.
  • caf\udcc3\udca9 under UTF-8: created, and HEAD is on caf<c3 a9>, beside CAF<c3 a9>.

On main (blob 41c2eb42), HEAD on the twin:

Every run exited 0.

The question a fix must settle

What is a case twin of a branch whose name is not UTF-8? Case twins were decided in #896 (case) and #962 (NFC and NFD, and every branch with HEAD elsewhere), both closed. Neither met a name the locale reads back as other text than the manifest's surrogates.

w1283a's Latin-1 objection, from #1300. One way out is to fold the branch as git's bytes read back, _branch_ref(branch)[len("refs/heads/"):], as #1300 compares HEAD's ref with it. That finds both misses above. But it changes what a twin is under Latin-1: the bytes 0xC4 and 0xE4 read back as U+00C4 and U+00E4, which fold alike. So tb<c4>x and tb<e4>x would become twins under Latin-1, where UTF-8 and ASCII read each byte as a surrogate and call them none. Computed in process at #1300's head (fold_c4.py, w1300r's):

utf-8 read back: 'tb\udcc4x' 'tb\udce4x' folded equal: False | _folded_twin(HEAD on tb<e4>x, branch tb\udcc4x): False
iso8859-1 read back: 'tb\xc4x' 'tb\xe4x' folded equal: True | _folded_twin(HEAD on tb<e4>x, branch tb\udcc4x): False
ascii read back: 'tb\udcc4x' 'tb\udce4x' folded equal: False | _folded_twin(HEAD on tb<e4>x, branch tb\udcc4x): False

Today all three locales say no twin there. The one who takes this decides whether such a pair is a twin, which depends on whether any disk that folds case holds the two as one file.

Another way out, the filer's, computed and not tried in the file. Fold both sides as git's bytes decoded by ONE codec, UTF-8 with surrogateescape: HEAD's raw ref, and _handed_to_git(branch). fold_alt.py (w1300r's) computes it at #1300's head with the file's own _fold and _handed_to_git. The line is the same under Latin-1 and ASCII but for the codec's name:

utf-8: b'tb\xffx' vs 'tb\udcffx' alt=False; b'TB\xffx' vs 'tb\udcffx' alt=True; b'caf\xc3\xa9' vs 'caf\udcc3\udca9' alt=False; b'CAF\xc3\xa9' vs 'caf\udcc3\udca9' alt=True; b'tb\xe4x' vs 'tb\udcc4x' alt=False; b'Main' vs 'main' alt=True;

So both misses are found in every locale, the tracking branch itself and tb<e4>x for tb\udcc4x stay no twins, and Main for main stays one. _folded_spelling reads branch names through _heads, which decodes them, so it would need the raw names as well.

Done when

See #1283, #1300, #896, #962, #704, #715, #1153 and #1259.

Lane: openreposhape-1 (openRepoShape-1)

Activity

  1. added this to the v1.2.2 milestone on Nov 10, 2026
  2. brettheap commented on Nov 10, 2026

    @brettheap
    ContributorAuthor

    CLAIMED — lane openRepoShape-1, session 300f8f46-004a-4e72-8587-4f192be2e108@Eagle, 2026-11-10T12:19:45Z, for #1306

    Logged in lanes/log/openRepoShape-1.md at 868016982f842cb7f00d9cab02c8b9d742913ab7.

    The three reads (lane-collision-protocol Rule 1):

    1. existing `CLAIMED —` comments on opensoft/openRepoShape#1306:
       none
    2. `gh pr list --repo opensoft/openRepoShape --state all --search "#1306"`, kept where the row or its body names `#1306`:
    1300	assembly-root bootstrap.py: step (a) asks whether HEAD is on the tracking branch by the bytes git was handed, so under a Latin-1 locale `tb\\udcffx` is said created, then on, where it said `could not create branch` and `git refused` (#1283)	fix/1283-bootstrap-branch-latin1	OPEN
    3. `git ls-remote --heads [email protected]:opensoft/openRepoShape` branches naming `1306` as a whole token:
       none
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions