Skip to content

Discretisation of EntryMode to EntryKind is almost certainly incorrect #1259

@xmo-odoo

Description

@xmo-odoo

Looked at 3ac5d0b after hitting the privatisation of EntryMode's state1 and I might be misreading the code but I think the normalisation behaviour is not correct: https://github.com/Byron/gitoxide/blob/main/gix-object/src/tree/mod.rs#L77-L90

This converts exact tree, link, and commit (submodules) modes to the corresponding kind, then everything else is converted to an executable blob if 0o100 is set, and to a non-executable blob otherwise.

Git's own mode canonicalisation works very differently though: it uses the S_IS* macros from stat.h to parse the various modes. To my understanding this means it masks in the upper nibble, then checks that exactly against one of the type constants. So e.g.

0o40534

is considered a directory, because the permission bits are discarded before dispatch. In gix-object, I think this currently would parse as an executable blob.

Git checks for BLOB, LINK, then TREE but that should not matter overly much as all of those are equality checks, however it then falls back to GITLINK (Commit) so e.g. 0o10000 or 0o140000 should be interpreted as Commit, not Blob.

That would also make the first four is_ functions incorrect as they check for exact values rather than follow normalisation.

Footnotes

  1. incidentally the ability to create an arbitrary EntryMode might be useful to test git implementations themselves, but the payload is not pub and there seems to be no way to convert a u16 to an EntryMode.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions