Skip to main content

grit_lib/diff/
mod.rs

1//! Tree and content diffs, rename detection, merge diffs, and related helpers.
2//!
3//! Library guide: [mod](https://grit-scm.com/docs/library/diff)
4//!
5//! ```rust
6//! use grit_lib::repo::{InitOptions, Repository};
7//! # fn main() -> grit_lib::error::Result<()> {
8//! let dir = tempfile::tempdir()?;
9//! let _repo = Repository::init(dir.path(), &InitOptions::default())?;
10//! let _ = _repo.diff();
11//!
12//! # Ok(())
13//! # }
14//! ```
15mod changes;
16mod commit_files_many;
17mod core;
18pub(crate) use core::myers_rediff_changed_masks_for_region;
19mod detail;
20mod files;
21mod filter;
22mod git_histogram;
23pub mod handle;
24mod has_changes;
25pub mod hunk_id;
26mod merge_commit;
27mod no_index;
28mod options;
29mod patch_log;
30pub mod pickaxe;
31mod posix_ere;
32mod rename_lines;
33mod stat;
34pub(crate) use core::is_func_line;
35pub(crate) use posix_ere::PosixBre;
36mod targets;
37mod tree_content;
38pub(crate) use tree_content::gitlink_line;
39pub use tree_content::{bytes_for_diff, load_odb_blob_side_for_diff};
40mod unified_emit;
41mod whitespace_mode;
42
43pub use changes::{load_object_changes, FileChange, UncommittedDiff};
44pub use commit_files_many::{CommitFilesManyInput, CommitFilesManyOptions, CommitFilesResult};
45pub use core::*;
46pub use detail::FileDiff as ListedFileDiff;
47pub use detail::{line_change_counts, DiffDetail, DiffTotals, LineStat};
48pub use files::{build_file_diffs, build_file_diffs_streaming, name_status_line, DiffFilesOutput};
49pub use filter::{DiffFilter, InvalidDiffFilter};
50pub use handle::Diff;
51pub use has_changes::{
52    text_sides_differ, HAS_CHANGES_CALL_COUNT, WORKTREE_HAS_CHANGES_ENTRIES_SCANNED,
53};
54pub use hunk_id::{
55    hunk_ids, hunk_ids_with_duplicate_peers, peer_hunks_by_primary_path, peer_scope_includes_path,
56    DiffSide, HunkId, HunkIdError,
57};
58pub use merge_commit::{combined_structured_patch_body, commit_diff_files, DiffMerges};
59pub use no_index::{diff_paths, write_paths_patch, NoIndexError};
60pub use options::{
61    renames_from_config, DiffAlgorithm, DiffOptions, RenameDetection, UnknownDiffAlgorithm,
62    RENAME_DETECTION_DISABLED, WORD_LEVEL_INLINE_MAX_CHANGED_FILES,
63};
64pub use whitespace_mode::{normalize_ignore_space_change_line, WhitespaceMode};
65
66/// Unified hunk bodies (`@@` …) for two text sides using [`DiffOptions`].
67#[must_use]
68pub fn line_diff_unified_hunk_body(
69    old_content: &str,
70    new_content: &str,
71    options: &DiffOptions,
72) -> String {
73    core::unified_hunk_body_for_diff_options(old_content, new_content, options)
74}
75pub(crate) use core::{imara_unified_hunk_slices, unified_hunk_body_for_diff_options};
76pub use patch_log::{
77    write_commit_header_and_message, write_commit_log_patch, write_commits_log_patch,
78    write_diff_entry_log_patch, write_patch, write_patch_resolved, write_patch_structured,
79    LogPatchBinaryFormat, LogPatchCommitHeader, LogPatchOptions, PatchResolvedSide, PatchSide,
80    PatchTextOptions,
81};
82pub use pickaxe::{Pickaxe, PickaxeError, PickaxeKind};
83pub use stat::{DiffStat, FileStat, StatBar};
84pub use targets::hunk_diff_bundle;
85pub use targets::HunkDiffBundle;
86pub(crate) use targets::{
87    collect_files_for_target, include_file_in_diff, unstaged_file_diffs_with_peer_hunks,
88    unstaged_raw_changes_with_peer_hunks, unstaged_raw_changes_with_peer_hunks_in,
89};
90pub use targets::{
91    resolve_commit_diff_pathspecs, resolve_diff_arguments, resolve_diff_request, DiffArguments,
92    DiffRequest, DiffTarget, FileDiff, ResolveDiffArgumentsError,
93};
94pub use tree_content::{
95    for_each_tree_diff_structured, tree_diff_contents_parallel, tree_diff_stat_parallel,
96    tree_diff_structured_entry, tree_diff_structured_parallel, TreeDiffContent, TreeDiffStructured,
97};
98
99pub mod bloom {
100    //! bloom API (re-exported at this path).
101    pub use crate::bloom::*;
102}
103pub mod combined_diff_patch {
104    //! combined_diff_patch API (re-exported at this path).
105    pub use crate::combined_diff_patch::*;
106}
107pub mod combined_tree_diff {
108    //! combined_tree_diff API (re-exported at this path).
109    pub use crate::combined_tree_diff::*;
110}
111pub mod patch_ids {
112    //! patch_ids API (re-exported at this path).
113    pub use crate::patch_ids::*;
114}
115pub mod userdiff {
116    //! userdiff API (re-exported at this path).
117    pub use crate::userdiff::*;
118}
119pub mod merge_diff {
120    //! merge_diff API (re-exported at this path).
121    pub use crate::merge_diff::*;
122}
123pub mod merge_file {
124    //! merge_file API (re-exported at this path).
125    pub use crate::merge_file::*;
126}
127pub mod merge_trees {
128    //! merge_trees API (re-exported at this path).
129    pub use crate::merge_trees::*;
130}
131pub mod rerere {
132    //! rerere API (re-exported at this path).
133    pub use crate::rerere::*;
134}
135pub mod fmt_merge_msg {
136    //! fmt_merge_msg API (re-exported at this path).
137    pub use crate::fmt_merge_msg::*;
138}
139pub mod ws {
140    //! ASCII whitespace helpers used by the diff engine.
141    pub use crate::ws::*;
142}