Function-level git commit analysis tool
Project description
DiffScope
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 namerepo(str): Repository namecommit_sha(str): Full SHA of the analyzed commitrepository_url(str): URL to the repositorycommit_author(str, optional): Author of the commitcommit_date(str, optional): Date of the commitcommit_message(str, optional): Full commit messagemodified_files(List[ModifiedFile]): List of files changed in the commitmodified_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 filestatus(str): Status of the file - 'added', 'modified', 'removed', or 'renamed'additions(int): Number of lines addeddeletions(int): Number of lines deletedchanges(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 namefile(str): File containing the functiontype(str): Type of the function ('function', 'method', etc.)change_type(FunctionChangeType): Type of change - one of:ADDED: Function was addedMODIFIED: Function was modifiedREMOVED: Function was deletedRENAMED: Function was renamed
original_start(int, optional): Start line in the old versionoriginal_end(int, optional): End line in the old versionnew_start(int, optional): Start line in the new versionnew_end(int, optional): End line in the new versionchanges(int): Number of lines changeddiff(str, optional): Function-specific difforiginal_name(str, optional): Previous name for renamed functionsoriginal_content(str, optional): Function content before changesnew_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
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
88f323255b2cc124f5670918e705083fd47fa85077582da57fe036b5add93a2c
|
|
| MD5 |
b632dd9123d77035ea6bcea15da109fd
|
|
| BLAKE2b-256 |
fe8c00c6c63218fb96f6cc316e300e98c26dbe426c94711f63f237a0d3408dd3
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5cabaef3a0ed48ed895e04358f0990f71ab8a0a9947495e37807e92432660bd1
|
|
| MD5 |
5b7ab88fc9b005f4dd5dd8cb9c2628be
|
|
| BLAKE2b-256 |
dcd2e94b3860b97c34a4dc1187dadd40a0f9ac54d18781b3d1d32b707ba41eed
|