Struct git2::Diff [] [src]

pub struct Diff {
    // some fields omitted
}

The diff object that contains all individual file deltas.

This is an opaque structure which will be allocated by one of the diff generator functions below (such as Diff::tree_to_tree).

Methods

impl Diff

fn tree_to_tree(repo: &Repository, old_tree: Option<&Tree>, new_tree: Option<&Tree>, opts: Option<&mut DiffOptions>) -> Result<Diff, Error>

Create a diff with the difference between two tree objects.

This is equivalent to git diff <old-tree> <new-tree>

The first tree will be used for the "old_file" side of the delta and the second tree will be used for the "new_file" side of the delta. You can pass None to indicate an empty tree, although it is an error to pass None for both the old_tree and new_tree.

fn tree_to_index(repo: &Repository, old_tree: Option<&Tree>, index: Option<&Index>, opts: Option<&mut DiffOptions>) -> Result<Diff, Error>

Create a diff between a tree and repository index.

This is equivalent to git diff --cached <treeish> or if you pass the HEAD tree, then like git diff --cached.

The tree you pass will be used for the "old_file" side of the delta, and the index will be used for the "new_file" side of the delta.

If you pass None for the index, then the existing index of the repo will be used. In this case, the index will be refreshed from disk (if it has changed) before the diff is generated.

If the tree is None, then it is considered an empty tree.

fn index_to_workdir(repo: &Repository, index: Option<&Index>, opts: Option<&mut DiffOptions>) -> Result<Diff, Error>

Create a diff between the repository index and the workdir directory.

This matches the git diff command. See the note below on tree_to_workdir for a discussion of the difference between git diff and git diff HEAD and how to emulate a git diff <treeish> using libgit2.

The index will be used for the "old_file" side of the delta, and the working directory will be used for the "new_file" side of the delta.

If you pass None for the index, then the existing index of the repo will be used. In this case, the index will be refreshed from disk (if it has changed) before the diff is generated.

fn tree_to_workdir(repo: &Repository, old_tree: Option<&Tree>, opts: Option<&mut DiffOptions>) -> Result<Diff, Error>

Create a diff between a tree and the working directory.

The tree you provide will be used for the "old_file" side of the delta, and the working directory will be used for the "new_file" side.

This is not the same as git diff <treeish> or git diff-index <treeish>. Those commands use information from the index, whereas this function strictly returns the differences between the tree and the files in the working directory, regardless of the state of the index. Use tree_to_workdir_with_index to emulate those commands.

To see difference between this and tree_to_workdir_with_index, consider the example of a staged file deletion where the file has then been put back into the working dir and further modified. The tree-to-workdir diff for that file is 'modified', but git diff would show status 'deleted' since there is a staged delete.

If None is passed for tree, then an empty tree is used.

fn tree_to_workdir_with_index(repo: &Repository, old_tree: Option<&Tree>, opts: Option<&mut DiffOptions>) -> Result<Diff, Error>

Create a diff between a tree and the working directory using index data to account for staged deletes, tracked files, etc.

This emulates git diff <tree> by diffing the tree to the index and the index to the working directory and blending the results into a single diff that includes staged deleted, etc.

fn merge(&mut self, from: &Diff) -> Result<(), Error>

Merge one diff into another.

This merges items from the "from" list into the "self" list. The resulting diff will have all items that appear in either list. If an item appears in both lists, then it will be "merged" to appear as if the old version was from the "onto" list and the new version is from the "from" list (with the exception that if the item has a pending DELETE in the middle, then it will show as deleted).

fn deltas(&self) -> Deltas

Returns an iterator over the deltas in this diff.

fn get_delta(&self, i: usize) -> Option<DiffDelta>

Return the diff delta for an entry in the diff list.

fn is_sorted_icase(&self) -> bool

Check if deltas are sorted case sensitively or insensitively.

fn print<F>(&self, format: DiffFormat, cb: F) -> Result<(), Error> where F: FnMut(DiffDelta, Option<DiffHunk>, DiffLine) -> bool

Iterate over a diff generating formatted text output.

Returning false from the callback will terminate the iteration and return an error from this function.

fn stats(&self) -> Result<DiffStats, Error>

Accumulate diff statistics for all patches.

fn find_similar(&mut self, opts: Option<&mut DiffFindOptions>) -> Result<(), Error>

Transform a diff marking file renames, copies, etc.

This modifies a diff in place, replacing old entries that look like renames or copies with new entries reflecting those changes. This also will, if requested, break modified files into add/remove pairs if the amount of change is above a threshold.

Trait Implementations

impl Send for Diff

impl Drop for Diff

fn drop(&mut self)