Skip to content

Hash only the owner execute bit on source files#362

Merged
tinder-maxwellelliott merged 1 commit into
masterfrom
claude/source-exec-bit-owner-only
May 22, 2026
Merged

Hash only the owner execute bit on source files#362
tinder-maxwellelliott merged 1 commit into
masterfrom
claude/source-exec-bit-owner-only

Conversation

@tinder-maxwellelliott
Copy link
Copy Markdown
Collaborator

Summary

  • Narrow SourceFileHasher to check only PosixFilePermission.OWNER_EXECUTE instead of OR'ing owner/group/others. Pulled into a private isOwnerExecutable helper to avoid duplicating the try/catch at both call sites.
  • Add regression test testHashIgnoresGroupAndOthersExecuteBits that hashes the same file with mode rw-------, rw---x---, and rw------x and asserts all three hashes are identical.
  • Existing testHashExecutableBitChange (issue Missing bazel-diff support for change executable bit of files #325) still passes since it only toggles OWNER_EXECUTE.

Why

Cross-referencing how a sibling tool handles this: bazel-contrib/target-determinator shipped commit 5bfae36 ("fix(hash_cache): only take user execute bits into account") for the same reason:

There are some cases where files are initially created with some permissions (e.g. 775) but are then created by git with different permissions (e.g. 755) when cloning, checking out a branch or creating a worktree. Such differences don't matter to git nor to Bazel; consequently, they should not change the hash of a source file in target-determinator. The execution bit for the user (e.g. 744 vs 644) does matter, though, and should be part of the hash.

Git's index only records 100644 vs 100755 — the owner execute bit. Group/others execute bits aren't represented and can flip between checkouts under different umasks. Folding them into the hash adds noise without buying any signal that the build cares about.

The current OR-of-three logic was introduced in #331 (fix for #325). #325's example use case (toggling the owner execute bit on a script under a filegroup) is preserved by this change.

Test plan

  • bazel test //cli:SourceFileHasherTest passes locally (testHashExecutableBitChange and the new testHashIgnoresGroupAndOthersExecuteBits both green).
  • bazel test //cli:BuildGraphHasherTest //cli:TargetHashTest passes locally — no broader regressions.
  • CI on ubuntu+macos × Bazel 7/8/9.

🤖 Generated with Claude Code

Match what git's index tracks (100644 vs 100755). Group and others
execute bits don't affect the build and can flip between checkouts under
different umasks, causing spurious hash differences. This mirrors the
target-determinator fix in commit 5bfae36 ("only take user execute bits
into account").

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@tinder-maxwellelliott tinder-maxwellelliott merged commit 117a3b1 into master May 22, 2026
15 checks passed
@tinder-maxwellelliott tinder-maxwellelliott deleted the claude/source-exec-bit-owner-only branch May 22, 2026 14:23
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.

1 participant