Skip to content
Library to parse and apply unified diffs
Python C++ C Other
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
doc other/pack.py: Moved to https://pypi.python.org/pypi/pypack Sep 15, 2016
tests
.travis.yml .travis.yml: Python 3.3 is phased out Aug 28, 2019
README.md README.md Add PyPI badge Aug 28, 2019
patch.py

README.md

Library to parse and apply unified diffs.

Build Status PyPI

Features

  • Python 2 and 3 compatible
  • Automatic correction of
    • Linefeeds according to patched file
    • Diffs broken by stripping trailing whitespace
    • a/ and b/ prefixes
  • Single file, which is a command line tool and a library
  • No dependencies outside Python stdlib
  • Patch format detection (SVN, HG, GIT)
  • Nice diffstat histogram
  • Linux / Windows / OS X
  • Test coverage

Things that don't work out of the box:

  • File renaming, creation and removal
  • Directory tree operations
  • Version control specific properties
  • Non-unified diff formats

Usage

Download patch.py and run it with Python. It is a self-contained module without external dependencies.

patch.py diff.patch

You can also run the .zip file.

python patch-1.16.zip diff.patch

Installation

patch.py is self sufficient. You can copy it into your repository and use it from here. This setup will always be repeatable. But if you need to add patch module as a dependency, make sure to use strict specifiers to avoid hitting an API break when version 2 is released:

pip install "patch==1.*"

Other stuff

You can’t perform that action at this time.