Richard Möhn 1b9cb54927 Add hint to Diff.__iter__()
I'm not the guy who looks at examples in the first place and I guess
there are other people like me. When I wanted find out how to get
information out of a Diff, I looked at the documented methods and didn't
find anything. Only later @cmn showed me the [p for p in diff] example
in the documentation. Add a short piece of information that gives a hint
to those who prefer the dry API docs.
2015-04-23 16:38:55 +09:00

2.0 KiB

Diff

A diff shows the changes between trees, an index or the working dir.

pygit2.Repository.diff

Examples

# Changes between commits
>>> t0 = revparse_single('HEAD')
>>> t1 = revparse_single('HEAD^')
>>> repo.diff(t0, t1)
>>> t0.diff(t1)           # equivalent
>>> repo.diff('HEAD', 'HEAD^') # equivalent

# Get all patches for a diff
>>> diff = repo.diff('HEAD^', 'HEAD~3')
>>> patches = [p for p in diff]

# Diffing the empty tree
>>> tree = revparse_single('HEAD').tree
>>> tree.diff_to_tree()

# Diff empty tree to a tree
>>> tree = revparse_single('HEAD').tree
>>> tree.diff_to_tree(swap=True)

The Diff type

pygit2.Diff.patch

Diff.__iter__()

Returns an iterator over the deltas/patches in this diff.

Diff.__len__()

Returns the number of deltas/patches in this diff.

pygit2.Diff.merge

pygit2.Diff.find_similar

The Patch type

Attributes:

pygit2.Patch.delta

pygit2.Patch.hunks

pygit2.Patch.line_stats

The DiffDelta type

Attributes:

pygit2.DiffDelta.old_file

pygit2.DiffDelta.new_file

pygit2.DiffDelta.status

pygit2.DiffDelta.similarity

Getters:

pygit2.DiffDelta.is_binary

The DiffFile type

Attributes:

pygit2.DiffFile.path

pygit2.DiffFile.id

The DiffHunk type

pygit2.DiffHunk.old_start

pygit2.DiffHunk.old_lines

pygit2.DiffHunk.new_start

pygit2.DiffHunk.new_lines

pygit2.DiffHunk.lines