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