Skip to content

Commit

Permalink
pre-commit: filter out large diffs
Browse files Browse the repository at this point in the history
  • Loading branch information
dtcxzyw committed Jan 12, 2024
1 parent 1bc533c commit f60af7f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
28 changes: 28 additions & 0 deletions scripts/filter_pr_changes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/python3

import subprocess

max_diff_per_file = 20000
max_diff_total = 20000
max_file_total = 300 - 1

stats = subprocess.check_output(['git', 'diff', '--numstat']).decode().splitlines()
diffs = []
for line in stats:
add, sub, file = line.removesuffix('\n').split()
count = int(add)+int(sub)
if count > max_diff_per_file:
continue
diffs.append((file, count))
diffs.sort(key=lambda x: x[1])

file_count = 0
diff_count = 0

for file, count in diffs:
if file_count < max_file_total and diff_count + count <= max_diff_total:
file_count += 1
diff_count += count
subprocess.run(['git', 'add', file])
else:
break
5 changes: 4 additions & 1 deletion scripts/update_optimized.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,15 @@ then
echo "SHOULD_OPEN_ISSUE=0" >> $GITHUB_OUTPUT
fi
else
git commit -a -m "pre-commit: Update"
diff_stat=$(git diff --shortstat)
./scripts/filter_pr_changes.py
git commit -m "pre-commit: Update"
git push -f
echo "baseline: https://github.com/llvm/llvm-project/commit/$LLVM_REVISION" > scripts/pr-comment.md
echo "patch: $COMMIT_URL" >> scripts/pr-comment.md
echo "sha256: $PATCH_SHA256" >> scripts/pr-comment.md
echo "commit: $(git rev-parse HEAD)" >> scripts/pr-comment.md
echo "$diff_stat" >> scripts/pr-comment.md
head -100 test.log >> scripts/pr-comment.md
git show --name-only --oneline | head -100 >> scripts/pr-comment.md
fi

0 comments on commit f60af7f

Please sign in to comment.