Skip to content

Commit

Permalink
add --loc=auto
Browse files Browse the repository at this point in the history
  • Loading branch information
casperdcl committed Dec 2, 2020
1 parent 692a02a commit e2a91bf
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
2 changes: 1 addition & 1 deletion git-fame_completion.bash
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ _git_fame()
COMPREPLY=($(compgen -W 'months cocomo hours commits' -- ${cur}))
;;
--loc)
COMPREPLY=($(compgen -W 'surviving insertions deletions' -- ${cur}))
COMPREPLY=($(compgen -W 'auto surviving insertions deletions' -- ${cur}))
;;
--format)
COMPREPLY=($(compgen -W 'pipe markdown yaml json csv tsv tabulate' -- ${cur}))
Expand Down
20 changes: 16 additions & 4 deletions gitfame/_gitfame.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
-v, --version Print module version and exit.
--branch=<b> Branch or tag [default: HEAD] up to which to check.
--sort=<key> [default: loc]|commits|files|hours|months.
--loc=<type> [default: surviving]|ins(ertions)|del(etions)
--loc=<type> [default: auto]|surviving|ins(ertions)|del(etions)
What `loc` represents. Use 'ins,del' to count both.
'auto' means 'surviving' unless `--cost` is specified.
--excl=<f> Excluded files (default: None).
In no-regex mode, may be a comma-separated list.
Escape (\,) for a literal comma (may require \\, in shell).
Expand All @@ -24,6 +25,8 @@
person-hours (based on commit times).
Methods: month(s)|cocomo|hour(s)|commit(s).
May be multiple comma-separated values.
Alters meaning of `--loc='auto'` to mean 'ins' (COCOMO) or
'ins,del' (hours).
-n, --no-regex Assume <f> are comma-separated exact matches
rather than regular expressions [default: False].
NB: if regex is enabled ',' is equivalent to '|'.
Expand Down Expand Up @@ -145,7 +148,6 @@ def tabulate(
))).replace('/100.0/', '/ 100/')]
for (auth, s) in it_as()]
if cost:
cost = set(cost.lower().split(','))
stats_tot = dict(stats_tot)
if cost & COST_MONTHS:
COL_NAMES.insert(1, 'mths')
Expand Down Expand Up @@ -398,6 +400,16 @@ def run(args):
include_files = re.compile(args.incl)
# include_files = re.compile(args.incl, flags=re.M)

cost = set(args.cost.lower().split(',')) if args.cost else set()
churn = args.loc
if churn == "auto":
if cost & COST_HOURS:
churn = "ins,del"
elif cost & COST_MONTHS:
churn = "ins"
else:
churn = "surviving"

auth_stats = {}
statter = partial(
_get_auth_stats,
Expand All @@ -407,7 +419,7 @@ def run(args):
ignore_whitespace=args.ignore_whitespace, M=args.M, C=args.C,
warn_binary=args.warn_binary, bytype=args.bytype,
show_email=args.show_email, prefix_gitdir=len(gitdirs) > 1,
churn=args.loc)
churn=churn)

# concurrent multi-repo processing
if len(gitdirs) > 1:
Expand Down Expand Up @@ -445,7 +457,7 @@ def run(args):

print_unicode(tabulate(
auth_stats, stats_tot,
args.sort, args.bytype, args.format, args.cost, args.enum))
args.sort, args.bytype, args.format, cost, args.enum))


def get_main_parser():
Expand Down
7 changes: 3 additions & 4 deletions gitfame/tests/tests_gitfame.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import unicode_literals

import sys
from json import loads
from os import path
from shutil import rmtree
from tempfile import mkdtemp
Expand Down Expand Up @@ -53,8 +54,8 @@ def test_tabulate():

def test_tabulate_cost():
"""Test cost estimates"""
assert (_gitfame.tabulate(
auth_stats, stats_tot, cost="hours,COCOMO") == dedent("""\
assert (_gitfame.tabulate(auth_stats, stats_tot, cost={"hours", "months"}) == dedent(
"""\
Total commits: 35
Total files: 14
Total hours: 5.5
Expand Down Expand Up @@ -116,7 +117,6 @@ def test_tabulate_yaml():

def test_tabulate_json():
"""Test JSON tabulate"""
from json import loads
res = loads(_gitfame.tabulate(auth_stats, stats_tot, backend='json'))
assert (res == loads(dedent("""\
{"total": {"files": 14, "loc": 613, "commits": 35},
Expand Down Expand Up @@ -151,7 +151,6 @@ def test_tabulate_tabulate():

def test_tabulate_enum():
"""Test --enum tabulate"""
from json import loads
res = loads(_gitfame.tabulate(
auth_stats, stats_tot, backend='json', row_nums=True))
assert res['columns'][0] == '#'
Expand Down

0 comments on commit e2a91bf

Please sign in to comment.