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