From fda8f3490e14b909e7a827bd98800abc35560291 Mon Sep 17 00:00:00 2001 From: BHA Date: Thu, 16 Nov 2023 15:21:16 +0300 Subject: [PATCH] until part added --until arg added for searching from-to date --- git-fame_completion.bash | 4 ++-- gitfame/_gitfame.py | 18 +++++++++++++----- gitfame/git-fame.1 | 4 ++++ 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/git-fame_completion.bash b/git-fame_completion.bash index e8e8394..dd41ddc 100644 --- a/git-fame_completion.bash +++ b/git-fame_completion.bash @@ -33,12 +33,12 @@ _git_fame() --manpath) COMPREPLY=($(compgen -d -- "${cur}")) ;; - --incl|--excl|--since|--ignore-rev) + --incl|--excl|--since|--ignore-rev|--until) COMPREPLY=( ) ;; *) if [ ${COMP_WORDS[1]} == fame ]; then - COMPREPLY=($(compgen -dW '-h --help -v --version --cost --branch --since --sort --loc --incl --excl -R --recurse -n --no-regex -s --silent-progress --warn-binary -t --bytype -w --ignore-whitespace -e --show-email --enum -M -C --ignore-rev --ignore-revs-file --format --manpath --log' -- ${cur})) + COMPREPLY=($(compgen -dW '-h --help -v --version --cost --branch --since --until --sort --loc --incl --excl -R --recurse -n --no-regex -s --silent-progress --warn-binary -t --bytype -w --ignore-whitespace -e --show-email --enum -M -C --ignore-rev --ignore-revs-file --format --manpath --log' -- ${cur})) fi ;; esac diff --git a/gitfame/_gitfame.py b/gitfame/_gitfame.py index 511c2c8..1ca3fb1 100755 --- a/gitfame/_gitfame.py +++ b/gitfame/_gitfame.py @@ -21,6 +21,8 @@ --incl= Included files [default: .*]. See `--excl` for format. --since= Date from which to check. Can be absoulte (eg: 1970-01-31) or relative to now (eg: 3.weeks). + --until= Date to which to check. Can be absoulte (eg: 1970-01-31) + or relative to now (eg: 3.weeks). --cost= Include time cost in person-months (COCOMO) or person-hours (based on commit times). Methods: month(s)|cocomo|hour(s)|commit(s). @@ -207,8 +209,9 @@ def tabulate(auth_stats, stats_tot, sort='loc', bytype=False, backend='md', cost def _get_auth_stats(gitdir, branch="HEAD", since=None, include_files=None, exclude_files=None, silent_progress=False, ignore_whitespace=False, M=False, C=False, warn_binary=False, bytype=False, show_email=False, prefix_gitdir=False, - churn=None, ignore_rev="", ignore_revs_file=None): + churn=None, ignore_rev="", ignore_revs_file=None, until=None): """Returns dict: {"": {"loc": int, "files": {}, "commits": int, "ctimes": [int]}}""" + until = ["--until", until] if until else [] since = ["--since", since] if since else [] git_cmd = ["git", "-C", gitdir] log.debug("base command:%s", ' '.join(git_cmd)) @@ -225,13 +228,13 @@ def _get_auth_stats(gitdir, branch="HEAD", since=None, include_files=None, exclu churn = churn or set() if churn & CHURN_SLOC: - base_cmd = git_cmd + ["blame", "--line-porcelain"] + since + base_cmd = git_cmd + ["blame", "--line-porcelain"] + since + until if ignore_rev: base_cmd.extend(["--ignore-rev", ignore_rev]) if ignore_revs_file: base_cmd.extend(["--ignore-revs-file", ignore_revs_file]) else: - base_cmd = git_cmd + ["log", "--format=aN%aN ct%ct", "--numstat"] + since + base_cmd = git_cmd + ["log", "--format=aN%aN ct%ct", "--numstat"] + since + until if ignore_whitespace: base_cmd.append("-w") @@ -278,6 +281,11 @@ def stats_append(fname, auth, loc, tstamp): # preventing user with nearest commit to boundary owning the LOC blame_out = RE_BLAME_BOUNDS.sub('', blame_out) + if until: + # Strip boundary messages, + # preventing user with nearest commit to boundary owning the LOC + blame_out = RE_BLAME_BOUNDS.sub('', blame_out) + for loc, auth, tstamp in RE_AUTHS_BLAME.findall(blame_out): # for each chunk loc = int(loc) stats_append(fname, auth, loc, tstamp) @@ -311,7 +319,7 @@ def stats_append(fname, auth, loc, tstamp): # quickly count commits (even if no surviving loc) log.log(logging.NOTSET, "authors:%s", '; '.join(auth_stats.keys())) - auth_commits = check_output(git_cmd + ["shortlog", "-s", "-e", branch] + since) + auth_commits = check_output(git_cmd + ["shortlog", "-s", "-e", branch] + since + until) for stats in auth_stats.values(): stats.setdefault("commits", 0) log.debug(RE_NCOM_AUTH_EM.findall(auth_commits.strip())) @@ -412,7 +420,7 @@ def run(args): " which may need to be added to --excl") auth_stats = {} - statter = partial(_get_auth_stats, branch=args.branch, since=args.since, + statter = partial(_get_auth_stats, branch=args.branch, since=args.since, until=args.until, include_files=include_files, exclude_files=exclude_files, silent_progress=args.silent_progress, ignore_whitespace=args.ignore_whitespace, M=args.M, C=args.C, diff --git a/gitfame/git-fame.1 b/gitfame/git-fame.1 index 9636124..ec11c94 100644 --- a/gitfame/git-fame.1 +++ b/gitfame/git-fame.1 @@ -81,6 +81,10 @@ See \f[V]--excl\f[R] for format. Date from which to check. Can be absoulte (eg: 1970-01-31) or relative to now (eg: 3.weeks). .TP +--until=\f[I]date\f[R] +Date to which to check. +Can be absoulte (eg: 1970-01-31) or relative to now (eg: 3.weeks). +.TP --cost=\f[I]method\f[R] Include time cost in person-months (COCOMO) or person-hours (based on commit times).