Repository navigation
Closed
Description
Writing an index that was read as version 4 produces a file git cannot read. IndexWriter::serialize() keeps the version number from the index it read (
pitmaster/src/Index/IndexWriter.php
Lines 24 to 26 in 5beb97d
| $header = 'DIRC' | |
| . pack('N', $index->version()) | |
| . pack('N', count($entries)); |
pitmaster/src/Index/IndexWriter.php
Lines 59 to 84 in 5beb97d
| $fixed = pack('N', $entry->ctimeSec) | |
| . pack('N', $entry->ctimeNsec) | |
| . pack('N', $entry->mtimeSec) | |
| . pack('N', $entry->mtimeNsec) | |
| . pack('N', $entry->dev) | |
| . pack('N', $entry->ino) | |
| . pack('N', $entry->mode) | |
| . pack('N', $entry->uid) | |
| . pack('N', $entry->gid) | |
| . pack('N', $entry->fileSize) | |
| . $entry->hash->binary | |
| . pack('n', $entry->flags); | |
| if (($entry->flags & 0x4000) !== 0) { | |
| $fixed .= pack('n', $entry->extendedFlags); | |
| } | |
| $pathBytes = $entry->path . "\0"; | |
| $entryData = $fixed . $pathBytes; | |
| // Pad to 8-byte alignment | |
| $padLen = (8 - (strlen($entryData) % 8)) % 8; | |
| $entryData .= str_repeat("\0", $padLen); | |
| return $entryData; | |
| } |
Repro
git init -q t && cd t && git config user.name T && git config user.email t@x
echo a > README.md && mkdir -p src/deep && echo b > src/deep/file.txt
git add . && git commit -qm i
git update-index --index-version 4
echo c >> README.md
php -r 'require "vendor/autoload.php"; Pitmaster\Pitmaster::open(getcwd())->add("README.md");'
git status
# fatal: malformed name field in the index, near path 'EADME.md'Every operation that writes the index (add, commit state, checkout, reset, ...) is affected. Reading v4 works.
Expected
Either write v4 entries with prefix compression, or downgrade the index to version 2/3 when writing.
Metadata
Metadata
Assignees
Labels
No labels
Activity