pub struct Count {
pub id: ObjectId,
pub entry_pack_location: PackLocation,
}Expand description
An item representing a future Entry in the leanest way possible.
One can expect to have one of these in memory when building big objects, so smaller is better here. They should contain everything of importance to generate a pack as fast as possible.
Fields§
§id: ObjectIdThe hash of the object to write
entry_pack_location: PackLocationA way to locate a pack entry in the object database, only available if the object is in a pack.
Implementations§
source§impl Count
impl Count
sourcepub fn from_data(oid: impl Into<ObjectId>, location: Option<Location>) -> Self
pub fn from_data(oid: impl Into<ObjectId>, location: Option<Location>) -> Self
Create a new instance from the given oid and its corresponding git object data.
Examples found in repository?
src/data/output/count/objects/mod.rs (line 246)
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383
pub fn this<Find, IterErr, Oid>(
db: &Find,
input_object_expansion: ObjectExpansion,
seen_objs: &impl util::InsertImmutable<ObjectId>,
oids: impl IntoIterator<Item = std::result::Result<Oid, IterErr>>,
buf1: &mut Vec<u8>,
#[allow(clippy::ptr_arg)] buf2: &mut Vec<u8>,
progress: &mut impl Progress,
should_interrupt: &AtomicBool,
allow_pack_lookups: bool,
) -> super::Result<find::existing::Error<Find::Error>, IterErr>
where
Find: crate::Find,
Oid: Into<ObjectId>,
IterErr: std::error::Error,
{
use ObjectExpansion::*;
let mut out = Vec::new();
let mut tree_traversal_state = git_traverse::tree::breadthfirst::State::default();
let mut tree_diff_state = git_diff::tree::State::default();
let mut parent_commit_ids = Vec::new();
let mut traverse_delegate = tree::traverse::AllUnseen::new(seen_objs);
let mut changes_delegate = tree::changes::AllNew::new(seen_objs);
let mut outcome = Outcome::default();
let stats = &mut outcome;
for id in oids.into_iter() {
if should_interrupt.load(Ordering::Relaxed) {
return Err(Error::Interrupted);
}
let id = id.map(|oid| oid.into()).map_err(Error::InputIteration)?;
let (obj, location) = db.find(id, buf1)?;
stats.input_objects += 1;
match input_object_expansion {
TreeAdditionsComparedToAncestor => {
use git_object::Kind::*;
let mut obj = obj;
let mut location = location;
let mut id = id.to_owned();
loop {
push_obj_count_unique(&mut out, seen_objs, &id, location, progress, stats, false);
match obj.kind {
Tree | Blob => break,
Tag => {
id = TagRefIter::from_bytes(obj.data)
.target_id()
.expect("every tag has a target");
let tmp = db.find(id, buf1)?;
obj = tmp.0;
location = tmp.1;
stats.expanded_objects += 1;
continue;
}
Commit => {
let current_tree_iter = {
let mut commit_iter = CommitRefIter::from_bytes(obj.data);
let tree_id = commit_iter.tree_id().expect("every commit has a tree");
parent_commit_ids.clear();
for token in commit_iter {
match token {
Ok(git_object::commit::ref_iter::Token::Parent { id }) => {
parent_commit_ids.push(id)
}
Ok(_) => break,
Err(err) => return Err(Error::CommitDecode(err)),
}
}
let (obj, location) = db.find(tree_id, buf1)?;
push_obj_count_unique(
&mut out, seen_objs, &tree_id, location, progress, stats, true,
);
git_object::TreeRefIter::from_bytes(obj.data)
};
let objects = if parent_commit_ids.is_empty() {
traverse_delegate.clear();
git_traverse::tree::breadthfirst(
current_tree_iter,
&mut tree_traversal_state,
|oid, buf| {
stats.decoded_objects += 1;
match db.find(oid, buf).ok() {
Some((obj, location)) => {
progress.inc();
stats.expanded_objects += 1;
out.push(output::Count::from_data(oid, location));
obj.try_into_tree_iter()
}
None => None,
}
},
&mut traverse_delegate,
)
.map_err(Error::TreeTraverse)?;
&traverse_delegate.non_trees
} else {
for commit_id in &parent_commit_ids {
let parent_tree_id = {
let (parent_commit_obj, location) = db.find(commit_id, buf2)?;
push_obj_count_unique(
&mut out, seen_objs, commit_id, location, progress, stats, true,
);
CommitRefIter::from_bytes(parent_commit_obj.data)
.tree_id()
.expect("every commit has a tree")
};
let parent_tree = {
let (parent_tree_obj, location) = db.find(parent_tree_id, buf2)?;
push_obj_count_unique(
&mut out,
seen_objs,
&parent_tree_id,
location,
progress,
stats,
true,
);
git_object::TreeRefIter::from_bytes(parent_tree_obj.data)
};
changes_delegate.clear();
git_diff::tree::Changes::from(Some(parent_tree))
.needed_to_obtain(
current_tree_iter.clone(),
&mut tree_diff_state,
|oid, buf| {
stats.decoded_objects += 1;
db.find_tree_iter(oid, buf).map(|t| t.0)
},
&mut changes_delegate,
)
.map_err(Error::TreeChanges)?;
}
&changes_delegate.objects
};
for id in objects.iter() {
out.push(id_to_count(db, buf2, id, progress, stats, allow_pack_lookups));
}
break;
}
}
}
}
TreeContents => {
use git_object::Kind::*;
let mut id = id;
let mut obj = (obj, location);
loop {
push_obj_count_unique(&mut out, seen_objs, &id, obj.1.clone(), progress, stats, false);
match obj.0.kind {
Tree => {
traverse_delegate.clear();
git_traverse::tree::breadthfirst(
git_object::TreeRefIter::from_bytes(obj.0.data),
&mut tree_traversal_state,
|oid, buf| {
stats.decoded_objects += 1;
match db.find(oid, buf).ok() {
Some((obj, location)) => {
progress.inc();
stats.expanded_objects += 1;
out.push(output::Count::from_data(oid, location));
obj.try_into_tree_iter()
}
None => None,
}
},
&mut traverse_delegate,
)
.map_err(Error::TreeTraverse)?;
for id in traverse_delegate.non_trees.iter() {
out.push(id_to_count(db, buf1, id, progress, stats, allow_pack_lookups));
}
break;
}
Commit => {
id = CommitRefIter::from_bytes(obj.0.data)
.tree_id()
.expect("every commit has a tree");
stats.expanded_objects += 1;
obj = db.find(id, buf1)?;
continue;
}
Blob => break,
Tag => {
id = TagRefIter::from_bytes(obj.0.data)
.target_id()
.expect("every tag has a target");
stats.expanded_objects += 1;
obj = db.find(id, buf1)?;
continue;
}
}
}
}
AsIs => push_obj_count_unique(&mut out, seen_objs, &id, location, progress, stats, false),
}
}
outcome.total_objects = out.len();
Ok((out, outcome))
}
#[inline]
fn push_obj_count_unique(
out: &mut Vec<output::Count>,
all_seen: &impl util::InsertImmutable<ObjectId>,
id: &oid,
location: Option<crate::data::entry::Location>,
progress: &mut impl Progress,
statistics: &mut Outcome,
count_expanded: bool,
) {
let inserted = all_seen.insert(id.to_owned());
if inserted {
progress.inc();
statistics.decoded_objects += 1;
if count_expanded {
statistics.expanded_objects += 1;
}
out.push(output::Count::from_data(id, location));
}
}Trait Implementations§
source§impl<'de> Deserialize<'de> for Count
impl<'de> Deserialize<'de> for Count
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
source§impl Ord for Count
impl Ord for Count
source§impl PartialEq<Count> for Count
impl PartialEq<Count> for Count
source§impl PartialOrd<Count> for Count
impl PartialOrd<Count> for Count
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self and other) and is used by the <=
operator. Read moreimpl Eq for Count
impl StructuralEq for Count
impl StructuralPartialEq for Count
Auto Trait Implementations§
impl RefUnwindSafe for Count
impl Send for Count
impl Sync for Count
impl Unpin for Count
impl UnwindSafe for Count
Blanket Implementations§
§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Checks if this value is equivalent to the given key. Read more