Skip to main content

Python library to discover commit times of all files under a git repository

Project description

This is a library for finding the commit times of all the files under a git repository.

Can be used from the commandline:

$ cd /some/repository
$ gitmit

Or as a library:

from gitmit.mit import GitTimes
print(GitTimes(root_folder, ".").find())

Options to both include:

parent_dir

The relative folder to the root of the repository that we care about. The rest of the filters are then relative to here.

timestamps_for

A list of globs specifying what to include (i.e. anything not covered by the globs is ignored)

exclude

A list of globs specifying what to exclude after timestamps_for is taken into account

include

A list of globs specifying what should be re-included after exclude is taken into account

with_cache

Boolean saying whether we should write the resulting commit times to a file under the .git folder that we can reuse in the future.

debug

Currently the only difference with debug is outputting the commits per second as we traverse the commits in the repository.

Why/History

I needed this ability in my Docker client (http://harpoon.readthedocs.org) so that I could maintain the modified times of the files in the context sent to the docker daemon between builds on my build servers (doing a git clone sets the modified times of the files to the time of the clone).

Originally I was shelling out to git log for every file. This was slow! I then moved to dulwich (python implementation of git) which was faster, but still slow. Then I implemented it with pygit2 (libgit2 c bindings in python) and decided to make it a separate library.

Unfortunately it’s still not as fast as doing a git whatchanged --pretty=%at and interpreting the results, but I rather a solution that uses libraries rather than interpreting text from the output of a program and the speed is not a problem for reasonably sized repositories.

In September 2018 I moved back to using dulwich. This is because pygit2 is a bit of a pain because of how it pins to particular versions of libgit2, which itself can be annoying to get installed such that pygit2 can find it.

Installation

Just use pip:

$ pip install gitmit

Changelog

0.5 - TBD
  • Switch to dulwich over pygit2. This is because pygit2 is a pain to install. The downside is it is slower, but only by a few seconds.

Before 0.5 no changelog was maintained

Tests

Install testing deps and run the helpful script:

$ pip install -e .
$ pip install -e ".[tests]"
$ ./test.sh

Or use tox:

$ pip install tox
$ tox

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

gitmit-0.5.tar.gz (11.1 kB view details)

Uploaded Source

File details

Details for the file gitmit-0.5.tar.gz.

File metadata

  • Download URL: gitmit-0.5.tar.gz
  • Upload date:
  • Size: 11.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.23.1 CPython/2.7.14

File hashes

Hashes for gitmit-0.5.tar.gz
Algorithm Hash digest
SHA256 e4b6ef3734cc1fe5b5d26cb44f9135bbc548553e18f1f53e30282d5afcdf7145
MD5 caadbad38b7838253775f818478360cf
BLAKE2b-256 4a1c235c8e310fc485e9400f427b2ed69fa9ca2d560cf413a1defe49e4fae93d

See more details on using hashes here.

Supported by

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