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_diff_arguments, DiffArguments, DiffTarget, FileDiff, ResolveDiffArgumentsError,
86};
87pub use tree_content::{
88    for_each_tree_diff_structured, tree_diff_contents_parallel, tree_diff_stat_parallel,
89    tree_diff_structured_entry, tree_diff_structured_parallel, TreeDiffContent, TreeDiffStructured,
90};
91
92pub mod bloom {
93    //! bloom API (re-exported at this path).
94    pub use crate::bloom::*;
95}
96pub mod combined_diff_patch {
97    //! combined_diff_patch API (re-exported at this path).
98    pub use crate::combined_diff_patch::*;
99}
100pub mod combined_tree_diff {
101    //! combined_tree_diff API (re-exported at this path).
102    pub use crate::combined_tree_diff::*;
103}
104pub mod diffstat {
105    //! diffstat API (re-exported at this path).
106    pub use crate::diffstat::*;
107}
108pub mod patch_ids {
109    //! patch_ids API (re-exported at this path).
110    pub use crate::patch_ids::*;
111}
112pub mod userdiff {
113    //! userdiff API (re-exported at this path).
114    pub use crate::userdiff::*;
115}
116pub mod merge_diff {
117    //! merge_diff API (re-exported at this path).
118    pub use crate::merge_diff::*;
119}
120pub mod merge_file {
121    //! merge_file API (re-exported at this path).
122    pub use crate::merge_file::*;
123}
124pub mod merge_trees {
125    //! merge_trees API (re-exported at this path).
126    pub use crate::merge_trees::*;
127}
128pub mod rerere {
129    //! rerere API (re-exported at this path).
130    pub use crate::rerere::*;
131}
132pub mod fmt_merge_msg {
133    //! fmt_merge_msg API (re-exported at this path).
134    pub use crate::fmt_merge_msg::*;
135}
136pub mod ws {
137    //! ASCII whitespace helpers used by the diff engine.
138    pub use crate::ws::*;
139}