Extract every catalog metric. Function/class facts are per declared subject; absent constructs are not applicable. Clone scope is exactly the supplied same-language files, with exact tokens and an explicit minimum window size. Unchanged comparison files may be supplied with identical before/after text.
(
changes: &[FileChange],
registry: &mut ParserRegistry,
config: &ExtractionConfig,
)
| 462 | /// same-language files, with exact tokens and an explicit minimum window size. |
| 463 | /// Unchanged comparison files may be supplied with identical before/after text. |
| 464 | pub fn extract_changes( |
| 465 | changes: &[FileChange], |
| 466 | registry: &mut ParserRegistry, |
| 467 | config: &ExtractionConfig, |
| 468 | ) -> Result<Extraction, &'static str> { |
| 469 | if config.minimum_clone_tokens < 4 || config.minimum_clone_tokens > config.max_tokens_per_file { |
| 470 | return Err("clone token minimum must be between 4 and the per-file token budget"); |
| 471 | } |
| 472 | let mut ordered: Vec<_> = changes.iter().collect(); |
| 473 | ordered.sort_by(|a, b| a.path.cmp(&b.path)); |
| 474 | if ordered.windows(2).any(|pair| pair[0].path == pair[1].path) |
| 475 | || ordered.iter().any(|change| change.path.is_empty()) |
| 476 | { |
| 477 | return Err("metric extraction requires unique nonempty source paths"); |
| 478 | } |
| 479 | let paths: Vec<_> = ordered.iter().map(|change| change.path.clone()).collect(); |
| 480 | let mut bytes_left = config.max_total_bytes; |
| 481 | let mut tokens_left = config.max_total_tokens; |
| 482 | let mut subjects_left = config.max_total_subjects; |
| 483 | let mut before = Vec::new(); |
| 484 | let mut after = Vec::new(); |
| 485 | for (index, change) in ordered.iter().enumerate() { |
| 486 | if index >= config.max_files { |
| 487 | before.push(Parsed::unavailable( |
| 488 | Language::detect(&change.path), |
| 489 | "File count budget exceeded", |
| 490 | )); |
| 491 | after.push(Parsed::unavailable( |
| 492 | Language::detect(&change.path), |
| 493 | "File count budget exceeded", |
| 494 | )); |
| 495 | } else { |
| 496 | before.push(parse( |
| 497 | &change.before, |
| 498 | &change.path, |
| 499 | registry, |
| 500 | config, |
| 501 | &mut bytes_left, |
| 502 | &mut tokens_left, |
| 503 | &mut subjects_left, |
| 504 | )); |
| 505 | after.push(parse( |
| 506 | &change.after, |
| 507 | &change.path, |
| 508 | registry, |
| 509 | config, |
| 510 | &mut bytes_left, |
| 511 | &mut tokens_left, |
| 512 | &mut subjects_left, |
| 513 | )); |
| 514 | } |
| 515 | } |
| 516 | let mut diff_left = config.max_diff_work; |
| 517 | let mut old_masks = Vec::new(); |
| 518 | let mut new_masks = Vec::new(); |
| 519 | for (old, new) in before.iter().zip(&after) { |
| 520 | let masks = if old.token_error.is_some() || new.token_error.is_some() { |
| 521 | Err("Changed-token comparison lacks a complete token stream".into()) |