Skip to content

Commit 2fee94f

Browse files
author
fossdd
committed
Update pijul
1 parent 7062a49 commit 2fee94f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+431
-170
lines changed

Cargo.lock

Lines changed: 32 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
pijul = { ... }: {
8484
buildInputs = with pkgs; [
8585
zstd
86+
xxHash
8687
libsodium
8788
libiconv
8889
] ++ lib.optionals stdenv.isDarwin (

libpijul/src/alive/debug.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,10 @@ impl Graph {
109109
}
110110
}
111111
}
112-
for &(edge, VertexId(j)) in
113-
&self.children[line.children..line.children + line.n_children]
112+
for &(edge, VertexId(j)) in (self.children
113+
[line.children..line.children + line.n_children])
114+
.iter()
115+
.chain(line.extra.iter())
114116
{
115117
if let Some(ref edge) = edge {
116118
writeln!(
@@ -127,7 +129,7 @@ impl Graph {
127129
}
128130
)?
129131
} else {
130-
writeln!(w, "n_{}->n_0[label=\"none\"];", i)?
132+
writeln!(w, "n_{}->n_{}[label=\"none\"];", i, j)?
131133
}
132134
}
133135
}
@@ -151,8 +153,10 @@ impl Graph {
151153
line.vertex.end.0,
152154
)?;
153155

154-
for &(edge, VertexId(j)) in
155-
&self.children[line.children..line.children + line.n_children]
156+
for &(edge, VertexId(j)) in self.children
157+
[line.children..line.children + line.n_children]
158+
.iter()
159+
.chain(line.extra.iter())
156160
{
157161
if let Some(ref edge) = edge {
158162
writeln!(
@@ -164,7 +168,7 @@ impl Graph {
164168
edge.introduced_by().to_base32()
165169
)?
166170
} else {
167-
writeln!(w, "n_{}->n_0[label=\"none\"];", i)?
171+
writeln!(w, "n_{}->n_{}[label=\"none\"];", i, j)?
168172
}
169173
}
170174
}

libpijul/src/alive/mod.rs

Lines changed: 55 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,19 @@ mod dfs;
66
mod output;
77
pub mod retrieve;
88
mod tarjan;
9-
pub(crate) use output::*;
10-
pub(crate) use retrieve::*;
9+
pub use output::*;
10+
pub use retrieve::*;
1111

1212
#[derive(Debug, Clone)]
13-
pub(crate) struct AliveVertex {
13+
pub struct AliveVertex {
1414
pub vertex: Vertex<ChangeId>,
1515
flags: Flags,
16-
children: usize,
17-
n_children: usize,
16+
pub children: usize,
17+
pub n_children: usize,
1818
index: usize,
1919
lowlink: usize,
2020
pub scc: usize,
21+
pub extra: Vec<(Option<SerializedEdge>, VertexId)>,
2122
}
2223

2324
bitflags! {
@@ -29,10 +30,10 @@ bitflags! {
2930
}
3031

3132
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)]
32-
pub(crate) struct VertexId(pub(crate) usize);
33+
pub struct VertexId(pub usize);
3334

3435
impl VertexId {
35-
const DUMMY: VertexId = VertexId(0);
36+
pub const DUMMY: VertexId = VertexId(0);
3637
}
3738

3839
impl AliveVertex {
@@ -44,12 +45,26 @@ impl AliveVertex {
4445
index: 0,
4546
lowlink: 0,
4647
scc: 0,
48+
extra: Vec::new(),
4749
};
50+
51+
pub fn new(vertex: Vertex<ChangeId>) -> Self {
52+
AliveVertex {
53+
vertex,
54+
flags: Flags::empty(),
55+
children: 0,
56+
n_children: 0,
57+
index: 0,
58+
lowlink: 0,
59+
scc: 0,
60+
extra: Vec::new(),
61+
}
62+
}
4863
}
4964
#[derive(Debug)]
5065
pub struct Graph {
51-
pub(crate) lines: Vec<AliveVertex>,
52-
children: Vec<(Option<SerializedEdge>, VertexId)>,
66+
pub lines: Vec<AliveVertex>,
67+
pub children: Vec<(Option<SerializedEdge>, VertexId)>,
5368
total_bytes: usize,
5469
}
5570

@@ -75,13 +90,29 @@ impl std::ops::IndexMut<VertexId> for Graph {
7590
}
7691

7792
impl Graph {
78-
pub(crate) fn children(&self, i: VertexId) -> &[(Option<SerializedEdge>, VertexId)] {
93+
pub fn push_child_to_last(&mut self, e: Option<SerializedEdge>, j: VertexId) {
94+
let line = self.lines.last_mut().unwrap();
95+
self.children.push((e, j));
96+
line.n_children += 1;
97+
}
98+
99+
pub fn children<'a>(
100+
&'a self,
101+
i: VertexId,
102+
) -> impl Iterator<Item = &'a (Option<SerializedEdge>, VertexId)> {
79103
let line = &self[i];
80-
&self.children[line.children..line.children + line.n_children]
104+
(&self.children[line.children..line.children + line.n_children])
105+
.iter()
106+
.chain(self[i].extra.iter())
81107
}
82108

