| @@ -144,7 +144,7 @@ where · 143 unmodified lines |
| 144 | } | 144 | } |
| 145 | | 145 | |
| 146 | pub(crate) mod function { | 146 | pub(crate) mod function { |
| 147 | use std::{borrow::Cow, cmp::Ordering, collections::VecDeque, iter::FromIterator}; | 147 | use std::{borrow::Cow, cmp::Ordering}; |
| 148 | | 148 | |
| 149 | use bstr::BStr; | 149 | use bstr::BStr; |
| 150 | use gix_hash::oid; | 150 | use gix_hash::oid; |
| @@ -152,7 +152,8 @@ pub(crate) mod function { · 1 unmodified line |
| 152 | use gix_object::CommitRefIter; | 152 | use gix_object::CommitRefIter; |
| 153 | | 153 | |
| 154 | use super::{Error, Outcome}; | 154 | use super::{Error, Outcome}; |
| 155 | use crate::describe::{Flags, Options, MAX_CANDIDATES}; | 155 | use crate::describe::{CommitTime, Flags, Options, MAX_CANDIDATES}; |
| | 156 | use crate::PriorityQueue; |
| 156 | | 157 | |
| 157 | /// Given a `commit` id, traverse the commit graph and collect candidate names from the `name_by_oid` mapping to produce | 158 | /// Given a `commit` id, traverse the commit graph and collect candidate names from the `name_by_oid` mapping to produce |
| 158 | /// an `Outcome`, which converted [`into_format()`][Outcome::into_format()] will produce a typical `git describe` string. | 159 | /// an `Outcome`, which converted [`into_format()`][Outcome::into_format()] will produce a typical `git describe` string. |
| @@ -201,14 +202,14 @@ pub(crate) mod function { · 42 unmodified lines |
| 201 | let mut buf = Vec::new(); | 202 | let mut buf = Vec::new(); |
| 202 | let mut parent_buf = Vec::new(); | 203 | let mut parent_buf = Vec::new(); |
| 203 | | 204 | |
| 204 | let mut queue = VecDeque::from_iter(Some((commit.to_owned(), u32::MAX))); | 205 | let mut queue = PriorityQueue::from_iter(Some((u32::MAX, commit.to_owned()))); |
| 205 | let mut candidates = Vec::new(); | 206 | let mut candidates = Vec::new(); |
| 206 | let mut commits_seen = 0; | 207 | let mut commits_seen = 0; |
| 207 | let mut gave_up_on_commit = None; | 208 | let mut gave_up_on_commit = None; |
| 208 | let mut seen = HashMap::<gix_hash::ObjectId, Flags>::default(); | 209 | let mut seen = HashMap::<gix_hash::ObjectId, Flags>::default(); |
| 209 | seen.insert(commit.to_owned(), 0u32); | 210 | seen.insert(commit.to_owned(), 0u32); |
| 210 | | 211 | |
| 211 | while let Some((commit, _commit_time)) = queue.pop_front() { | 212 | while let Some(commit) = queue.pop() { |
| 212 | commits_seen += 1; | 213 | commits_seen += 1; |
| 213 | if let Some(name) = name_by_oid.get(&commit) { | 214 | if let Some(name) = name_by_oid.get(&commit) { |
| 214 | if candidates.len() < max_candidates { | 215 | if candidates.len() < max_candidates { |
| @@ -290,7 +291,7 @@ pub(crate) mod function { · 75 unmodified lines |
| 290 | }); | 291 | }); |
| 291 | | 292 | |
| 292 | if let Some(commit_id) = gave_up_on_commit { | 293 | if let Some(commit_id) = gave_up_on_commit { |
| 293 | queue.push_front((commit_id, u32::MAX)); | 294 | queue.insert(u32::MAX, commit_id); |
| 294 | commits_seen -= 1; | 295 | commits_seen -= 1; |
| 295 | } | 296 | } |
| 296 | | 297 | |
| @@ -318,7 +319,7 @@ pub(crate) mod function { · 21 unmodified lines |
| 318 | find: &mut Find, | 319 | find: &mut Find, |
| 319 | buf: &mut Vec<u8>, | 320 | buf: &mut Vec<u8>, |
| 320 | parent_buf: &mut Vec<u8>, | 321 | parent_buf: &mut Vec<u8>, |
| 321 | queue: &mut VecDeque<(gix_hash::ObjectId, u32)>, | 322 | queue: &mut PriorityQueue<CommitTime, gix_hash::ObjectId>, |
| 322 | seen: &mut HashMap<gix_hash::ObjectId, Flags>, | 323 | seen: &mut HashMap<gix_hash::ObjectId, Flags>, |
| 323 | commit: &gix_hash::oid, | 324 | commit: &gix_hash::oid, |
| 324 | commit_flags: Flags, | 325 | commit_flags: Flags, |
| @@ -356,10 +357,7 @@ pub(crate) mod function { · 31 unmodified lines |
| 356 | .unwrap_or_default(); | 357 | .unwrap_or_default(); |
| 357 | | 358 | |
| 358 | entry.insert(commit_flags); | 359 | entry.insert(commit_flags); |
| 359 | match queue.binary_search_by(|c| c.1.cmp(&parent_commit_date).reverse()) { | 360 | queue.insert(parent_commit_date, parent_id); |
| 360 | Ok(_) => queue.push_back((parent_id, parent_commit_date)), | | |
| 361 | Err(pos) => queue.insert(pos, (parent_id, parent_commit_date)), | | |
| 362 | }; | | |
| 363 | } | 361 | } |
| 364 | hash_map::Entry::Occupied(mut entry) => { | 362 | hash_map::Entry::Occupied(mut entry) => { |
| 365 | *entry.get_mut() |= commit_flags; | 363 | *entry.get_mut() |= commit_flags; |
| @@ -378,7 +376,7 @@ pub(crate) mod function { · 12 unmodified lines |
| 378 | | 376 | |
| 379 | #[allow(clippy::too_many_arguments)] | 377 | #[allow(clippy::too_many_arguments)] |
| 380 | fn finish_depth_computation<'name, Find, E>( | 378 | fn finish_depth_computation<'name, Find, E>( |
| 381 | mut queue: VecDeque<(gix_hash::ObjectId, u32)>, | 379 | mut queue: PriorityQueue<CommitTime, gix_hash::ObjectId>, |
| 382 | mut find: Find, | 380 | mut find: Find, |
| 383 | best_candidate: &mut Candidate<'name>, | 381 | best_candidate: &mut Candidate<'name>, |
| 384 | mut seen: HashMap<gix_hash::ObjectId, Flags>, | 382 | mut seen: HashMap<gix_hash::ObjectId, Flags>, |
| @@ -391,13 +389,13 @@ pub(crate) mod function { · 6 unmodified lines |
| 391 | E: std::error::Error + Send + Sync + 'static, | 389 | E: std::error::Error + Send + Sync + 'static, |
| 392 | { | 390 | { |
| 393 | let mut commits_seen = 0; | 391 | let mut commits_seen = 0; |
| 394 | while let Some((commit, _commit_time)) = queue.pop_front() { | 392 | while let Some(commit) = queue.pop() { |
| 395 | commits_seen += 1; | 393 | commits_seen += 1; |
| 396 | let flags = seen[&commit]; | 394 | let flags = seen[&commit]; |
| 397 | if (flags & best_candidate.identity_bit) == best_candidate.identity_bit { | 395 | if (flags & best_candidate.identity_bit) == best_candidate.identity_bit { |
| 398 | if queue | 396 | if queue |
| 399 | .iter() | 397 | .iter_random() |
| 400 | .all(|(id, _)| (seen[id] & best_candidate.identity_bit) == best_candidate.identity_bit) | 398 | .all(|id| (seen[id] & best_candidate.identity_bit) == best_candidate.identity_bit) |
| 401 | { | 399 | { |
| 402 | break; | 400 | break; |
| 403 | } | 401 | } |
| @@ -429,3 +427,5 @@ pub(crate) mod function { · 25 unmodified lines |
| 429 | order: usize, | 427 | order: usize, |
| 430 | } | 428 | } |
| 431 | } | 429 | } |
| | 430 | |
| | 431 | type CommitTime = u32; |