дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-04 01:01:17 +02:00
fix(vcs): keep No Merges fast when pull requests branch off older commits (#7862)
With No Merges on, a hidden merge's graph parents are its parents' projections onto shown commits, merged. When pull requests branch off an older main commit, neither parent of a merge reaches the other, so each merge kept every feature merged before it and a 500K-commit repository never finished loading. The merged projection now drops the commits reachable through another of them (the same bounded walk that keeps a commit when unsure), in the graph builder and the filtered log view. Fixes #7807
Цей коміт міститься в:
1 джерело
ea4ac8cc6e
коміт
a6aa26ea2a
2 files changed
+54
-20
No files matched your search
@@ -1020,6 +1020,15 @@ fn sort_subset(
|
||||
let mut times = Vec::with_capacity(ids.len());
|
||||
let mut projected: HashMap<ObjectId, Vec<usize>> = HashMap::new();
|
||||
let mut pruned: HashMap<ObjectId, Vec<ObjectId>> = HashMap::new();
|
||||
let lookup = |id: ObjectId| -> IdeResult<Option<(Vec<ObjectId>, i64)>> {
|
||||
if let Some((ps, time)) = nodes.get(&id) {
|
||||
return Ok(Some((if shallow.contains(&id) { Vec::new() } else { ps.clone() }, *time)));
|
||||
}
|
||||
let Ok(commit) = repo.find_commit(id) else { return Ok(None) };
|
||||
let parents =
|
||||
if shallow.contains(&id) { Vec::new() } else { commit.parent_ids().map(|p| p.detach()).collect() };
|
||||
Ok(Some((parents, commit.time().map(|t| t.seconds).unwrap_or(0))))
|
||||
};
|
||||
for id in &ids {
|
||||
if cancel.is_cancelled() {
|
||||
return Err(IdeError::cancelled());
|
||||
@@ -1081,33 +1090,28 @@ fn sort_subset(
|
||||
.collect()
|
||||
};
|
||||
if !expanded {
|
||||
let ancestors = without_redundant_parents(ancestors, cancel, |id| {
|
||||
if let Some((ps, time)) = nodes.get(&id) {
|
||||
return Ok(Some((
|
||||
if shallow.contains(&id) { Vec::new() } else { ps.clone() },
|
||||
*time,
|
||||
)));
|
||||
}
|
||||
let Ok(commit) = repo.find_commit(id) else { return Ok(None) };
|
||||
let parents = if shallow.contains(&id) {
|
||||
Vec::new()
|
||||
} else {
|
||||
commit.parent_ids().map(|p| p.detach()).collect()
|
||||
};
|
||||
Ok(Some((parents, commit.time().map(|t| t.seconds).unwrap_or(0))))
|
||||
})?;
|
||||
let ancestors = without_redundant_parents(ancestors, cancel, &lookup)?;
|
||||
stack.push((curr, true));
|
||||
stack.extend(ancestors.iter().rev().map(|&p| (p, false)));
|
||||
pruned.insert(curr, ancestors);
|
||||
} else {
|
||||
let sources = pruned.remove(&curr).unwrap_or(ancestors);
|
||||
let mut combined = Vec::new();
|
||||
for a in pruned.remove(&curr).unwrap_or(ancestors) {
|
||||
for &p in projected.get(&a).into_iter().flatten() {
|
||||
for a in &sources {
|
||||
for &p in projected.get(a).into_iter().flatten() {
|
||||
if !combined.contains(&p) {
|
||||
combined.push(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Projections of several parents overlap: keep the commits not reachable through another.
|
||||
if sources.len() > 1 && combined.len() > 1 {
|
||||
let commits = combined.iter().map(|&p| ids[p]).collect();
|
||||
combined = without_redundant_parents(commits, cancel, &lookup)?
|
||||
.iter()
|
||||
.map(|id| positions[id])
|
||||
.collect();
|
||||
}
|
||||
projected.insert(curr, combined);
|
||||
}
|
||||
}
|
||||
@@ -1418,14 +1422,19 @@ impl Visibility<'_> {
|
||||
stack.extend(ancestors.iter().rev().map(|p| (*p, false)));
|
||||
self.pruned.insert(id, ancestors);
|
||||
} else {
|
||||
let sources = self.pruned.remove(&id).unwrap_or(ancestors);
|
||||
let mut nearest = Vec::new();
|
||||
for p in self.pruned.remove(&id).unwrap_or(ancestors) {
|
||||
for ancestor in self.projected.get(&p).into_iter().flatten() {
|
||||
for p in &sources {
|
||||
for ancestor in self.projected.get(p).into_iter().flatten() {
|
||||
if !nearest.contains(ancestor) {
|
||||
nearest.push(*ancestor);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Projections of several parents overlap: keep the commits not reachable through another.
|
||||
if sources.len() > 1 && nearest.len() > 1 {
|
||||
nearest = self.prune(repo, nearest)?;
|
||||
}
|
||||
self.projected.insert(id, nearest);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -272,22 +272,30 @@ fn a_user_filter_links_shown_commits_past_hidden_ones() {
|
||||
/// back as `M_k = merge(M_k-1, F_k)`, written with `git fast-import`. Returns the feature commits
|
||||
/// newest first.
|
||||
fn pull_request_history(dir: &Path, merges: usize) -> Vec<String> {
|
||||
pull_request_history_from(dir, merges, 1)
|
||||
}
|
||||
|
||||
/// `merges` merged pull requests, each feature branched off `behind` merges before the one that merges it.
|
||||
fn pull_request_history_from(dir: &Path, merges: usize, behind: usize) -> Vec<String> {
|
||||
git(dir, &["init", "-q"], None);
|
||||
let mut stream =
|
||||
String::from("commit refs/heads/main\nmark :1\ncommitter T <[email protected]> 1000 +0000\ndata 4\nroot\n");
|
||||
let mut prev = 1;
|
||||
let mut mark = 1;
|
||||
let mut mains = vec![1];
|
||||
for k in 0..merges {
|
||||
let t = 1001 + 2 * k as i64;
|
||||
let feature = mark + 1;
|
||||
let merge = mark + 2;
|
||||
let base = mains[mains.len().saturating_sub(behind)];
|
||||
stream += &format!(
|
||||
"commit refs/heads/main\nmark :{feature}\ncommitter T <[email protected]> {t} +0000\ndata 1\nf\nfrom :{prev}\n\
|
||||
"commit refs/heads/main\nmark :{feature}\ncommitter T <[email protected]> {t} +0000\ndata 1\nf\nfrom :{base}\n\
|
||||
commit refs/heads/main\nmark :{merge}\ncommitter T <[email protected]> {} +0000\ndata 1\nm\nfrom :{prev}\nmerge :{feature}\n",
|
||||
t + 1
|
||||
);
|
||||
prev = merge;
|
||||
mark = merge;
|
||||
mains.push(merge);
|
||||
}
|
||||
let mut child = Command::new("git")
|
||||
.current_dir(dir)
|
||||
@@ -305,6 +313,23 @@ fn pull_request_history(dir: &Path, merges: usize) -> Vec<String> {
|
||||
(0..merges).rev().map(|k| marks[&(2 + 2 * k)].clone()).collect()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn no_merges_on_concurrent_pull_requests_loads_its_first_page_quickly() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let features = pull_request_history_from(tmp.path(), 3000, 5);
|
||||
let repo = Repo::discover(tmp.path()).unwrap().unwrap();
|
||||
let started = std::time::Instant::now();
|
||||
let out = repo
|
||||
.log(&LogQuery { branches: vec!["main".into()], no_merges: true, limit: 100, ..Default::default() })
|
||||
.unwrap();
|
||||
let elapsed = started.elapsed();
|
||||
assert_eq!(ids(&out)[..3], features[..3]);
|
||||
// A feature branched off five merges back reaches the features merged before it only
|
||||
// through the five merged since: those are its graph parents, the main line's first.
|
||||
assert_eq!(parents_of(&out, &features[0]), features[5..10].iter().rev().cloned().collect::<Vec<_>>());
|
||||
assert!(elapsed < std::time::Duration::from_secs(5), "took {elapsed:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn no_merges_on_a_long_pull_request_history_links_each_feature_to_the_previous_one() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
|
||||
Reference in new issue
Заблокувати користувача