https://github.com/nagaokayuji/diff3
A simple implementation of Myers' diff algorithm and a three-way merge algorithm (diff3) in Python.
https://github.com/nagaokayuji/diff3
diff diff3 myers-algorithm python3
Last synced: 3 months ago
JSON representation
A simple implementation of Myers' diff algorithm and a three-way merge algorithm (diff3) in Python.
- Host: GitHub
- URL: https://github.com/nagaokayuji/diff3
- Owner: nagaokayuji
- License: mit
- Created: 2025-02-23T16:25:07.000Z (3 months ago)
- Default Branch: main
- Last Pushed: 2025-02-24T05:58:25.000Z (3 months ago)
- Last Synced: 2025-02-24T06:31:34.355Z (3 months ago)
- Topics: diff, diff3, myers-algorithm, python3
- Language: Python
- Homepage:
- Size: 12.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# diff & diff3 in Python
A simple implementation of Myers' diff algorithm and a three-way merge algorithm (diff3) in Python.
This library enables you to compare two sequences efficiently and perform three-way merging for version control or conflict resolution.## Features
- Implements **Myers' diff algorithm** for calculating differences between two sequences.
- Implements **diff3 algorithm** for three-way merging based on the following reference:
- https://www.cis.upenn.edu/~bcpierce/papers/diff3-short.pdf
- **Lightweight and dependency-free**, making it easy to integrate into any project.
- **Compatible with Python 3.9+**.
- **No guarantees** on correctness or robustness – use at your own risk.
- **MIT License** – free to use and modify.## Installation
You can install the package via `pip`:
```sh
pip install git+https://github.com/nagaokayuji/diff3.git
```Or, clone the repository and install locally:
```sh
git clone https://github.com/nagaokayuji/diff3.git
cd diff3
pip install .
```## Usage
### diff
```python
from diff3 import difforiginal = list("ABCABBA")
target = list("CBABAC")
diff_result = diff(original, target)
print(diff_result)
# Output:
# [- A, - B, C, + B, A, B, - B, A, + C]
```### diff3 (Three-way Merge)
```python
from diff3 import mergebase = ['a', 'b', 'c', 'd', 'e']
a = ['a', 'b', 'c', 'cc', 'd', 'e']
b = ['a', 'c', 'd', 'dd', 'e', 'f']merged = merge(base, a, b)
print(merged)
# Output:
# a
# c
# cc
# d
# dd
# e
# f
```## Running Tests
Unit tests are included. To run all tests, use:
```sh
PYTHONPATH=src python -m unittest discover test
```## License
This project is licensed under the MIT License.