83109
fn child(&self, i: VertexId, j: usize) -> &(Option<SerializedEdge>, VertexId) {
84-
&self.children[self[i].children + j]
110+
let line = &self[i];
111+
if j < line.n_children {
112+
&self.children[self[i].children + j]
113+
} else {
114+
&line.extra[j - line.n_children]
115+
}
85116
}
86117
}
87118

@@ -112,13 +143,13 @@ pub(crate) fn remove_redundant_children(
112143
if !visited.insert(p) {
113144
continue;
114145
}
115-
for (_, child) in graph.children(p) {
116-
if graph[p].scc < target_scc && graph[p].scc != graph[*child].scc {
117-
assert!(graph[p].scc > graph[*child].scc);
118-
vertices.remove(&graph[*child].vertex);
146+
for &(_, child) in graph.children(p) {
147+
if graph[p].scc < target_scc && graph[p].scc != graph[child].scc {
148+
assert!(graph[p].scc > graph[child].scc);
149+
vertices.remove(&graph[child].vertex);
119150
}
120-
if graph[*child].scc >= min {
121-
stack.push(*child);
151+
if graph[child].scc >= min {
152+
stack.push(child);
122153
}
123154
}
124155
}
@@ -164,15 +195,15 @@ pub(crate) fn remove_redundant_parents(
164195
}
165196
}
166197
stack.push((p, true));
167-
for (_, child) in graph.children(p) {
168-
if graph[*child].scc >= min {
169-
stack.push((*child, false));
198+
for &(_, child) in graph.children(p) {
199+
if graph[child].scc >= min {
200+
stack.push((child, false));
170201
}
171202
if graph[p].scc > target_scc
172-
&& graph[*child].scc != graph[p].scc
173-
&& covered.contains(&(graph[*child].vertex, target))
203+
&& graph[child].scc != graph[p].scc
204+
&& covered.contains(&(graph[child].vertex, target))
174205
{
175-
assert!(graph[*child].scc < graph[p].scc);
206+
assert!(graph[child].scc < graph[p].scc);
176207
vertices.remove(&graph[p].vertex);
177208
covered.insert((graph[p].vertex, target));
178209
}

libpijul/src/alive/retrieve.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ pub fn retrieve<T: GraphTxnT>(
2525
index: 0,
2626
lowlink: 0,
2727
scc: 0,
28+
extra: Vec::new(),
2829
});
2930
cache.insert(pos0, VertexId(1));
3031

@@ -102,6 +103,7 @@ fn new_vertex<T: GraphTxnT>(
102103
index: 0,
103104
lowlink: 0,
104105
scc: 0,
106+
extra: Vec::new(),
105107
}))
106108
}
107109

libpijul/src/alive/tarjan.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,12 @@ impl Graph {
2727
self[n_l].lowlink = self[n_l].lowlink.min(self[n_child].lowlink);
2828
}
2929

30-
for j in i..self[n_l].n_children {
31-
let &(_, n_child) = self.child(n_l, j);
30+
for j in i..self[n_l].n_children + self[n_l].extra.len() {
31+
let n_child = if j < self[n_l].n_children {
32+
self.child(n_l, j).1
33+
} else {
34+
self[n_l].extra[j - self[n_l].n_children].1
35+
};
3236
if !self[n_child].flags.contains(Flags::VISITED) {
3337
call_stack.push((n_l, j, false));
3438
call_stack.push((n_child, 0, true));

libpijul/src/change.rs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,7 +1216,10 @@ impl Hunk<Option<ChangeId>, LocalByte> {
12161216
) -> Result<Hunk<Option<Hash>, Local>, T::GraphError> {
12171217
self.atom_map(
12181218
|x| x.globalize(txn),
1219-
|l| Local { path: l.path, line: l.line }
1219+
|l| Local {
1220+
path: l.path,
1221+
line: l.line,
1222+
},
12201223
)
12211224
}
12221225
}
@@ -1330,7 +1333,15 @@ impl Change {
13301333
/// directory `dir`, where "<hash>" is the actual hash of the
13311334
/// change.
13321335
#[cfg(feature = "zstd")]
1333-
pub fn serialize<W: Write, E: From<ChangeError>, F: FnOnce(&mut Self, &Hash) -> Result<(), E>>(&mut self, mut w: W, f: F) -> Result<Hash, E> {
1336+
pub fn serialize<
1337+
W: Write,
1338+
E: From<ChangeError>,
1339+
F: FnOnce(&mut Self, &Hash) -> Result<(), E>,
1340+
>(
1341+
&mut self,
1342+
mut w: W,
1343+
f: F,
1344+
) -> Result<Hash, E> {
13341345
// Hashed part.
13351346
let mut hashed = Vec::new();
13361347
bincode::serialize_into(&mut hashed, &self.hashed).map_err(From::from)?;
@@ -1364,7 +1375,11 @@ impl Change {
13641375
let mut contents_comp = Vec::new();
13651376
let now = std::time::Instant::now();
13661377
compress(&self.contents, &mut contents_comp)?;
1367-
debug!("compressed {:?} bytes of contents in {:?}", self.contents.len(), now.elapsed());
1378+
debug!(
1379+
"compressed {:?} bytes of contents in {:?}",
1380+
self.contents.len(),
1381+
now.elapsed()
1382+
);
13681383

13691384
let offsets = Offsets {
13701385
version: VERSION,

0 commit comments

Comments
 (0)