Replace gix with configurable libgit2 diffs
This commit is contained in:
@@ -12,6 +12,12 @@ pub(super) struct PreferenceDraft {
|
||||
pub(super) endpoint_cors: bool,
|
||||
pub(super) dev_brain_enabled: bool,
|
||||
pub(super) dev_brain_vault_path: String,
|
||||
pub(super) git_diff_algorithm: GitDiffAlgorithm,
|
||||
pub(super) git_context_lines: String,
|
||||
pub(super) git_interhunk_lines: String,
|
||||
pub(super) git_indent_heuristic: bool,
|
||||
pub(super) git_whitespace: GitDiffWhitespace,
|
||||
pub(super) git_ignore_blank_lines: bool,
|
||||
pub(super) context_tokens: String,
|
||||
pub(super) max_generated_tokens: String,
|
||||
pub(super) system_prompt: text_editor::Content,
|
||||
@@ -64,6 +70,12 @@ impl PreferenceDraft {
|
||||
endpoint_cors: config.endpoint.cors,
|
||||
dev_brain_enabled: config.dev_brain.enabled,
|
||||
dev_brain_vault_path: config.dev_brain.vault_path.clone().unwrap_or_default(),
|
||||
git_diff_algorithm: config.git.diff_algorithm,
|
||||
git_context_lines: config.git.context_lines.to_string(),
|
||||
git_interhunk_lines: config.git.interhunk_lines.to_string(),
|
||||
git_indent_heuristic: config.git.indent_heuristic,
|
||||
git_whitespace: config.git.whitespace,
|
||||
git_ignore_blank_lines: config.git.ignore_blank_lines,
|
||||
context_tokens: generation.context_tokens.to_string(),
|
||||
max_generated_tokens: generation.max_generated_tokens.to_string(),
|
||||
system_prompt: text_editor::Content::with_text(&generation.system_prompt),
|
||||
@@ -126,6 +138,17 @@ impl PreferenceDraft {
|
||||
Ok(preferences)
|
||||
}
|
||||
|
||||
pub(super) fn git(&self) -> Result<GitConfig, String> {
|
||||
Ok(GitConfig {
|
||||
diff_algorithm: self.git_diff_algorithm,
|
||||
context_lines: parse_u32("Git diff context lines", &self.git_context_lines)?,
|
||||
interhunk_lines: parse_u32("Git diff interhunk lines", &self.git_interhunk_lines)?,
|
||||
indent_heuristic: self.git_indent_heuristic,
|
||||
whitespace: self.git_whitespace,
|
||||
ignore_blank_lines: self.git_ignore_blank_lines,
|
||||
})
|
||||
}
|
||||
|
||||
pub(super) fn reset(&mut self) {
|
||||
*self = Self::from_saved(&Config::default());
|
||||
}
|
||||
@@ -248,6 +271,13 @@ fn parse_optional_u32(name: &str, value: &str) -> Result<Option<u32>, String> {
|
||||
parse_optional_number(name, value)
|
||||
}
|
||||
|
||||
fn parse_u32(name: &str, value: &str) -> Result<u32, String> {
|
||||
value
|
||||
.trim()
|
||||
.parse()
|
||||
.map_err(|_| format!("{name} must be a non-negative whole number."))
|
||||
}
|
||||
|
||||
fn parse_optional_u8(name: &str, value: &str) -> Result<Option<u8>, String> {
|
||||
parse_optional_number(name, value)
|
||||
}
|
||||
@@ -363,6 +393,13 @@ impl App {
|
||||
return;
|
||||
}
|
||||
};
|
||||
let git = match self.preference_draft.git() {
|
||||
Ok(git) => git,
|
||||
Err(error) => {
|
||||
self.preference_error = Some(error);
|
||||
return;
|
||||
}
|
||||
};
|
||||
let config = Config {
|
||||
model: self.preference_draft.model,
|
||||
idle_timeout_minutes,
|
||||
@@ -378,6 +415,7 @@ impl App {
|
||||
},
|
||||
generation,
|
||||
runtime,
|
||||
git,
|
||||
interface: self.config.interface.clone(),
|
||||
};
|
||||
if let Err(error) = config.validate() {
|
||||
|
||||
Reference in New Issue
Block a user