Enum git_index::write::Extensions
source · Expand description
A way to specify which of the optional extensions to write.
Variants§
All
Writes all available optional extensions to avoid loosing any information.
Given
Fields
Only write the given optional extensions, with each extension being marked by a boolean flag.
Note: mandatory extensions
Mandatory extensions, like sdir
or other lower-case ones, may not be configured here as they need to be present
or absent depending on the state of the index itself and for it to be valid.
None
Write no optional extension at all for what should be the smallest possible index
Implementations§
source§impl Extensions
impl Extensions
sourcepub fn should_write(&self, signature: Signature) -> Option<Signature>
pub fn should_write(&self, signature: Signature) -> Option<Signature>
Returns Some(signature)
if it should be written out.
Examples found in repository?
src/write.rs (line 78)
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
pub fn write_to(&self, out: impl std::io::Write, Options { extensions }: Options) -> std::io::Result<Version> {
let version = self.detect_required_version();
let mut write = CountBytes::new(out);
let num_entries = self
.entries()
.len()
.try_into()
.expect("definitely not 4billion entries");
let offset_to_entries = header(&mut write, version, num_entries)?;
let offset_to_extensions = entries(&mut write, self, offset_to_entries)?;
let (extension_toc, out) = self.write_extensions(write, offset_to_extensions, extensions)?;
if num_entries > 0
&& extensions
.should_write(extension::end_of_index_entry::SIGNATURE)
.is_some()
&& !extension_toc.is_empty()
{
extension::end_of_index_entry::write_to(out, self.object_hash, offset_to_extensions, extension_toc)?
}
Ok(version)
}
fn write_extensions<T>(
&self,
mut write: CountBytes<T>,
offset_to_extensions: u32,
extensions: Extensions,
) -> std::io::Result<(Vec<(extension::Signature, u32)>, T)>
where
T: std::io::Write,
{
type WriteExtFn<'a> = &'a dyn Fn(&mut dyn std::io::Write) -> Option<std::io::Result<extension::Signature>>;
let extensions: &[WriteExtFn<'_>] = &[
&|write| {
extensions
.should_write(extension::tree::SIGNATURE)
.and_then(|signature| self.tree().map(|tree| tree.write_to(write).map(|_| signature)))
},
&|write| {
self.is_sparse()
.then(|| extension::sparse::write_to(write).map(|_| extension::sparse::SIGNATURE))
},
];
let mut offset_to_previous_ext = offset_to_extensions;
let mut out = Vec::with_capacity(5);
for write_ext in extensions {
if let Some(signature) = write_ext(&mut write).transpose()? {
let offset_past_ext = write.count;
let ext_size = offset_past_ext - offset_to_previous_ext - (extension::MIN_SIZE as u32);
offset_to_previous_ext = offset_past_ext;
out.push((signature, ext_size));
}
}
Ok((out, write.inner))
}
Trait Implementations§
source§impl Clone for Extensions
impl Clone for Extensions
source§fn clone(&self) -> Extensions
fn clone(&self) -> Extensions
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read more