gix_filter/eol/
mod.rs

1///
2pub mod convert_to_git;
3pub use convert_to_git::function::convert_to_git;
4
5///
6pub mod convert_to_worktree;
7pub use convert_to_worktree::convert_to_worktree;
8
9mod utils;
10
11/// The kind of end of lines to set.
12///
13/// The default is implemented to be the native line ending for the current platform.
14#[derive(Debug, Copy, Clone, Eq, PartialEq)]
15pub enum Mode {
16    /// Equivalent to `git` (`\n`) line-endings.
17    Lf,
18    /// Equivalent to `windows` (`\r\n`) line-endings.
19    CrLf,
20}
21
22/// Possible states for the `core.autocrlf`.
23#[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
24pub enum AutoCrlf {
25    /// The same as if the `text eol=lf` attribute is set.
26    Input,
27    /// The same as if the `text eol=crlf` attribute is set.
28    Enabled,
29    /// No conversion is performed.
30    #[default]
31    Disabled,
32}
33
34/// The combination of `crlf`, `text` and `eol` attributes into one neat package.
35#[derive(Debug, Copy, Clone, Eq, PartialEq)]
36pub enum AttributesDigest {
37    /// Equivalent to the `-text` attribute.
38    Binary,
39    /// Equivalent to the `text` attribute.
40    Text,
41    /// Equivalent to the `text eol=lf` attributes.
42    TextInput,
43    /// Equivalent to the `text eol=crlf` attributes.
44    TextCrlf,
45    /// Equivalent to the `text=auto` attributes.
46    TextAuto,
47    /// Equivalent to the `text=auto eol=crlf` attributes.
48    TextAutoCrlf,
49    /// Equivalent to the `text=auto eol=lf` attributes.
50    TextAutoInput,
51}
52
53impl From<Mode> for AttributesDigest {
54    fn from(value: Mode) -> Self {
55        match value {
56            Mode::Lf => AttributesDigest::TextInput,
57            Mode::CrLf => AttributesDigest::TextCrlf,
58        }
59    }
60}
61
62impl From<AutoCrlf> for AttributesDigest {
63    fn from(value: AutoCrlf) -> Self {
64        match value {
65            AutoCrlf::Input => AttributesDigest::TextAutoInput,
66            AutoCrlf::Enabled => AttributesDigest::TextAutoCrlf,
67            AutoCrlf::Disabled => AttributesDigest::Binary,
68        }
69    }
70}
71
72/// Git Configuration that affects how CRLF conversions are applied.
73#[derive(Default, Debug, Copy, Clone)]
74pub struct Configuration {
75    /// Corresponds to `core.autocrlf`.
76    pub auto_crlf: AutoCrlf,
77    /// Corresponds to `core.eol`, and is `None` if unset or set to `native`, or `Some(<mode>)` respectively.
78    pub eol: Option<Mode>,
79}
80
81/// Statistics about a buffer that helps to safely perform EOL conversions
82#[derive(Debug, Default, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
83pub struct Stats {
84    /// The amount of null bytes.
85    pub null: usize,
86    /// The amount of lone carriage returns (`\r`).
87    pub lone_cr: usize,
88    /// The amount of lone line feeds (`\n`).
89    pub lone_lf: usize,
90    /// The amount carriage returns followed by line feeds
91    pub crlf: usize,
92    /// The estimate of printable characters.
93    pub printable: usize,
94    /// The estimate of characters that can't be printed.
95    pub non_printable: usize,
96}