Skip to main content

Function-level git commit analysis tool

Project description

DiffScope

PyPI version License

Function-level git commit analysis tool. DiffScope helps you analyze Git commits to identify which functions were modified, added, or deleted.

Features

  • Analyze GitHub commits at both file and function levels
  • Identify exactly which functions were changed in each commit
  • Detect function changes including signature, body, and docstring changes
  • Supports multiple programming languages (Python, JavaScript, TypeScript, Java, C/C++, Go)
  • Simple Python API and command-line interface

Installation

pip install diffscope

Quick Start

Command Line

# Basic analysis with text output
diffscope https://github.com/owner/repo/commit/sha

# JSON output format
diffscope https://github.com/owner/repo/commit/sha --format json

Python API

The analyze_commit() function returns a CommitAnalysisResult object that contains all the analysis data:

from diffscope import analyze_commit

# Analyze a GitHub commit
result = analyze_commit("https://github.com/owner/repo/commit/sha")
# result is a CommitAnalysisResult object

# Print file-level changes
print(f"Files changed: {len(result.modified_files)}")
for file in result.modified_files:
    print(f"- {file.filename}: +{file.additions} -{file.deletions}")

# Print function-level changes
print(f"Functions changed: {len(result.modified_functions)}")
for function in result.modified_functions:
    print(f"- {function.name} in {function.file}: {function.change_type}")

Data Models

CommitAnalysisResult

class CommitAnalysisResult:
    """Contains the results of analyzing a git commit."""

Attributes:

  • owner (str): Repository owner name
  • repo (str): Repository name
  • commit_sha (str): Full SHA of the analyzed commit
  • repository_url (str): URL to the repository
  • commit_author (str, optional): Author of the commit
  • commit_date (str, optional): Date of the commit
  • commit_message (str, optional): Full commit message
  • modified_files (List[ModifiedFile]): List of files changed in the commit
  • modified_functions (List[ModifiedFunction]): List of functions changed in the commit

ModifiedFile

class ModifiedFile:
    """Information about a modified file in a commit."""

Attributes:

  • filename (str): Path to the file
  • status (str): Status of the file - 'added', 'modified', 'removed', or 'renamed'
  • additions (int): Number of lines added
  • deletions (int): Number of lines deleted
  • changes (int): Total number of changes (additions + deletions)
  • language (str, optional): Programming language of the file (if detected)
  • patch (str, optional): Unified diff patch for the file (if available)
  • previous_filename (str, optional): Original path for renamed files

ModifiedFunction

class ModifiedFunction:
    """Information about a modified function in a commit."""

Attributes:

  • name (str): Function name
  • file (str): File containing the function
  • type (str): Type of the function ('function', 'method', etc.)
  • change_type (FunctionChangeType): Type of change - one of:
    • ADDED: Function was added
    • MODIFIED: Function was modified
    • REMOVED: Function was deleted
    • RENAMED: Function was renamed
  • original_start (int, optional): Start line in the old version
  • original_end (int, optional): End line in the old version
  • new_start (int, optional): Start line in the new version
  • new_end (int, optional): End line in the new version
  • changes (int): Number of lines changed
  • diff (str, optional): Function-specific diff
  • original_name (str, optional): Previous name for renamed functions
  • original_content (str, optional): Function content before changes
  • new_content (str, optional): Function content after changes

GitHub Authentication

To avoid rate limits, set a GitHub token:

export GITHUB_TOKEN=your_token_here  # Linux/Mac
$env:GITHUB_TOKEN="your_token_here"  # Windows PowerShell
set GITHUB_TOKEN=your_token_here     # Windows CMD

Example Use Cases

  • Code Review: Focus on specific function changes
  • Documentation: Track function-level changes in components
  • Impact Analysis: Understand the scope of changes
  • Migration: Analyze patterns across multiple commits

Documentation

For more detailed information:

License

Apache License 2.0

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

diffscope-0.1.2.tar.gz (52.8 kB view details)

Uploaded Source

Built Distribution

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

diffscope-0.1.2-py3-none-any.whl (32.9 kB view details)

Uploaded Python 3

File details

Details for the file diffscope-0.1.2.tar.gz.

File metadata

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

File hashes

Hashes for diffscope-0.1.2.tar.gz
Algorithm Hash digest
SHA256 88f323255b2cc124f5670918e705083fd47fa85077582da57fe036b5add93a2c
MD5 b632dd9123d77035ea6bcea15da109fd
BLAKE2b-256 fe8c00c6c63218fb96f6cc316e300e98c26dbe426c94711f63f237a0d3408dd3

See more details on using hashes here.

File details

Details for the file diffscope-0.1.2-py3-none-any.whl.

File metadata

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

File hashes

Hashes for diffscope-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 5cabaef3a0ed48ed895e04358f0990f71ab8a0a9947495e37807e92432660bd1
MD5 5b7ab88fc9b005f4dd5dd8cb9c2628be
BLAKE2b-256 dcd2e94b3860b97c34a4dc1187dadd40a0f9ac54d18781b3d1d32b707ba41eed

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