pub trait FindExt: Find {
fn find<'a>(
&self,
id: impl AsRef<oid>,
buffer: &'a mut Vec<u8>
) -> Result<(Data<'a>, Option<Location>), Error<Self::Error>> { ... }
fn find_commit<'a>(
&self,
id: impl AsRef<oid>,
buffer: &'a mut Vec<u8>
) -> Result<(CommitRef<'a>, Option<Location>), Error<Self::Error>> { ... }
fn find_tree<'a>(
&self,
id: impl AsRef<oid>,
buffer: &'a mut Vec<u8>
) -> Result<(TreeRef<'a>, Option<Location>), Error<Self::Error>> { ... }
fn find_tag<'a>(
&self,
id: impl AsRef<oid>,
buffer: &'a mut Vec<u8>
) -> Result<(TagRef<'a>, Option<Location>), Error<Self::Error>> { ... }
fn find_blob<'a>(
&self,
id: impl AsRef<oid>,
buffer: &'a mut Vec<u8>
) -> Result<(BlobRef<'a>, Option<Location>), Error<Self::Error>> { ... }
fn find_commit_iter<'a>(
&self,
id: impl AsRef<oid>,
buffer: &'a mut Vec<u8>
) -> Result<(CommitRefIter<'a>, Option<Location>), Error<Self::Error>> { ... }
fn find_tree_iter<'a>(
&self,
id: impl AsRef<oid>,
buffer: &'a mut Vec<u8>
) -> Result<(TreeRefIter<'a>, Option<Location>), Error<Self::Error>> { ... }
fn find_tag_iter<'a>(
&self,
id: impl AsRef<oid>,
buffer: &'a mut Vec<u8>
) -> Result<(TagRefIter<'a>, Option<Location>), Error<Self::Error>> { ... }
}
Expand description
An extension trait with convenience functions.
Provided Methods§
sourcefn find<'a>(
&self,
id: impl AsRef<oid>,
buffer: &'a mut Vec<u8>
) -> Result<(Data<'a>, Option<Location>), Error<Self::Error>>
fn find<'a>(
&self,
id: impl AsRef<oid>,
buffer: &'a mut Vec<u8>
) -> Result<(Data<'a>, Option<Location>), Error<Self::Error>>
Like try_find(…)
, but flattens the Result<Option<_>>
into a single Result
making a non-existing object an error.
Examples found in repository?
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
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))
}
sourcefn find_commit<'a>(
&self,
id: impl AsRef<oid>,
buffer: &'a mut Vec<u8>
) -> Result<(CommitRef<'a>, Option<Location>), Error<Self::Error>>
fn find_commit<'a>(
&self,
id: impl AsRef<oid>,
buffer: &'a mut Vec<u8>
) -> Result<(CommitRef<'a>, Option<Location>), Error<Self::Error>>
Like find(…)
, but flattens the Result<Option<_>>
into a single Result
making a non-existing object an error
while returning the desired object type.
sourcefn find_tree<'a>(
&self,
id: impl AsRef<oid>,
buffer: &'a mut Vec<u8>
) -> Result<(TreeRef<'a>, Option<Location>), Error<Self::Error>>
fn find_tree<'a>(
&self,
id: impl AsRef<oid>,
buffer: &'a mut Vec<u8>
) -> Result<(TreeRef<'a>, Option<Location>), Error<Self::Error>>
Like find(…)
, but flattens the Result<Option<_>>
into a single Result
making a non-existing object an error
while returning the desired object type.
sourcefn find_tag<'a>(
&self,
id: impl AsRef<oid>,
buffer: &'a mut Vec<u8>
) -> Result<(TagRef<'a>, Option<Location>), Error<Self::Error>>
fn find_tag<'a>(
&self,
id: impl AsRef<oid>,
buffer: &'a mut Vec<u8>
) -> Result<(TagRef<'a>, Option<Location>), Error<Self::Error>>
Like find(…)
, but flattens the Result<Option<_>>
into a single Result
making a non-existing object an error
while returning the desired object type.
sourcefn find_blob<'a>(
&self,
id: impl AsRef<oid>,
buffer: &'a mut Vec<u8>
) -> Result<(BlobRef<'a>, Option<Location>), Error<Self::Error>>
fn find_blob<'a>(
&self,
id: impl AsRef<oid>,
buffer: &'a mut Vec<u8>
) -> Result<(BlobRef<'a>, Option<Location>), Error<Self::Error>>
Like find(…)
, but flattens the Result<Option<_>>
into a single Result
making a non-existing object an error
while returning the desired object type.
sourcefn find_commit_iter<'a>(
&self,
id: impl AsRef<oid>,
buffer: &'a mut Vec<u8>
) -> Result<(CommitRefIter<'a>, Option<Location>), Error<Self::Error>>
fn find_commit_iter<'a>(
&self,
id: impl AsRef<oid>,
buffer: &'a mut Vec<u8>
) -> Result<(CommitRefIter<'a>, Option<Location>), Error<Self::Error>>
Like find(…)
, but flattens the Result<Option<_>>
into a single Result
making a non-existing object an error
while returning the desired iterator type.
sourcefn find_tree_iter<'a>(
&self,
id: impl AsRef<oid>,
buffer: &'a mut Vec<u8>
) -> Result<(TreeRefIter<'a>, Option<Location>), Error<Self::Error>>
fn find_tree_iter<'a>(
&self,
id: impl AsRef<oid>,
buffer: &'a mut Vec<u8>
) -> Result<(TreeRefIter<'a>, Option<Location>), Error<Self::Error>>
Like find(…)
, but flattens the Result<Option<_>>
into a single Result
making a non-existing object an error
while returning the desired iterator type.
Examples found in repository?
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
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))
}