Author: Nathan James
Date: 2020-06-28T09:49:39+01:00
New Revision: abafb655c85d92c02c19c8723ef9ecc5d48574bf
URL: 
https://github.com/llvm/llvm-project/commit/abafb655c85d92c02c19c8723ef9ecc5d48574bf
DIFF: 
https://github.com/llvm/llvm-project/commit/abafb655c85d92c02c19c8723ef9ecc5d48574bf.diff

LOG: [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

Added: 
    

Modified: 
    clang/docs/tools/generate_formatted_state.py

Removed: 
    


################################################################################
diff  --git a/clang/docs/tools/generate_formatted_state.py 
b/clang/docs/tools/generate_formatted_state.py
index 1b620a84ac0b..41d5cd9d4004 100755
--- a/clang/docs/tools/generate_formatted_state.py
+++ b/clang/docs/tools/generate_formatted_state.py
@@ -72,6 +72,8 @@ def get_style(count, passed):
      - {style2}`{percent}%`
 """
 
+FNULL = open(os.devnull, 'w')
+
 with open(DOC_FILE, 'wb') as output:
     sha = get_git_revision_short_hash()
     today = datetime.now().strftime("%B %d, %Y %H:%M:%S")
@@ -85,14 +87,22 @@ def get_style(count, passed):
         for subdir in subdirs:
             if any(sd == subdir for sd in skipped_dirs):
                 subdirs.remove(subdir)
+            else:
+                act_sub_dir = os.path.join(root, subdir)
+                # Check the git index to see if the directory contains tracked
+                # files. Reditect the output to a null descriptor as we aren't
+                # interested in it, just the return code.
+                git_check = subprocess.Popen(
+                    ["git", "ls-files", "--error-unmatch", act_sub_dir],
+                    stdout=FNULL,
+                    stderr=FNULL)
+                if git_check.wait() != 0:
+                    print("Skipping directory: ", act_sub_dir)
+                    subdirs.remove(subdir)
 
         path = os.path.relpath(root, TOP_DIR)
         path = path.replace('\\', '/')
 
-        head, _ = os.path.split(root)
-        while head:
-            head, _ = os.path.split(head)
-
         file_count = 0
         file_pass = 0
         file_fail = 0


        
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to