Skip to content

Commit

Permalink
Merge pull request #92 from bhalbayrak/bha
Browse files Browse the repository at this point in the history
until part added
  • Loading branch information
casperdcl authored Nov 16, 2023
2 parents b18ffe2 + fda8f34 commit 687643b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
4 changes: 2 additions & 2 deletions git-fame_completion.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 13 additions & 5 deletions gitfame/_gitfame.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
--incl=<f> Included files [default: .*]. See `--excl` for format.
--since=<date> Date from which to check. Can be absoulte (eg: 1970-01-31)
or relative to now (eg: 3.weeks).
--until=<date> Date to which to check. Can be absoulte (eg: 1970-01-31)
or relative to now (eg: 3.weeks).
--cost=<method> Include time cost in person-months (COCOMO) or
person-hours (based on commit times).
Methods: month(s)|cocomo|hour(s)|commit(s).
Expand Down Expand Up @@ -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: {"<author>": {"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))
Expand All @@ -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")
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()))
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions gitfame/git-fame.1
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down

0 comments on commit 687643b

Please sign in to comment.