-
-
Notifications
You must be signed in to change notification settings - Fork 13
feat: add large-file-script. #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
yuting1214
wants to merge
27
commits into
michen00:main
Choose a base branch
from
yuting1214:mark-chen-pr
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
0da9b06
feat: add large-file-script.
yuting1214 268e0bd
Merge branch 'main' into mark-chen-pr
michen00 fea6565
Merge branch 'main' into mark-chen-pr
michen00 42f2b3e
Merge branch 'main' into mark-chen-pr
michen00 1229cfb
Merge branch 'main' into mark-chen-pr
michen00 e53e0cb
Merge branch 'main' into mark-chen-pr
michen00 4113f8f
Merge branch 'main' into mark-chen-pr
michen00 e564c47
Merge branch 'main' into mark-chen-pr
michen00 d5c04a3
Merge branch 'main' into mark-chen-pr
michen00 4c6db2f
Merge branch 'main' into mark-chen-pr
michen00 dc7373b
Merge branch 'main' into mark-chen-pr
michen00 97c74bf
Merge branch 'main' into mark-chen-pr
michen00 c9e29ce
Merge branch 'main' into mark-chen-pr
michen00 4e8e66f
Merge branch 'main' into mark-chen-pr
michen00 d65f6d2
Merge branch 'main' into mark-chen-pr
michen00 a3be28b
Merge branch 'main' into mark-chen-pr
michen00 9b5f72c
chore: autofix via pre-commit hooks
pre-commit-ci[bot] 71c247d
Merge branch 'main' into mark-chen-pr
michen00 18acd2c
Merge branch 'main' into mark-chen-pr
michen00 446cb54
Merge branch 'main' into mark-chen-pr
michen00 8f3cab6
fix(large-files): make the script executable
michen00 b66c0b0
Merge branch 'main' into mark-chen-pr
michen00 9baab2a
Merge branch 'main' into mark-chen-pr
michen00 f585fd5
Merge branch 'main' into mark-chen-pr
michen00 4811f24
Merge branch 'main' into mark-chen-pr
michen00 51b7259
Merge branch 'main' into mark-chen-pr
michen00 a09b445
Merge branch 'main' into mark-chen-pr
michen00 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| #!/bin/bash | ||
|
|
||
| set -e | ||
|
|
||
| # Function to display help message | ||
| usage() { | ||
| cat <<EOF | ||
| Usage: large-files [N] | ||
|
|
||
| Find the top N largest files in a Git repository. | ||
|
|
||
| Arguments: | ||
| N Number of large files to display (default: 20) | ||
|
|
||
| Description: | ||
| This script scans the entire Git history and identifies the largest files that | ||
| have ever existed in the repository. It uses 'git rev-list' to extract object | ||
| sizes and sorts them to display the largest files. | ||
|
|
||
| Requirements: | ||
| - Ensure you're inside a Git repository. | ||
| - Install 'numfmt' (available in GNU coreutils) for better size formatting. | ||
|
|
||
| Examples: | ||
| large-files # Show top 20 largest files | ||
| large-files 50 # Show top 50 largest files | ||
| EOF | ||
| exit 0 | ||
| } | ||
|
|
||
| # Default number of files to display | ||
| NUM_FILES=20 | ||
|
|
||
| # Parse command-line argument | ||
| if [[ $# -gt 1 ]]; then | ||
| usage | ||
| elif [[ $# -eq 1 ]]; then | ||
| NUM_FILES="$1" | ||
| if ! [[ "$NUM_FILES" =~ ^[0-9]+$ ]]; then | ||
| echo "Error: N must be a valid integer." | ||
| usage | ||
| fi | ||
| fi | ||
|
|
||
| # Ensure we are inside a Git repository | ||
| if ! git rev-parse --is-inside-work-tree >/dev/null 2>&1; then | ||
| echo "Error: Not inside a Git repository." | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo "🔍 Finding the $NUM_FILES largest files in the repository..." | ||
|
|
||
| # Extract large files from Git history | ||
| git rev-list --objects --all | | ||
| git cat-file --batch-check='%(objectsize:disk) %(rest)' | | ||
| sort -rh | | ||
| head -n "$NUM_FILES" | | ||
| awk '{ printf "%10s %s\n", $1, $2 }' | | ||
| numfmt --to=iec-i --suffix=B --padding=7 --field=1 | ||
|
|
||
| echo "✅ Done!" | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Considering all files that have ever existed significantly diminishes the utility of this tool. Consider the following output of refs to the same file:
(Side note: If we are going to claim 'to have ever existed', we should probably do an explicit
fetchin the beginning.)I can think of a couple of ways to make this script more useful:
@yuting1214, what do you think? Do any of the above (alone or in conjunction) sound more or less appealing to you?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Michael,
I'm more than happy to contribute more about this repo. It's just I'm a little occupied at the moment.
Once I settled a few things, I'll come back and write more code with you. Stay tuned.