libgit2/rugged — pull request #103 by brianmario (2012-09-11 23:33:57+00:00)
Title: Wrap diff iterator API

My initial attempt at wrapping the diff iterator API recently added to libgit2.

The various `diff` methods don't accept options yet, but I'll add that asap. Wanted to open this pull to get a discussion going around where I'm taking the API so far. And so we can all get a good chuckle from my crappy C code ;)

## Quick API example:

``` ruby
r = Rugged::Repository.new('.')
diff = r.diff(commit1, commit2)

diff.deltas.each do |delta|
# ...
delta.hunks.each do |hunk|
# ...
hunk.lines.each do |line|
# ...
end
end
end
```

## New Objects

This introduces four new objects, `Rugged::Diff`, `Rugged::Diff::Delta`, `Rugged::Diff::Hunk` and `Rugged::Diff::Line`.

`Rugged::Diff` - The high-level object representing a diff, which is composed of a list of file deltas.

`Rugged::Diff::Delta` - A list of changes (hunks) from a specific file or rename.

`Rugged::Diff::Hunk` - A list of lines from a single change in a file.

`Rugged::Diff::Line` - A single line from the diff which can either be a change itself or a context line.

## New Methods

`Rugged::Tree#diff(other_tree)` is the entry point into the libgit2 code to compute the diff, but I also added a couple of "convinience" methods: `Rugged::Commit#diff(other_commit)` and `Rugged::Repository#diff(tree_or_commit1, tree_or_commit2)`.

As usual, this all needs tests. I held back because I have no idea where this API will end up.

Discuss! :)