git_filter_server/
processor.rs

1use crate::parse_error;
2use anyhow::Result;
3use std::io::{Read, Write};
4
5#[derive(PartialEq, Clone, Copy, Hash)]
6pub enum ProcessingType {
7    /// Clean filter is ran on stage
8    Clean,
9    /// Smudge filter is ran on checkout
10    Smudge,
11}
12
13impl ProcessingType {
14    pub fn name(&self) -> &'static str {
15        match self {
16            ProcessingType::Clean => "clean",
17            ProcessingType::Smudge => "smudge",
18        }
19    }
20    pub fn done_name(&self) -> &'static str {
21        match self {
22            ProcessingType::Clean => "cleaned",
23            ProcessingType::Smudge => "smudged",
24        }
25    }
26    pub fn acc_name(&self) -> &'static str {
27        match self {
28            Self::Clean => "cleaning",
29            Self::Smudge => "smudging",
30        }
31    }
32}
33
34/// This trait is used for user-defined logic of git-filter-server
35/// Typically git talks with processor via stdio, so better do not use it inside
36pub trait Processor {
37    /// Handle clean/smudge operation
38    fn process<R: Read, W: Write>(
39        &mut self,
40        _pathname: &str,
41        _process_type: ProcessingType,
42        _input: &mut R,
43        _output: &mut W,
44    ) -> Result<()> {
45        Err(parse_error!("processing is not supported").into())
46    }
47
48    /// Schedule delayed execution
49    fn schedule_process<R: Read>(
50        &mut self,
51        _pathname: &str,
52        _process_type: ProcessingType,
53        _input: &mut R,
54    ) -> Result<()> {
55        panic!("delayed processing is not implemented")
56    }
57
58    /// Get data for file, previously scheduled via schedule_process
59    fn get_scheduled<W: Write>(
60        &mut self,
61        _pathname: &str,
62        _process_type: ProcessingType,
63        _output: &mut W,
64    ) -> Result<()> {
65        panic!("delayed processing is not implemented")
66    }
67    /// Called once all files are already scheduled/processed
68    fn switch_to_wait(&mut self) {}
69
70    /// Get scheduled files ready for outputting
71    fn get_available(&mut self) -> Result<Vec<String>> {
72        panic!("delayed processing is not implemented")
73    }
74
75    /// Should processing of file be delayed?
76    /// Only use it for long-running tasks, i.e file downloading, which would be better parallelized
77    fn should_delay(&self, _pathname: &str, _process_type: ProcessingType) -> bool {
78        false
79    }
80
81    /// Does this filter supports clean/smudge?
82    fn supports_processing(&self, _process_type: ProcessingType) -> bool {
83        false
84    }
85}
86
87// Noop processor
88impl Processor for () {}