Skip to content

Commit 29d744b

Browse files
author
fossdd
committed
Update pijul
1 parent a10b12f commit 29d744b

File tree

4 files changed

+65
-18
lines changed

4 files changed

+65
-18
lines changed

libpijul/src/apply.rs

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,16 @@ pub fn apply_change_ws<T: MutTxnT, P: ChangeStore>(
173173
internal
174174
};
175175
debug!("internal = {:?}", internal);
176-
Ok(
177-
apply_change_to_channel(txn, channel, internal, &hash, &change, workspace)
178-
.map_err(ApplyError::LocalChange)?,
176+
Ok(apply_change_to_channel(
177+
txn,
178+
channel,
179+
&mut |h| changes.knows(h, hash).unwrap(),
180+
internal,
181+
&hash,
182+
&change,
183+
workspace,
179184
)
185+
.map_err(ApplyError::LocalChange)?)
180186
}
181187

182188
pub fn apply_change_rec_ws<T: TxnT + MutTxnT, P: ChangeStore>(
@@ -230,8 +236,16 @@ pub fn apply_change_rec_ws<T: TxnT + MutTxnT, P: ChangeStore>(
230236
};
231237
debug!("internal = {:?}", internal);
232238
workspace.clear();
233-
apply_change_to_channel(txn, channel, internal, &hash, &change, workspace)
234-
.map_err(ApplyError::LocalChange)?;
239+
apply_change_to_channel(
240+
txn,
241+
channel,
242+
&mut |h| changes.knows(h, &hash).unwrap(),
243+
internal,
244+
&hash,
245+
&change,
246+
workspace,
247+
)
248+
.map_err(ApplyError::LocalChange)?;
235249
}
236250
}
237251
}
@@ -282,9 +296,10 @@ pub fn apply_change_rec<T: MutTxnT, P: ChangeStore>(
282296
)
283297
}
284298

