Skip to content

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

Draft
simpleqt wants to merge 2 commits into
apache:masterfrom
simpleqt:gitidentifiers-exec-bit
Draft

simpleqt wants to merge 2 commits into
apache:masterfrom
simpleqt:gitidentifiers-exec-bit

Conversation

@simpleqt

@simpleqt simpleqt commented Nov 15, 2026 •

Copy link
Copy Markdown

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
<action type="fix" dev="ggregory" due-to="Gary Gregory">StringUtils now uses the JVM default charset for null charset names in getBytesUnchecked and newString.</action>
<action type="fix" dev="ggregory" due-to="Gary Gregory">BCodec.encode(String, String) now wraps illegal charset names in EncoderException, consistent with unsupported charset names.</action>
<action type="fix" dev="ggregory" due-to="Gary Gregory">QCodec.encode(String, String) now wraps illegal charset names in EncoderException, consistent with unsupported charset names.</action> <!-- ADD -->
<action type="fix" dev="ggregory" due-to="Gary Gregory">QCodec.encode(String, String) now wraps illegal charset names in EncoderException, consistent with unsupported charset names.</action>

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.

Don't edit this file.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Removed. src/changes/changes.xml is no longer touched: the branch is the Java change plus the regression test only, now at fa2997c (2 files, +29/-1).

The CI run on the previous head was green (10 checks, including Java CI); I cannot tell yet whether the new head needs another approval before it runs, and I am not claiming one.

I left the pull request as a draft, as you asked, and will not touch src/changes/changes.xml in any of my open pull requests.

@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
// Windows reports every readable file as executable. Git records the executable bit only where the file system
// provides POSIX permissions; elsewhere, for example with Git for Windows and its default core.fileMode=false,
// regular files are stored as 100644.
if (Files.getFileAttributeView(path, PosixFileAttributeView.class) != null && Files.isExecutable(path)) {

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: since we are retrieving the file attributes, we might as well use them. We could for example:

  • Retrieve an attribute view:

    BasicFileAttributeView view = Files.getFileAttributeView(path, PosixFileAttributeView.class, LinkOption.NOFOLLOW_LINKS);
    if (view == null) {
      view = Files.getFileAttributeView(path, BasicFileAttributeView.class, LinkOption.NOFOLLOW_LINKS);
    }
    BasicFileAttributes attrs = view.readAttributes();
  • Use attrs.isSymbolicLink(), attrs.isDirectory() and

    ((PosixFileAttributes) attrs).permissions().contains(PosixFilePermission.OWNER_EXECUTE);

    to classify the file.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done on 8e8a5d2 — thanks, this is cleaner than the three separate calls. FileMode.get now reads one attribute set: it asks for the PosixFileAttributeView with NOFOLLOW_LINKS, falls back to BasicFileAttributeView when the file system has no POSIX view, classifies with attrs.isSymbolicLink() / attrs.isDirectory(), and uses ((PosixFileAttributes) attrs).permissions().contains(PosixFilePermission.OWNER_EXECUTE) for the executable bit. get now declares IOException, which its only caller (populate) already throws.

Local evidence on Windows 10 / JDK 17.0.11:

  • the three non-symlink GitIdentifiersTest cases this change covers: 3 run, 0 failures
  • full mvn -B -ntp -o -Dmaven.repo.local=G:/pr/tools/m2local test: 19971 run, 0 failures, 3 errors, 20 skipped — the 3 errors are the pre-existing Windows symlink-privilege failures in testBlobIdSymlink/testTreeIdPathUnix, unrelated to this change; the two GitIdentifiers Windows failures this PR fixes are gone

The PR description now shows the attribute-view implementation. The PR is still a draft; CI on the new head is action_required again, so the local run is the only executed evidence.

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
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