Skip to content

GitIdentifiers: record files as regular without POSIX permissions - #458

Merged
garydgregory merged 3 commits into
apache:masterfrom
simpleqt:gitidentifiers-exec-bit
Nov 21, 2026
Merged

garydgregory merged 3 commits into
apache:masterfrom
simpleqt:gitidentifiers-exec-bit

Conversation

@simpleqt

@simpleqt simpleqt commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

GitIdentifiers.treeId(Path) records every file as mode 100755 on Windows, so the tree identifiers it computes do not match Git's.

Files.isExecutable(Path) is the only test used to choose between 100644 and 100755, and on the default Windows file system every readable file reports as executable. Git records the executable bit only where the file system exposes POSIX permissions; with its default core.fileMode=false on Windows, every regular file is stored as 100644. The same applies to any file system without POSIX permissions.

The mode is now classified from one attribute set, preferring the POSIX view where the file system provides it and falling back to the basic view elsewhere:

BasicFileAttributeView view = Files.getFileAttributeView(path, PosixFileAttributeView.class, LinkOption.NOFOLLOW_LINKS);
if (view == null) {
    view = Files.getFileAttributeView(path, BasicFileAttributeView.class, LinkOption.NOFOLLOW_LINKS);
    final BasicFileAttributes attributes = view.readAttributes();
    ...
}
final BasicFileAttributes attributes = view.readAttributes();
...
return ((PosixFileAttributes) attributes).permissions().contains(PosixFilePermission.OWNER_EXECUTE) ? EXECUTABLE : REGULAR;

attrs.isSymbolicLink() and attrs.isDirectory() classify the entry, and only the POSIX permission bits carry the owner-execute bit Git records. On a POSIX file system the POSIX view is present, so the executable bit is used exactly as before; on a file system without it the file is 100644. This also replaces the separate Files.isSymbolicLink/isDirectory/isExecutable calls with one attribute read, following the review suggestion.

Test

GitIdentifiersTest.testTreeIdPathRecordsFilesWithoutPosixExecutableBitAsRegular compares GitIdentifiers.treeId(Path) on a temporary directory with a tree built through TreeIdBuilder, so it fails while the path-based tree still uses the executable bit for an ordinary file. Two existing tests, testTreeIdPath and testTreeIdSortsSupplementaryPlaneNamesLikeGit, fail on Windows for the same reason and pass with the change.

Local results on Windows 10, JDK 17.0.11, mvn -B -o -Dtest=GitIdentifiersTest test:

  • with the source change reverted: 55 run, 3 failures (testTreeIdPath, testTreeIdPathRecordsFilesWithoutPosixExecutableBitAsRegular, testTreeIdSortsSupplementaryPlaneNamesLikeGit), plus 3 errors from the symlink tests that need a Windows privilege this host does not have
  • with the change: 55 run, 0 failures, and the same 3 symlink errors, which are environmental and unrelated to this change
  • the focused non-symlink cases (testTreeIdPath, testTreeIdSortsSupplementaryPlaneNamesLikeGit, testTreeIdPathRecordsFilesWithoutPosixExecutableBitAsRegular): 3 run, 0 failures
  • full mvn -B -ntp -o -Dmaven.repo.local=G:/pr/tools/m2local test: 19971 run, 0 failures, 3 errors (the same Windows symlink-privilege errors), 20 skipped

Linux and macOS CI are the first runs on a POSIX file system; the changed branch is a single guard, and the POSIX path keeps its previous behaviour. CI on this repository is currently action_required (first contribution from this fork), so the numbers above are local only.

The commit carries an Assisted-By: trailer, as AGENTS.md asks.

Copilot AI balanced review requested due to automatic review settings November 15, 2026 15:40

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

Comment thread src/changes/changes.xml Resolved
@garydgregory
garydgregory marked this pull request as draft November 15, 2026 16:22
@garydgregory

Copy link
Copy Markdown
Member

Convert to draft until review.

@simpleqt
simpleqt force-pushed the gitidentifiers-exec-bit branch from 194f644 to fa2997c Compare November 16, 2026 11:23

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are recorded for the non-POSIX file-mode handling change.

No open issues 🎉

Review effort: Balanced

Files.isExecutable(Path) returns true for every readable file on the default Windows file system, so treeId(Path) recorded all regular files with mode 100755 instead of 100644 and produced tree identifiers that differ from Git's. Git records the executable bit only where the file system exposes POSIX permissions; with its default core.fileMode=false on Windows it stores regular files as 100644.

The executable bit is now used only when the file has a POSIX attribute view. On a POSIX file system the view is present and Files.isExecutable stays authoritative, so the behaviour there is unchanged.

Add a regression test. Existing GitIdentifiersTest.testTreeIdPath and testTreeIdSortsSupplementaryPlaneNamesLikeGit now pass on Windows.

Assisted-By: DeepSeek dsv41
@simpleqt
simpleqt force-pushed the gitidentifiers-exec-bit branch from fa2997c to 8e8a5d2 Compare November 19, 2026 12:13

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

There are no active review issues blocking the filesystem-based Git tree mode correction.

No open issues 🎉

Review effort: Balanced

Address the review nit on FileMode.get: read one BasicFileAttributeView (POSIX preferred, Basic fallback), classify symbolic link and directory once, and use an instanceof PosixFileAttributes check for the owner-execute bit. This removes the duplicated fallback classification.

The executable bit is still only read where the file system exposes POSIX permissions; without a POSIX view the attributes are BasicFileAttributes and the file is REGULAR.
@garydgregory
garydgregory marked this pull request as ready for review November 21, 2026 15:53
@garydgregory
garydgregory merged commit 1660ecd into apache:master Nov 21, 2026
10 checks passed
Comment on lines +227 to +231
// Read one attribute set, preferring POSIX where the file system provides it. The basic view always exists and
// classifies links and directories; only POSIX permissions carry the owner-execute bit that Git records. Git
// records the executable bit only where the file system exposes POSIX permissions; elsewhere, for example with
// Git for Windows and its default core.fileMode=false, regular files are stored as 100644 even though Windows
// reports every readable file as executable.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I think the code is self-explaining, so this comment could be dropped. LLMs have the tendency of writing the history of their life as comments, but IMHO most of them are not necessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants