feat: update

This commit is contained in:
anjingyu 2024-09-06 19:57:31 +08:00
parent c6f127be24
commit e78b318b05
2 changed files with 73 additions and 3 deletions

View File

@ -48,8 +48,8 @@ class AdGitHelper:
__ -> --
_v=None -> -v
__version=None -> --version
__depth_=1 -> --depth 1
__depth=1 -> --depth=1
__depth_=1 -> --depth=1
__depth=1 -> --depth 1
NOTE: All the dict arguments will be ahead of list arguments"""
def __init__(self, git=None, dry_run=False):

View File

@ -2,7 +2,7 @@
# -*- coding: utf-8; mode: python; tab-width: 4; indent-tabs-mode: nil -*-
# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 fileencoding=utf-8
#
# THIS FILE IS PART OF lrio PROJECT
# THIS FILE IS PART OF adtools PROJECT
#
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
# Version 2, December 2004
@ -27,6 +27,7 @@ import json
import datetime
import argparse
import textwrap
import uuid
from urllib.parse import quote_plus, urlparse
import crayons
@ -231,9 +232,78 @@ def __create_argparser():
help=textwrap.dedent("""Only output command, never do operation."""),
)
# lblob sub-command
sub_parser = subparsers.add_parser('lblob', help='List blob size of each commit', parents=parent_parser)
sub_parser.set_defaults(func=__list_all_blobs)
sub_parser.add_argument(
"repo", help=textwrap.dedent("Repository directory.")
)
sub_parser.add_argument(
"-l", "--limit", type=int,
default=10 * 1024 * 1024, help=textwrap.dedent("The upper limit, default: 10MB.")
)
sub_parser.add_argument(
"--dry-run",
default=False,
action="store_true",
help=textwrap.dedent("""Only output command, never do operation."""),
)
return parser
def __list_all_blobs(gh, args, extra_args):
git_repo_path = os.path.abspath(args.repo)
limit = args.limit
with AdUtil.chdir(git_repo_path):
all_commits = []
code, raw_all_commits = gh.rev_list(__all=None, __pretty='oneline')
raw_all_commits = raw_all_commits.split('\n')
for commit in raw_all_commits:
commit = commit.strip()
if not commit:
continue;
items = commit.split(maxsplit=2)
if len(items) < 1:
continue
commit = items[0]
all_commits.append(commit)
# Create a temporary file for following steps
commit_file_path = '.{}'.format(str(uuid.uuid4()))
open(commit_file_path, 'w+').writelines(all_commits)
commits = {}
# Parse commits one by one
for commit in all_commits:
commits[commit] = []
code, content = gh.diff_tree(commit, _r=None, _c=None, _M=None, _C=None, __no_commit_id=None)
content = content.strip()
if code != 0 or not content:
continue
objs = content.split('\n')
for obj in objs:
items = obj.split()
cid = items[3]
path = items[5]
# Deleted item
if cid == "0000000000000000000000000000000000000000":
cid = items[2]
code, size = gh.cat_file(cid, _s=None)
if code != 0:
continue
size = int(size.strip())
commits[commit].append({'path': path, 'id': cid, 'size': size})
if size > limit:
print(f"{commit}, {path}, {size}")
def main():
parser = __create_argparser()