diff --git a/.travis.yml b/.travis.yml index 2d864f6..df66aef 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,6 +3,7 @@ matrix: include: - python: 2.6 env: TOXENV=py26 + dist: trusty - python: 2.7 env: TOXENV=py27 - python: 3.4 diff --git a/.zenodo.json b/.zenodo.json index 3dda76a..0d0593e 100644 --- a/.zenodo.json +++ b/.zenodo.json @@ -1,8 +1,8 @@ -{ "metadata": { +{ "title": "git-fame: Pretty-print `git` repository collaborators sorted by contributions", "keywords": [ "git", "blame", "git-blame", "git-log", "code-analysis", "cost", "loc", "author", "commit", "shortlog", "ls-files"], "creators": [ {"name": "da Costa-Luis, Casper O.", "orcid": "0000-0002-7211-1557"}] -}} +} diff --git a/README.rst b/README.rst index 0ef5657..e8fbdad 100644 --- a/README.rst +++ b/README.rst @@ -180,6 +180,7 @@ Documentation -w, --ignore-whitespace Ignore whitespace when comparing the parent's version and the child's to find where the lines came from [default: False]. + -e, --show-email Show author email instead of name [default: False]. -M Detect intra-file line moves and copies [default: False]. -C Detect inter-file line moves and copies [default: False]. --format= Table format @@ -194,6 +195,38 @@ If multiple user names and/or emails correspond to the same user, aggregate ``git-fame`` statistics and maintain a ``git`` repository properly by adding a `.mailmap file `_. +Examples +-------- + +CODEOWNERS +~~~~~~~~~~ + +Generating +`CODEOWNERS `__: + +.. code:: sh + + # bash syntax function for current directory git repository + owners(){ + for f in $(git ls-files); do + # filename + echo -n "$f " + # author emails if loc distribution >= 30% + git fame -esnwMC --incl "$f" | tr '/' '|' \ + | awk -F '|' '(NR>6 && $6>=30) {print $2}' \ + | xargs echo + done + } + + # print to screen and file + owners | tee .github/CODEOWNERS + + # same but with `tqdm` progress for large repos + owners \ + | tqdm --total $(git ls-files | wc -l) \ + --unit file --desc "Generating CODEOWNERS" \ + > .github/CODEOWNERS + Contributions ------------- diff --git a/git-fame_completion.bash b/git-fame_completion.bash index 08d84c5..6ab25d9 100644 --- a/git-fame_completion.bash +++ b/git-fame_completion.bash @@ -23,7 +23,7 @@ _git_fame() ;; *) if [ ${COMP_WORDS[1]} == fame ]; then - COMPREPLY=($(compgen -dW '-h --help -v --version --cost --branch --since --sort --incl --excl -n --no-regex -s --silent-progress --warn-binary -t --bytype -w --ignore-whitespace -M -C --format --manpath --log' -- ${cur})) + COMPREPLY=($(compgen -dW '-h --help -v --version --cost --branch --since --sort --incl --excl -n --no-regex -s --silent-progress --warn-binary -t --bytype -w --ignore-whitespace -e --show-email -M -C --format --manpath --log' -- ${cur})) fi ;; esac diff --git a/gitfame/_gitfame.py b/gitfame/_gitfame.py index eac0f6e..c222afa 100755 --- a/gitfame/_gitfame.py +++ b/gitfame/_gitfame.py @@ -26,6 +26,7 @@ -s, --silent-progress Suppress `tqdm` [default: False]. --warn-binary Don't silently skip files which appear to be binary data [default: False]. + -e, --show-email Show author email instead of name [default: False]. -t, --bytype Show stats per file extension [default: False]. -w, --ignore-whitespace Ignore whitespace when comparing the parent's version and the child's to find where the lines @@ -59,7 +60,7 @@ RE_AUTHS = re.compile( - r'^\w+ \d+ \d+ (\d+)\nauthor (.+?)$.*?committer-time (\d+)', + r'^\w+ \d+ \d+ (\d+)\nauthor (.+?)$.*?\ncommitter-time (\d+)', flags=re.M | re.DOTALL) # finds all non-escaped commas # NB: does not support escaping of escaped character @@ -274,14 +275,25 @@ def run(args): for stats in auth_stats.values(): stats.setdefault("commits", 0) log.debug(RE_NCOM_AUTH_EM.findall(auth_commits.strip())) - for (ncom, auth, _) in RE_NCOM_AUTH_EM.findall(auth_commits.strip()): + auth2em = {} + for (ncom, auth, em) in RE_NCOM_AUTH_EM.findall(auth_commits.strip()): + auth = _str(auth) + auth2em[auth] = em # TODO: count most used email? try: - auth_stats[_str(auth)]["commits"] += int(ncom) + auth_stats[auth]["commits"] += int(ncom) except KeyError: - auth_stats[_str(auth)] = {"loc": 0, - "files": set([]), - "commits": int(ncom), - "ctimes": []} + auth_stats[auth] = {"loc": 0, + "files": set([]), + "commits": int(ncom), + "ctimes": []} + if args.show_email: + # replace author name with email + log.debug(auth2em) + old = auth_stats + auth_stats = {} + for auth, stats in getattr(old, 'iteritems', old.items)(): + auth_stats[auth2em[auth]] = stats + del old stats_tot = dict((k, 0) for stats in auth_stats.values() for k in stats) log.debug(stats_tot) diff --git a/gitfame/_version.py b/gitfame/_version.py index a0fe438..99b610a 100644 --- a/gitfame/_version.py +++ b/gitfame/_version.py @@ -12,7 +12,7 @@ __all__ = ["__version__"] # major, minor, patch, -extra -version_info = 1, 9, 1 +version_info = 1, 10, 0 # Nice string for the version __version__ = '.'.join(map(str, version_info))