Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
258 changes: 227 additions & 31 deletions src/daemon.rs

Large diffs are not rendered by default.

30 changes: 30 additions & 0 deletions src/daemon/analyzers/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::daemon::domain::{AnalysisResult, NormalizedCommand};
use crate::error::GitAiError;
use crate::git::cli_parser::parse_git_cli_args;
use std::collections::HashMap;
use std::path::Path;
use std::sync::Arc;
Expand Down Expand Up @@ -109,3 +110,32 @@ pub(crate) fn normalized_args(argv: &[String]) -> Vec<String> {
argv.to_vec()
}
}

pub(crate) fn checkout_is_path_checkout(cmd: &NormalizedCommand) -> bool {
let args = if cmd.invoked_args.is_empty() {
parse_git_cli_args(&normalized_args(&cmd.raw_argv)).command_args
} else {
cmd.invoked_args.clone()
};
let mut positionals = 0usize;
let mut skip_option_value = false;
for arg in &args {
if skip_option_value {
skip_option_value = false;
continue;
}
match arg.as_str() {
"--" | "-p" | "--patch" | "--ours" | "--theirs" => return true,
"-b" | "-B" | "--orphan" | "--conflict" => skip_option_value = true,
value if value.starts_with("--pathspec") => return true,
value if value.starts_with('-') => {}
_ => {
positionals += 1;
if positionals > 1 {
return true;
}
}
}
}
false
}
14 changes: 4 additions & 10 deletions src/daemon/analyzers/workspace.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use crate::daemon::analyzers::{AnalysisView, CommandAnalyzer, command_args, normalized_args};
use crate::daemon::analyzers::{
AnalysisView, CommandAnalyzer, checkout_is_path_checkout, command_args, normalized_args,
};
use crate::daemon::domain::{
AnalysisResult, CommandClass, Confidence, NormalizedCommand, SemanticEvent, StashOpKind,
};
Expand All @@ -14,7 +16,6 @@ impl CommandAnalyzer for WorkspaceAnalyzer {
state: AnalysisView<'_>,
) -> Result<AnalysisResult, GitAiError> {
let name = cmd.primary_command.as_deref().unwrap_or_default();
let args = command_args(cmd);

let mut events = Vec::new();
match name {
Expand All @@ -26,7 +27,7 @@ impl CommandAnalyzer for WorkspaceAnalyzer {
});
}
"checkout" => {
if is_path_checkout(&args) {
if checkout_is_path_checkout(cmd) {
events.push(SemanticEvent::CheckoutPaths);
} else if let Some(change) = cmd.ref_changes.first() {
events.push(SemanticEvent::RefUpdated {
Expand Down Expand Up @@ -87,13 +88,6 @@ fn infer_stash_kind(args: &[String]) -> StashOpKind {
}
}

fn is_path_checkout(args: &[String]) -> bool {
args.iter().any(|arg| arg == "--")
|| args
.iter()
.any(|arg| arg.starts_with("--pathspec") || arg == "--ours" || arg == "--theirs")
}

fn current_head_for_workspace_command(
cmd: &NormalizedCommand,
refs: &std::collections::HashMap<String, String>,
Expand Down
13 changes: 3 additions & 10 deletions src/daemon/family_actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,17 +110,10 @@ pub fn spawn_family_actor(family_key: FamilyKey) -> FamilyActorHandle {
match msg {
FamilyMsg::Apply(cmd, respond_to) => {
let mut cmd = *cmd;
let result = ref_cursor.enrich_command(&mut cmd, &state).and_then(
|command_start_refs| {
reducer::reduce_family_command_with_ref_snapshot(
&mut state,
cmd,
&analyzers,
&command_start_refs,
)
let result = ref_cursor.enrich_command(&mut cmd, &state).and_then(|()| {
reducer::reduce_family_command(&mut state, cmd, &analyzers)
.map(|(applied, _)| applied)
},
);
});
let _ = respond_to.send(result);
}
FamilyMsg::ApplyCheckpoint(respond_to) => {
Expand Down
Loading