MCPcopy Create free account
hub / github.com/AmrDeveloper/GQL / select_diffs

Function select_diffs

src/gitql/gitql_data_provider.rs:299–423  ·  view source on GitHub ↗
(repo: &gix::Repository, selected_columns: &[String])

Source from the content-addressed store, hash-verified

297}
298
299fn select_diffs(repo: &gix::Repository, selected_columns: &[String]) -> Result<Vec<Row>, String> {
300 let repo = {
301 let mut repo = repo.clone();
302 repo.object_cache_size_if_unset(4 * 1024 * 1024);
303 repo
304 };
305
306 let mut rewrite_cache = repo
307 .diff_resource_cache(Mode::ToGit, Default::default())
308 .unwrap();
309
310 let mut diff_cache = rewrite_cache.clone();
311
312 let should_calculate_diffs = selected_columns.iter().any(|col| {
313 col == "insertions" || col == "removals" || col == "files_changed" || col == "diff_changes"
314 });
315
316 let repo_path = repo.path().to_str().unwrap();
317 let walker = repo.head_id().unwrap().ancestors().all().unwrap();
318 let commits_info = walker.filter_map(Result::ok);
319
320 let mut rows: Vec<Row> = vec![];
321
322 for commit_info in commits_info.into_iter() {
323 let commit = commit_info.id().object().unwrap().into_commit();
324 let commit_ref = commit.decode().unwrap();
325 let mut values: Vec<Box<dyn Value>> = Vec::with_capacity(selected_columns.len());
326
327 // Calculate the diff between two commits take time, and should calculated once per commit
328 let (mut insertions, mut removals, mut files_changed) = (0, 0, 0);
329 let mut diff_changes: Vec<DiffChange> = vec![];
330
331 if should_calculate_diffs
332 && let Some(parent) = commit_info
333 .parent_ids()
334 .next()
335 .map(|id| id.object().unwrap().into_commit().tree().unwrap())
336 {
337 let current = commit.tree().unwrap();
338 rewrite_cache.clear_resource_cache_keep_allocation();
339 diff_cache.clear_resource_cache_keep_allocation();
340
341 if let Ok(mut changes) = current.changes() {
342 let _ = changes.for_each_to_obtain_tree_with_cache(
343 &parent,
344 &mut rewrite_cache,
345 |change| {
346 files_changed += usize::from(change.entry_mode().is_no_tree());
347 let diff_change =
348 DiffChange::new_with_content(&change, &mut diff_cache, &repo);
349 insertions += diff_change.insertions;
350 removals += diff_change.removals;
351 diff_changes.push(diff_change);
352 Ok::<_, Infallible>(std::ops::ControlFlow::Continue(()))
353 },
354 );
355 }
356 }

Callers 1

select_gql_objectsFunction · 0.85

Calls 1

lenMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…