Skip to main content

A tool to calculate change churn below the file-level

Project description

Git Churn

The purpose of this tool is to calculate change churn below the file-level. Git can already calculate churn with git log --numstat which will print how many lines of text were added and removed in each file touched by a commit. This tool prints the same information for each tag touched by a commit. A tag is any item in a source file such as a class, function, field, etc. We detect tags using Universal CTags. In effect, this tool is just some glue between ctags and git.

Install

gitchurn can be installed with pip.

pip install gitchurn

Git must also be installed. Universal CTags is also required. Please follow the link for instructions. You can test your install by running ctags --version.

Usage

Simply navigate to a git repository and run python -m gitchurn or just gitchurn. You will see something like:

9d0e3d1af0cb7e62c810ec23f97e12e86ab3cf6f	14	<tag_1>
9d0e3d1af0cb7e62c810ec23f97e12e86ab3cf6f	15	<tag_2>
a058e4559d0363ed956780e81f2e6f0d84d0ead3	2	<tag_3>

The output is always three columns delimated by tabs. The first column is the commit hash. The second column is the churn (added plus deleted lines). The last column is the tag. By default, tags are printed in a human readable format but this can be changed with --tag-format. See gitchurn --help for further options.

These churn calculations are fairly expensive and are not going to fluxuate, so it might be wise to immediately pipe the output to a file. You will also see significant performance gains by filtering down commits. See the next section for more details.

Example

For a more involved example, say we want the churn for the last 100 commits of some project. Let's use Apache DeltaSpike as an example.

git clone https://github.com/apache/deltaspike
cd deltaspike
gitchurn --git-log-args "master -n 100"

The arguments passed to --git-log-args will be fowarded to git-log. So master -n 100 means we want only the 100 most recent commits reachable from the master branch.

Now we can limit this even further. Say we are only interested in Java code which is not tests.

gitchurn --git-log-args "master -n 100 -- **/*.java :^**/src/test/**"

Everything after -- is interpreted as path information by git-log. So **/*.java is a glob telling git to only select Java files. Similarly, :^**/src/test/** tells git to exclude tests. (The :^ prefix causes git to invert the selection.)

Finally, if we want to ignore large commits (such as those caused by refactoring), we can set a maximum commit size.

gitchurn --git-log-args "master -n 100 -- **/*.java :^**/src/test/**" --max-changes 30

So any commits which have changed more than 30 non-test Java files will be excluded.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gitchurn-0.0.4.tar.gz (12.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gitchurn-0.0.4-py3-none-any.whl (14.2 kB view details)

Uploaded Python 3

File details

Details for the file gitchurn-0.0.4.tar.gz.

File metadata

  • Download URL: gitchurn-0.0.4.tar.gz
  • Upload date:
  • Size: 12.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.8.5

File hashes

Hashes for gitchurn-0.0.4.tar.gz
Algorithm Hash digest
SHA256 3121881f8f3a5533f82dd1ecede476a9c42e73168ed8ba44b4ae75e043503879
MD5 daae51bfe4b8a43715b3429ae67a646e
BLAKE2b-256 9b194ee97e06c343966779b1c9a640979f882879f96c181aeb7109edea7061a5

See more details on using hashes here.

File details

Details for the file gitchurn-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: gitchurn-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 14.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.8.5

File hashes

Hashes for gitchurn-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 ab10d3825f0a98cf5dc08e4ecbd4dfc89615ea80a00215193394994adadc0e80
MD5 fd42f097bf098879ad5be1bb05bc9716
BLAKE2b-256 3b0ffea4beb497926562c3a4df31a3c9fa543fdfd913962de480616376c4b8bd

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page