Skip to content

Commit 2abde00

Browse files
author
fossdd
committed
Update pijul
1 parent c703861 commit 2abde00

File tree

7 files changed

+49
-38
lines changed

7 files changed

+49
-38
lines changed

libpijul/src/change.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ pub enum ChangeError {
2929
VersionMismatch { got: u64 },
3030
#[error(transparent)]
3131
Io(#[from] std::io::Error),
32+
#[error("while retrieving {:?}: {}", hash, err)]
33+
IoHash {
34+
err: std::io::Error,
35+
hash: crate::pristine::Hash,
36+
},
3237
#[error(transparent)]
3338
Bincode(#[from] bincode::Error),
3439
#[error(transparent)]
@@ -1520,7 +1525,13 @@ impl Change {
15201525
#[cfg(feature = "zstd")]
15211526
pub fn deserialize(file: &str, hash: Option<&Hash>) -> Result<Self, ChangeError> {
15221527
use std::io::Read;
1523-
let mut r = std::fs::File::open(file)?;
1528+
let mut r = std::fs::File::open(file).map_err(|err| {
1529+
if let Some(h) = hash {
1530+
ChangeError::IoHash { err, hash: *h }
1531+
} else {
1532+
ChangeError::Io(err)
1533+
}
1534+
})?;
15241535
let mut buf = vec![0u8; Self::OFFSETS_SIZE as usize];
15251536
r.read_exact(&mut buf)?;
15261537
let offsets: Offsets = bincode::deserialize(&buf)?;

libpijul/src/change/change_file.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ impl ChangeFile {
3838
/// Open a change file from a path.
3939
pub fn open(hash: Hash, path: &str) -> Result<Self, ChangeError> {
4040
use std::io::Read;
41-
let mut r = std::fs::File::open(path)?;
41+
let mut r = std::fs::File::open(path).map_err(|err| ChangeError::IoHash { err, hash })?;
4242
let mut buf = Vec::new();
4343
buf.resize(Change::OFFSETS_SIZE as usize, 0);
4444
r.read_exact(&mut buf)?;

libpijul/src/pristine/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,7 @@ pub trait TxnT:
661661

662662
fn state_from_prefix(
663663
&self,
664-
channel: &Self::Channel,
664+
channel: &Self::States,
665665
s: &str,
666666
) -> Result<(Merkle, L64), HashPrefixError<Self::GraphError>>;
667667

libpijul/src/pristine/sanakirja.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,12 +360,16 @@ impl Txn {
360360

361361
let rev: UDb<SerializedHash, L64> = UDb::from_page(tup.rev.into());
362362
let states: UDb<SerializedMerkle, L64> = UDb::from_page(tup.states.into());
363+
let tags: UDb<L64, Pair<SerializedMerkle, SerializedMerkle>> =
364+
UDb::from_page(tup.tags.into());
363365
debug!("check: remote 0x{:x}", remote.db);
364366
remote.add_refs(&self.txn, refs).unwrap();
365367
debug!("check: rev 0x{:x}", rev.db);
366368
rev.add_refs(&self.txn, refs).unwrap();
367369
debug!("check: states 0x{:x}", states.db);
368370
states.add_refs(&self.txn, refs).unwrap();
371+
debug!("check: tags 0x{:x}", tags.db);
372+
tags.add_refs(&self.txn, refs).unwrap();
369373
}
370374
::sanakirja::debug::add_free_refs(&self.txn, refs).unwrap();
371375
::sanakirja::debug::check_free(&self.txn, &refs);
@@ -1248,7 +1252,7 @@ impl<T: ::sanakirja::LoadPage<Error = ::sanakirja::Error> + ::sanakirja::RootPag
12481252

12491253
fn state_from_prefix(
12501254
&self,
1251-
channel: &Self::Channel,
1255+
channel: &Self::States,
12521256
s: &str,
12531257
) -> Result<(Merkle, L64), super::HashPrefixError<Self::GraphError>> {
12541258
let h: SerializedMerkle = if let Some(ref h) = Merkle::from_prefix(s) {
@@ -1258,7 +1262,7 @@ impl<T: ::sanakirja::LoadPage<Error = ::sanakirja::Error> + ::sanakirja::RootPag
12581262
};
12591263
let mut result = None;
12601264
debug!("h = {:?}", h);
1261-
for x in btree::iter(&self.txn, &channel.states, Some((&h, None)))
1265+
for x in btree::iter(&self.txn, &channel, Some((&h, None)))
12621266
.map_err(|e| super::HashPrefixError::Txn(e.into()))?
12631267
{
12641268
let (e, i) = x.map_err(|e| super::HashPrefixError::Txn(e.into()))?;

libpijul/src/tag/txn.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
use super::*;
22
use crate::small_string::SmallStr;
3+
use std::collections::HashMap;
34
use std::sync::Mutex;
45

5-
/// Size of the LRU cache.
6-
const CACHE_SIZE: usize = 1024;
7-
86
struct WithOffset<R> {
97
off: u64,
108
r: R,
@@ -31,7 +29,7 @@ impl<R: Seek> Seek for WithOffset<R> {
3129
pub struct TagTxn {
3230
pub(crate) header: FileHeader,
3331
s: Mutex<zstd_seekable::Seekable<'static, WithOffset<std::fs::File>>>,
34-
loaded: Mutex<lru_cache::LruCache<u64, Box<[u8; crate::tag::BLOCK_SIZE]>>>,
32+
loaded: Mutex<HashMap<u64, Box<[u8; crate::tag::BLOCK_SIZE]>>>,
3533
}
3634

3735
impl std::convert::From<BlockError<::zstd_seekable::Error>> for BlockError<TagError> {
@@ -70,14 +68,22 @@ impl TagTxn {
7068
}))?;
7169
Ok(TagTxn {
7270
header: ch.header,
73-
loaded: Mutex::new(lru_cache::LruCache::new(CACHE_SIZE)),
71+
loaded: Mutex::new(HashMap::new()),
7472
s: Mutex::new(s),
7573
})
7674
}
7775

7876
pub fn channel(&self) -> ChannelRef<Self> {
7977
ChannelRef::new(self.header.offsets.clone())
8078
}
79+
80+
/// Clear the cache, freeing memory.
81+
pub fn clear(&mut self) {
82+
// This function is only safe because it takes a mutable
83+
// borrow, and all references returned by the methods on
84+
// `TagTxn` return immutable borrows of `self`.
85+
self.loaded.lock().unwrap().clear()
86+
}
8187
}
8288

8389
impl ::sanakirja::LoadPage for TagTxn {

pijul/src/commands/pushpull.rs

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,6 @@ pub struct Push {
9191
/// Push to this remote channel instead of the remote's default channel
9292
#[clap(long = "to-channel")]
9393
to_channel: Option<String>,
94-
/// Push tags instead of regular changes.
95-
#[clap(long = "tag")]
96-
is_tag: bool,
9794
/// Push only these changes
9895
#[clap(last = true)]
9996
changes: Vec<String>,
@@ -150,7 +147,6 @@ impl Push {
150147
channel: &mut ChannelRef<MutTxn<()>>,
151148
repo: &Repository,
152149
remote: &mut RemoteRepo,
153-
is_tag: bool,
154150
) -> Result<PushDelta, anyhow::Error> {
155151
let remote_delta = remote
156152
.update_changelist_pushpull(
@@ -160,7 +156,7 @@ impl Push {
160156
Some(self.force_cache),
161157
repo,
162158
self.changes.as_slice(),
163-
is_tag,
159+
false,
164160
)
165161
.await?;
166162
if let RemoteRepo::LocalChannel(ref remote_channel) = remote {
@@ -231,13 +227,7 @@ impl Push {
231227
unknown_changes,
232228
..
233229
} = self
234-
.to_upload(
235-
&mut *txn.write(),
236-
&mut channel,
237-
&repo,
238-
&mut remote,
239-
self.is_tag,
240-
)
230+
.to_upload(&mut *txn.write(), &mut channel, &repo, &mut remote)
241231
.await?;
242232

243233
debug!("to_upload = {:?}", to_upload);
@@ -341,7 +331,6 @@ impl Pull {
341331
channel: &mut ChannelRef<MutTxn<()>>,
342332
repo: &mut Repository,
343333
remote: &mut RemoteRepo,
344-
is_tag: bool,
345334
) -> Result<RemoteDelta<MutTxn<()>>, anyhow::Error> {
346335
let force_cache = if self.force_cache {
347336
Some(self.force_cache)
@@ -356,7 +345,7 @@ impl Pull {
356345
force_cache,
357346
repo,
358347
self.changes.as_slice(),
359-
is_tag,
348+
true,
360349
)
361350
.await?;
362351
let to_download = remote
@@ -423,13 +412,7 @@ impl Pull {
423412
remote_unrecs,
424413
..
425414
} = self
426-
.to_download(
427-
&mut *txn.write(),
428-
&mut channel,
429-
&mut repo,
430-
&mut remote,
431-
self.is_tag,
432-
)
415+
.to_download(&mut *txn.write(), &mut channel, &mut repo, &mut remote)
433416
.await?;
434417

435418
let hash = super::pending(txn.clone(), &mut channel, &mut repo)?;
@@ -549,7 +532,7 @@ impl Pull {
549532
}
550533
}
551534
}
552-
if touched_paths.is_empty() && !self.is_tag {
535+
if touched_paths.is_empty() {
553536
touched_paths.insert(String::from(""));
554537
}
555538
let mut last = None;

pijul/src/remote/mod.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ impl RemoteRepo {
599599
force_cache: Option<bool>,
600600
repo: &Repository,
601601
specific_changes: &[String],
602-
is_tag: bool,
602+
is_pull: bool,
603603
) -> Result<RemoteDelta<MutTxn<()>>, anyhow::Error> {
604604
debug!("update_changelist_pushpull");
605605
if let RemoteRepo::LocalChannel(c) = self {
@@ -694,12 +694,19 @@ impl RemoteRepo {
694694
let to_download = specific_changes
695695
.iter()
696696
.map(|h| {
697-
if is_tag {
698-
Ok(CS::State(
699-
txn.state_from_prefix(&*current_channel.read(), h)?.0,
700-
))
697+
if is_pull {
698+
{
699+
if let Ok(t) = txn.state_from_prefix(&remote_ref.lock().states, h) {
700+
return Ok(CS::State(t.0));
701+
}
702+
}
703+
Ok(CS::Change(txn.hash_from_prefix_remote(&remote_ref, h)?))
701704
} else {
702-
Ok(CS::Change(txn.hash_from_prefix(h)?.0))
705+
if let Ok(t) = txn.state_from_prefix(&current_channel.read().states, h) {
706+
Ok(CS::State(t.0))
707+
} else {
708+
Ok(CS::Change(txn.hash_from_prefix(h)?.0))
709+
}
703710
}
704711
})
705712
.collect::<Result<Vec<_>, anyhow::Error>>();

0 commit comments

Comments
 (0)