Skip to content

Commit abafb65

Browse files
committed
[clang][docs] Remove untracked files from formatted status
Currently on http://clang.llvm.org/docs/ClangFormattedStatus.html there are format stats on files no actually inside the tree but generated by build scripts. These are usually copied from somewhere else. Right now for example there are files from `llvm/utils/release/llvm-package...`. Adding these files bloats the list while not giving an accurate representation of how formatted the repo is. This addresses this issue by checking the git index and ignoring any folder that doesn't contain tracked files. I'm still unsure whether it would be better to just do away with the `os.walk` method and just check over every file returned from `git ls-index <project-root>`. Reviewed By: MyDeveloperDay Differential Revision: https://reviews.llvm.org/D82707
1 parent ab46273 commit abafb65

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

clang/docs/tools/generate_formatted_state.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ def get_style(count, passed):
7272
- {style2}`{percent}%`
7373
"""
7474

75+
FNULL = open(os.devnull, 'w')
76+
7577
with open(DOC_FILE, 'wb') as output:
7678
sha = get_git_revision_short_hash()
7779
today = datetime.now().strftime("%B %d, %Y %H:%M:%S")
@@ -85,14 +87,22 @@ def get_style(count, passed):
8587
for subdir in subdirs:
8688
if any(sd == subdir for sd in skipped_dirs):
8789
subdirs.remove(subdir)
90+
else:
91+
act_sub_dir = os.path.join(root, subdir)
92+
# Check the git index to see if the directory contains tracked
93+
# files. Reditect the output to a null descriptor as we aren't
94+
# interested in it, just the return code.
95+
git_check = subprocess.Popen(
96+
["git", "ls-files", "--error-unmatch", act_sub_dir],
97+
stdout=FNULL,
98+
stderr=FNULL)
99+
if git_check.wait() != 0:
100+
print("Skipping directory: ", act_sub_dir)
101+
subdirs.remove(subdir)
88102

89103
path = os.path.relpath(root, TOP_DIR)
90104
path = path.replace('\\', '/')
91105

92-
head, _ = os.path.split(root)
93-
while head:
94-
head, _ = os.path.split(head)
95-
96106
file_count = 0
97107
file_pass = 0
98108
file_fail = 0

0 commit comments

Comments
 (0)