Skip to main content

A Python library for easy and performant querying and parsing of Git repositories.

Project description

The gitplier library

A Python library for easy and performant querying and parsing of Git repositories.

  • When used correctly, it's fast. See the example below.
  • Understands specific types of repositories (stable kernel, RHEL kernel) and offers specialized methods for them.
  • Has no Python dependencies. At run time, it requires the git binary in the system.
  • Unlike naive attempts to execute git, gitplier runs correctly even with exotic git configurations.

Goals

The intention of this library is to become a kitchen sink of useful functions. Still, the functions should be as generic as possible. When making a function more generic requires more verbosity at the function call sites, we opt for more verbosity.

We aim for backward compatible API. Making the development of the library easier is never an excuse for breaking users.

The API

Anything starting with an underscore does not constitute API and should not be used. Always import the gitplier module and use the symbols from it. E. g., use only gitplier.GitError, despite internally it being gitplier._exceptions.GitError.

Do not depend on the GitError message content. It's meant for human consumption, not for programmatic parsing.

Example

Calculate how many per cent of stable commits were backported to CentOS Stream 9. This completes in about 6 seconds on a moderate machine.

import gitplier
import os

# Open the kernel stable repository.
stable = gitplier.kernel.KernelStableRepository(os.path.expanduser('~/git/stable'))
# Create a set that will hold all upstream commits referenced from the stable commits.
in_stable = set()
# Examine all stable branches from v5.14 on.
for branch_name, upstream_tag in stable.stable_branches(since='v5.14'):
    in_stable.update(
        commit.upstream
        for commit in stable.log(upstream_tag, branch_name, fields=(), include_merges=False)
        # Walk all commits in the branch. Ignore merges. To speed up the walking, do not
        # fetch any additional field.
    )

# Open the CentOS Stream 9 repository.
cs9 = gitplier.kernel.KernelRHELRepository(os.path.expanduser('~/git/centos-stream-9'))
# Count the upstream references in the CS9 tree that are also backported to stable.
count = sum(
    len(set(commit.upstream).intersection(in_stable))
    for commit in cs9.log('v5.14', 'main', fields=(), include_merges=False)
)

print(f'{count / len(in_stable) * 100:.1f}%')

Why not pygit2?

All git operations in gitplier are performed by executing the external git command. The disadvantages of that are clear but the advantages outweight them:

  1. No compatibility problems. libgit2 (and thus pygit2) does not support new git features and sometimes exhibits compatibility bugs.

  2. Easier to use API. Where pygit2 has a specific Oid type, gitplier has just a string. Etc.

  3. No dependency problems. While pygit2 and libgit2 do better job than most libraries out there, they do not have a stable API. You need to use the right versions when working with them.

  4. Performance. As surprising as it is, libgit2 is so slow that doing tons of fork/exec calls is significantly faster for most operations.

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

gitplier-1.0.2.tar.gz (23.9 kB view details)

Uploaded Source

Built Distribution

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

gitplier-1.0.2-py3-none-any.whl (28.4 kB view details)

Uploaded Python 3

File details

Details for the file gitplier-1.0.2.tar.gz.

File metadata

  • Download URL: gitplier-1.0.2.tar.gz
  • Upload date:
  • Size: 23.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.7

File hashes

Hashes for gitplier-1.0.2.tar.gz
Algorithm Hash digest
SHA256 f5d904652d24f9da4a53268a7fe6bd5541a50f547e5ef595ee33fbebe0eb0871
MD5 4b17807dd4ebce9c01332441f30d11d2
BLAKE2b-256 76ddb0209d1ef78005bce8dfee47fbefb2c3e57bb3b3a43ccccf8ed99e29a11f

See more details on using hashes here.

File details

Details for the file gitplier-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: gitplier-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 28.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.7

File hashes

Hashes for gitplier-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 1da1581e57e633f2bf268fc5a3988d4460a511745f3131b3c95336ce8337868a
MD5 57ba8aaaf4b2e7bfd35a620746cbb58d
BLAKE2b-256 6fbbee5fbc817f03ac176f7ed510463c8f2936410e93e60173eb1aa9f15cf25a

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