libgit2

diff

Version:

Overview

Calculating diffs is generally done in two phases: building a list of diffs then traversing it. 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 post-processing phases, such as rename detection, in between the steps. When you are done with a diff object, it must be freed. Terminology

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

  • A diff 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 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 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 object that contains all individual file deltas

This is an opaque structure which is allocated by git_diff_get_stats You are responsible for releasing the object memory when done, using the git_diff_stats_free() function.

Structs

Description of one side of a delta

Description of changes to one entry

Structure describing options about how the diff should be executed

The contents of one of the files in a binary diff

Structure describing the binary contents of a diff

Structure describing a hunk of a diff

Structure describing a line (or data span) of a diff

Pluggable similarity metric

Control behavior of rename and copy detection

Options for controlling the formatting of the generated e-mail

Patch ID options structure

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?

When producing a binary diff, the binary data returned will be either the deflated full ("literal") contents of the file, or the deflated binary delta between the two sides (whichever is smaller)

Line origin constants

Flags to control the behavior of diff rename/copy detection

Possible output formats for diff data

Formatting options for diff stats

Formatting options for diff e-mail generation

Callbacks

Diff notification callback function

Diff progress callback

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

When iterating over a diff, callback that will be made for binary content within the diff

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

Initializes a git_diff_options with default values creating an instance with GIT_DIFF_OPTIONS_INIT.

Initializes a git_diff_find_options with default values creating an instance with GIT_DIFF_FIND_OPTIONS_INIT.

Deallocate a diff

Create a diff with the difference between two tree objects

Create a diff between a tree and repository index

Create a diff between the repository index and the workdir directory

Create a diff between a tree and the working directory

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

Create a diff with the difference between two index objects

Merge one diff into another

Transform a diff marking file renames, copies, etc

Query how many diff records are there in a diff

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

Return the diff delta for an entry in the diff list

Check if deltas are sorted case sensitively or insensitively

Loop over all deltas in a diff issuing callbacks

Look up the single character abbreviation for a delta status code

Iterate over a diff generating formatted text output

Produce the complete formatted text output from a diff into a buffer

Directly run a diff on two blobs

Directly run a diff between a blob and a buffer

Directly run a diff between two buffers

Read the contents of a git patch file into a git_diff object

Accumulate diff statistics for all patches

Get the total number of files changed in a diff

Get the total number of insertions in a diff

Get the total number of deletions in a diff

Print diff statistics to a git_buf

Create an e-mail ready patch from a diff

Create an e-mail ready patch for a commit

Calculate the patch ID for the given patch