285-
fn apply_change_to_channel<T: ChannelMutTxnT + TreeTxnT>(
299+
fn apply_change_to_channel<T: ChannelMutTxnT + TreeTxnT, F: FnMut(&Hash) -> bool>(
286300
txn: &mut T,
287301
channel: &mut T::Channel,
302+
changes: &mut F,
288303
change_id: ChangeId,
289304
hash: &Hash,
290305
change: &Change,
@@ -305,9 +320,15 @@ fn apply_change_to_channel<T: ChannelMutTxnT + TreeTxnT>(
305320
debug!("Applying {:?} (1)", change_);
306321
for change_ in change_.iter() {
307322
match *change_ {
308-
Atom::NewVertex(ref n) => {
309-
put_newvertex(txn, T::graph_mut(channel), change, ws, change_id, n)?
310-
}
323+
Atom::NewVertex(ref n) => put_newvertex(
324+
txn,
325+
T::graph_mut(channel),
326+
changes,
327+
change,
328+
ws,
329+
change_id,
330+
n,
331+
)?,
311332
Atom::EdgeMap(ref n) => {
312333
for edge in n.edges.iter() {
313334
if !edge.flag.contains(EdgeFlags::DELETED) {
@@ -400,7 +421,15 @@ pub fn apply_local_change_ws<
400421
}
401422

402423
register_change(txn, &internal, hash, &change)?;
403-
let n = apply_change_to_channel(txn, &mut channel, internal, &hash, &change, workspace)?;
424+
let n = apply_change_to_channel(
425+
txn,
426+
&mut channel,
427+
&mut |_| true,
428+
internal,
429+
&hash,
430+
&change,
431+
workspace,
432+
)?;
404433
for (_, update) in inode_updates.iter() {
405434
info!("updating {:?}", update);
406435
update_inode(txn, &channel, internal, update)?;

libpijul/src/apply/edge.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ where
8383
if apply_check(source, target) {
8484
put_graph_with_rev(txn, graph, n.flag, source, target, change)?;
8585
for intro in zombies.drain(..) {
86+
debug!("putting zombie {:?} {:?} {:?}", source, target, intro);
8687
assert!(!n.flag.contains(EdgeFlags::FOLDER));
8788
put_graph_with_rev(txn, graph, EdgeFlags::DELETED, source, target, intro)?;
8889
}
@@ -142,6 +143,7 @@ where
142143
for v in iter_deleted_parents(txn, graph, target)? {
143144
let v = v?;
144145
let intro = v.introduced_by();
146+
debug!("known {:?} ?", intro);
145147
if !known(&txn.get_external(&intro)?.unwrap().into()) {
146148
zombies.push(intro)
147149
}

libpijul/src/apply/vertex.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ use crate::change::{Change, NewVertex};
33
use crate::pristine::*;
44
use crate::{ChangeId, EdgeFlags, Hash, Vertex};
55

6-
pub fn put_newvertex<T: GraphMutTxnT + TreeTxnT>(
6+
pub fn put_newvertex<T: GraphMutTxnT + TreeTxnT, F: FnMut(&Hash) -> bool>(
77
txn: &mut T,
88
graph: &mut T::Graph,
9+
changes: &mut F,
910
ch: &Change,
1011
ws: &mut Workspace,
1112
change: ChangeId,
@@ -29,7 +30,7 @@ pub fn put_newvertex<T: GraphMutTxnT + TreeTxnT>(
2930
assert!(ws.deleted_by.is_empty());
3031
for up in n.up_context.iter() {
3132
let up = internal_pos(txn, up, change)?;
32-
if put_up_context(txn, graph, ch, ws, up)? && n.flag.contains(EdgeFlags::FOLDER) {
33+
if put_up_context(txn, graph, changes, ws, up)? && n.flag.contains(EdgeFlags::FOLDER) {
3334
return Err(LocalApplyError::InvalidChange);
3435
}
3536
}
@@ -70,10 +71,10 @@ pub fn put_newvertex<T: GraphMutTxnT + TreeTxnT>(
7071
Ok(())
7172
}
7273

73-
fn put_up_context<T: GraphMutTxnT + TreeTxnT>(
74+
fn put_up_context<T: GraphMutTxnT + TreeTxnT, F: FnMut(&Hash) -> bool>(
7475
txn: &mut T,
7576
graph: &mut T::Graph,
76-
ch: &Change,
77+
knows: &mut F,
7778
ws: &mut Workspace,
7879
up: Position<ChangeId>,
7980
) -> Result<bool, LocalApplyError<T>> {
@@ -110,7 +111,7 @@ fn put_up_context<T: GraphMutTxnT + TreeTxnT>(
110111
.contains(EdgeFlags::PARENT | EdgeFlags::DELETED | EdgeFlags::BLOCK)
111112
{
112113
let introduced_by = txn.get_external(&parent.introduced_by())?.unwrap().into();
113-
if !ch.knows(&introduced_by) {
114+
if !knows(&introduced_by) {
114115
ws.deleted_by.insert(parent.introduced_by());
115116
}
116117
}

libpijul/src/unrecord/mod.rs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,6 @@ fn unapply<
177177
T::graph_mut(channel),
178178
change_id,
179179
newedges,
180-
change,
181180
&mut ws,
182181
)?,
183182
Atom::NewVertex(ref newvertex) => {
@@ -389,7 +388,6 @@ fn unapply_edges<T: GraphMutTxnT + TreeTxnT, P: ChangeStore>(
389388
channel: &mut T::Graph,
390389
change_id: ChangeId,
391390
newedges: &EdgeMap<Option<Hash>>,
392-
change: &Change,
393391
ws: &mut Workspace,
394392
) -> Result<(), UnrecordError<P::Error, T>> {
395393
debug!("newedges = {:#?}", newedges);
@@ -433,6 +431,7 @@ fn unapply_edges<T: GraphMutTxnT + TreeTxnT, P: ChangeStore>(
433431
}
434432
}
435433
let reintro = std::mem::take(&mut ws.must_reintroduce);
434+
let hash: Hash = (*txn.get_external(&change_id).unwrap().unwrap()).into();
436435
for edge in newedges.edges.iter() {
437436
let intro = internal(txn, &edge.introduced_by, change_id)?.unwrap();
438437
apply::put_newedge(
@@ -443,7 +442,23 @@ fn unapply_edges<T: GraphMutTxnT + TreeTxnT, P: ChangeStore>(
443442
newedges.inode,
444443
&edge.reverse(Some(ext)),
445444
|a, b| reintro.contains(&(a, b)),
446-
|h| change.knows(h),
445+
|h| {
446+
if edge.previous.contains(EdgeFlags::DELETED) {
447+
// When reintroducing a deleted flag, check whether
448+
// the re-introduction patch knows about the alive
449+
// edges around the target.
450+
changes
451+
.knows(edge.introduced_by.as_ref().unwrap_or(&hash), h)
452+
.unwrap()
453+
} else {
454+
// When the edge we are re-introducing is not a
455+
// deletion edge, this check isn't actually used: the
456+
// only zombies in that case are from a deleted
457+
// context, and these aren't detected with known
458+
// patches.
459+
true
460+
}
461+
},
447462
)?;
448463
}
449464
ws.must_reintroduce = reintro;

0 commit comments

Comments
 (0)