libgit2

diff

Version:

Overview

Calculating diffs is generally done in two phases: building a diff list then traversing the diff list. This makes is easier to share logic across the various types of diffs (tree vs tree, workdir vs index, etc.), and also allows you to insert optional diff list post-processing phases, such as rename detected, in between the steps. When you are done with a diff list object, it must be freed. Terminology

To understand the diff APIs, you should know the following terms:

  • A diff or diff list represents the cumulative list of differences between two snapshots of a repository (possibly filtered by a set of file name patterns). This is the git_diff_list object.
  • A delta is a file pair with an old and new revision. The old version may be absent if the file was just created and the new version may be absent if the file was deleted. A diff is mostly just a list of deltas.
  • A binary file / delta is a file (or pair) for which no text diffs should be generated. A diff list can contain delta entries that are binary, but no diff content will be output for those files. There is a base heuristic for binary detection and you can further tune the behavior with git attributes or diff flags and option settings.
  • A hunk is a span of modified lines in a delta along with some stable surrounding context. You can configure the amount of context and other properties of how hunks are generated. Each hunk also comes with a header that described where it starts and ends in both the old and new versions in the delta.
  • A line is a range of characters inside a hunk. It could be a context line (i.e. in both old and new versions), an added line (i.e. only in the new version), or a removed line (i.e. only in the old version). Unfortunately, we don't know anything about the encoding of data in the file being diffed, so we cannot tell you much about the line content. Line data will not be NUL-byte terminated, however, because it will be just a span of bytes inside the larger file.

Objects

The diff list object that contains all individual file deltas

The diff patch is used to store all the text diffs for a delta

Structs

Description of one side of a diff entry

Description of changes to one entry

Structure describing options about how the diff should be executed

Structure describing a hunk of a diff

Pluggable similarity metric

Control behavior of rename and copy detection

Macros

Enums

Flags for diff options in via the flags value in the git_diff_options.

Flags for the delta object and the file objects on each side

What type of change is described by a git_diff_delta?

Line origin constants

Flags to control the behavior of diff rename/copy detection

Callbacks

Diff notification callback function

When iterating over a diff, callback that will be made per file

When iterating over a diff, callback that will be made per hunk

When iterating over a diff, callback that will be made per text diff line

Functions

Deallocate a diff list

Create a diff list with the difference between two tree objects

Create a diff list between a tree and repository index

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

Create a diff list between a tree and the working directory

Merge one diff list into another

Transform a diff list marking file renames, copies, etc

Loop over all deltas in a diff list issuing callbacks

Iterate over a diff generating text output like "git diff --name-status"

Look up the single character abbreviation for a delta status code

Iterate over a diff generating text output like "git diff"

Query how many diff records are there in a diff list

Query how many diff deltas are there in a diff list filtered by type

Return the diff delta and patch for an entry in the diff list

Free a git_diff_patch object

Get the delta associated with a patch

Get the number of hunks in a patch

Get line counts of each type in a patch

Get the information about a hunk in a patch

Get the number of lines in a hunk

Get data about a line in a hunk of a patch

Serialize the patch to text via callback

Get the content of a patch as a single diff text

Directly run a diff on two blobs

Directly run a diff between a blob and a buffer