Skip to content

Commit 328900a

Browse files
committed
fix!: support for non-'static PackedRefs transactions. (#450)
When configuring for packed-refs updates, previously one needed to provide a function to find objects that could not borrow data due to implicit 'static requirement. This has been lifted to allow it to access references to data on the stack.
1 parent 728f688 commit 328900a

File tree

5 files changed

+16
-16
lines changed

5 files changed

+16
-16
lines changed

git-ref/src/store/file/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,11 @@ mod access {
6262
}
6363

6464
/// A transaction on a file store
65-
pub struct Transaction<'s> {
65+
pub struct Transaction<'s, 'p> {
6666
store: &'s Store,
6767
packed_transaction: Option<crate::store_impl::packed::Transaction>,
6868
updates: Option<Vec<transaction::Edit>>,
69-
packed_refs: transaction::PackedRefs,
69+
packed_refs: transaction::PackedRefs<'p>,
7070
}
7171

7272
pub(in crate::store_impl::file) fn path_to_name<'a>(path: impl Into<Cow<'a, Path>>) -> Cow<'a, BStr> {

git-ref/src/store/file/transaction/commit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::{
44
Target,
55
};
66

7-
impl<'s> Transaction<'s> {
7+
impl<'s, 'p> Transaction<'s, 'p> {
88
/// Make all [prepared][Transaction::prepare()] permanent and return the performed edits which represent the current
99
/// state of the affected refs in the ref store in that instant. Please note that the obtained edits may have been
1010
/// adjusted to contain more dependent edits or additional information.

git-ref/src/store/file/transaction/mod.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,24 @@ use crate::{
1010
/// used to obtain the peeled object ids for storage in packed-refs files.
1111
///
1212
/// Resolution means to follow tag objects until the end of the chain.
13-
pub type FindObjectFn =
14-
dyn FnMut(
13+
pub type FindObjectFn<'a> = dyn FnMut(
1514
git_hash::ObjectId,
1615
&mut Vec<u8>,
17-
) -> Result<Option<git_object::Kind>, Box<dyn std::error::Error + Send + Sync + 'static>>;
16+
) -> Result<Option<git_object::Kind>, Box<dyn std::error::Error + Send + Sync + 'static>>
17+
+ 'a;
1818

1919
/// How to handle packed refs during a transaction
20-
pub enum PackedRefs {
20+
pub enum PackedRefs<'a> {
2121
/// Only propagate deletions of references. This is the default
2222
DeletionsOnly,
2323
/// Propagate deletions as well as updates to references which are peeled, that is contain an object id
24-
DeletionsAndNonSymbolicUpdates(Box<FindObjectFn>),
24+
DeletionsAndNonSymbolicUpdates(Box<FindObjectFn<'a>>),
2525
/// Propagate deletions as well as updates to references which are peeled, that is contain an object id. Furthermore delete the
2626
/// reference which is originally updated if it exists. If it doesn't, the new value will be written into the packed ref right away.
27-
DeletionsAndNonSymbolicUpdatesRemoveLooseSourceReference(Box<FindObjectFn>),
27+
DeletionsAndNonSymbolicUpdatesRemoveLooseSourceReference(Box<FindObjectFn<'a>>),
2828
}
2929

30-
impl Default for PackedRefs {
30+
impl Default for PackedRefs<'_> {
3131
fn default() -> Self {
3232
PackedRefs::DeletionsOnly
3333
}
@@ -71,7 +71,7 @@ impl file::Store {
7171
/// will never have been altered.
7272
///
7373
/// The transaction inherits the parent namespace.
74-
pub fn transaction(&self) -> Transaction<'_> {
74+
pub fn transaction(&self) -> Transaction<'_, '_> {
7575
Transaction {
7676
store: self,
7777
packed_transaction: None,
@@ -81,9 +81,9 @@ impl file::Store {
8181
}
8282
}
8383

84-
impl<'s> Transaction<'s> {
84+
impl<'s, 'p> Transaction<'s, 'p> {
8585
/// Configure the way packed refs are handled during the transaction
86-
pub fn packed_refs(mut self, packed_refs: PackedRefs) -> Self {
86+
pub fn packed_refs(mut self, packed_refs: PackedRefs<'p>) -> Self {
8787
self.packed_refs = packed_refs;
8888
self
8989
}

git-ref/src/store/file/transaction/prepare.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::{
1212
FullName, FullNameRef, Reference, Target,
1313
};
1414

15-
impl<'s> Transaction<'s> {
15+
impl<'s, 'p> Transaction<'s, 'p> {
1616
fn lock_ref_and_apply_change(
1717
store: &file::Store,
1818
lock_fail_mode: git_lock::acquire::Fail,
@@ -167,7 +167,7 @@ impl<'s> Transaction<'s> {
167167
}
168168
}
169169

170-
impl<'s> Transaction<'s> {
170+
impl<'s, 'p> Transaction<'s, 'p> {
171171
/// Prepare for calling [`commit(…)`][Transaction::commit()] in a way that can be rolled back perfectly.
172172
///
173173
/// If the operation succeeds, the transaction can be committed or dropped to cause a rollback automatically.

git-ref/src/store/packed/transaction.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ impl packed::Transaction {
3838
pub fn prepare(
3939
mut self,
4040
edits: impl IntoIterator<Item = RefEdit>,
41-
find: &mut FindObjectFn,
41+
find: &mut FindObjectFn<'_>,
4242
) -> Result<Self, prepare::Error> {
4343
assert!(self.edits.is_none(), "BUG: cannot call prepare(…) more than once");
4444
let buffer = &self.buffer;

0 commit comments

Comments
 (0)