From 3c105a77aa12fde75ba2d09dd28f61dad0f6b77b Mon Sep 17 00:00:00 2001 From: Benjamin Tan Date: Mon, 25 Mar 2024 18:44:54 +0800 Subject: [PATCH] GitFetchOptions: Add hack to ensure `update_flags` bitfields are initialized properly --- src/remote.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/remote.rs b/src/remote.rs index 427165dd7f..0211493507 100644 --- a/src/remote.rs +++ b/src/remote.rs @@ -613,7 +613,11 @@ impl<'cb> Binding for FetchOptions<'cb> { .map(|m| m.raw()) .unwrap_or_else(|| ProxyOptions::new().raw()), prune: crate::call::convert(&self.prune), - update_flags: self.update_flags.bits() as c_uint, + // HACK: `libgit2` uses C bitfields, which do not have a guaranteed memory layout. + // Reversing the bits ensures that the bitfields are set whether the bits are laid out + // from left to right or right to left, but will not work on other memory layouts. + update_flags: (self.update_flags.bits() | self.update_flags.bits().reverse_bits()) + as c_uint, download_tags: crate::call::convert(&self.download_tags), depth: self.depth, follow_redirects: self.follow_redirects.raw(),