Removes the filesystem::push_filename and pop_filename methods in favor of fmt_filename which does not modify the original string, plus other similar changes like that which allow code to no longer have to worry about returning the string it's borrowing back to its original state, especially in case of branching.
UDGL7ER2R6SY2CBSPA4O4ULQ5PCUDWQBGYOWTN3MQGSS5L2EI2LQC
UTEVDVGBBJZWMPQIM3NSSVN2GNBMY6I6FTAVXER7NMVBQSYKAVBAC
ZLDTKXNASMGT27LAFUS5WOXKZIPYZA65Y4JVKWQRMQP7IGLU2QAAC
TSQI6N2IVX6TRXBGMMFEVGPY2TY2ULLVE3TSTQ266GX5JGYSMZ6QC
5SCFAC4I7WQGP6WR3ZJFJ3CQCKX57FRVYKP3HPIJPIGJGDNTQJSAC
E6IKUIPDX3P5CHW5R62DEJTCZZFJIM6UKQ6QN3SPASTAJY3MYZWQC
OGJFEWHUMFIZYBS456FPNUN3KEUDZXIJNFGPEMJGQDC7INZMHQZQC
SXEYMYF7P4RZMZ46WPL4IZUTSQ2ATBWYZX7QNVMS3SGOYXYOHAGQC
DWSAYGVEOR4D2EKIICEZUWCRGJTUXQQLOUWMYIFV7XN62K44F4FAC
UDHP4ZVBQZT2VBURB2MDCU2IZDNMCAFSIUKWRBDQ5BWMFKSN2LYQC
L4JXJHWXYNCL4QGJXNKKTOKKTAXKKXBJUUY7HFZGEUZ5A2V5H34QC
MU5GSJAW65PEG3BRYUKZ7O37BPHW3MOX3S5E2RFOXKGUOJEEDQ5AC
3WO4H2MMMQTYKCPBWYE67IRAEX7DFA2XAOMIKICA6BYDN23K6DQQC
DO2Y5TY5JQISUHCVNPI2FXO7WWZVJQ3LGPWF4DNADMGZRIO6PT2QC
TKEVOH7HXON7SOBGXTUDHAHO2U2GPTQRNESP6ERKUQAS526OZIRAC
ISCWVXO6UN37V2QMR75ZWS7H5E7WYZCGR6TX3EDFOFRVCAPMIVUAC
JUYSZJSHULJFR4HUJF72TEKKFMBPG4ZOGAGOJ2BX6P3D4DRZAU5QC
4XLHUME7YLJV6XUZBOW7PX62TCJXIWW2CP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NAMETYO4I52QKASQ3COYHH2JKGA7W5YLIRZZH53AC
7ZROQSSN2M3LW6ASYMM6DPR5AERWV4K4TKWKEBKTCEJPMIJAHHXQC
ZZXBHCN3WGJG26SBKZP3ZG4FYUKY7WK2EDSDXLDMQLK7PDKXISPQC
TYTQGSKZTHRGBOD6HQGK3VWWPXYXT5JONXYOV65ZO4O3HT7MBUNQC
I24UEJQLCH2SOXA4UHIYWTRDCHSOPU7AFTRUOTX7HZIAV4AZKYEQC
libpijul::changestore::filesystem::push_filename(final_path, h);
debug!("moving {:?} to {:?}", path, final_path);
std::fs::create_dir_all(&final_path.parent().unwrap())?;
let r = std::fs::rename(&path, &final_path);
libpijul::changestore::filesystem::pop_filename(final_path);
let p = fmt_filename(&mut buf, &destdir, &h);
debug!("moving {:?} to {:?}", path, p);
std::fs::create_dir_all(&p.parent().unwrap())?;
let r = std::fs::rename(&path, &p);
libpijul::changestore::filesystem::push_tag_filename(
final_path, &h,
);
debug!("moving {:?} to {:?}", path, final_path);
std::fs::create_dir_all(&final_path.parent().unwrap())?;
let r = std::fs::rename(&path, &final_path);
libpijul::changestore::filesystem::pop_filename(final_path);
let p = fmt_filename(&mut buf, &destdir, &h);
debug!("moving {:?} to {:?}", path, p);
std::fs::create_dir_all(&p.parent().unwrap())?;
let r = std::fs::rename(&path, &p);
match c {
CS::Change(c) => {
libpijul::changestore::filesystem::push_filename(&mut local, &c);
libpijul::changestore::filesystem::push_filename(&mut self.changes_dir, &c);
let src = fmt_filename(&mut buf, &changes_dir, c);
let dest = fmt_filename(&mut buf2, &changes_dir, c);
std::fs::create_dir_all(&dest.parent().unwrap())?;
debug!("hard link {:?} {:?}", src, dest);
if std::fs::metadata(&dest).is_err() {
if std::fs::hard_link(&src, &dest).is_err() {
std::fs::copy(&src, &dest)?;
std::fs::create_dir_all(&self.changes_dir.parent().unwrap())?;
debug!("hard link {:?} {:?}", local, self.changes_dir);
if std::fs::metadata(&self.changes_dir).is_err() {
if std::fs::hard_link(&local, &self.changes_dir).is_err() {
std::fs::copy(&local, &self.changes_dir)?;
}
}
match c {
CS::Change(c) => {
libpijul::changestore::filesystem::push_filename(&mut self.changes_dir, &c);
libpijul::changestore::filesystem::push_filename(&mut path, &c);
}
CS::State(c) => {
libpijul::changestore::filesystem::push_tag_filename(&mut self.changes_dir, &c);
libpijul::changestore::filesystem::push_tag_filename(&mut path, &c);
}
}
let src = fmt_filename(&mut buf, &self.changes_dir, &c);
let dest = fmt_filename(&mut buf2, &dest_dir, &c);
if std::fs::metadata(&path).is_ok() {
debug!("metadata {:?} ok", path);
libpijul::changestore::filesystem::pop_filename(&mut self.changes_dir);
libpijul::changestore::filesystem::pop_filename(&mut path);
if std::fs::metadata(&dest).is_ok() {
debug!("metadata {:?} ok", dest);
std::fs::create_dir_all(&path.parent().unwrap())?;
if std::fs::hard_link(&self.changes_dir, &path).is_err() {
std::fs::copy(&self.changes_dir, &path)?;
std::fs::create_dir_all(&dest.parent().unwrap())?;
if std::fs::hard_link(&src, &dest).is_err() {
std::fs::copy(&src, &dest)?;
match h {
CS::Change(h) => {
libpijul::changestore::filesystem::push_filename(&mut change_path_, h);
}
CS::State(h) => {
libpijul::changestore::filesystem::push_tag_filename(&mut change_path_, h);
}
}
let mut tag_path = repo.changes_dir.clone();
let h = if let Some(h) = libpijul::Merkle::from_base32(tag.as_bytes()) {
libpijul::changestore::filesystem::push_tag_filename(&mut tag_path, &h);
h
} else {
super::find_hash(&mut tag_path, &tag)?
let h = match Merkle::from_base32(tag.as_bytes()) {
None => super::find_hash(&repo.changes_dir, &tag)?,
Some(v) => v,
let mut tag_path = repo.changes_dir.clone();
let h = if let Some(h) = libpijul::Merkle::from_base32(tag.as_bytes()) {
libpijul::changestore::filesystem::push_tag_filename(&mut tag_path, &h);
h
} else {
super::find_hash(&mut tag_path, &tag)?
let h = match Merkle::from_base32(tag.as_bytes()) {
None => super::find_hash(&repo.changes_dir, &tag)?,
Some(v) => v,
let mut tag_path = repo.changes_dir.clone();
let h = if let Some(h) = libpijul::Merkle::from_base32(tag.as_bytes()) {
libpijul::changestore::filesystem::push_tag_filename(&mut tag_path, &h);
h
} else {
super::find_hash(&mut tag_path, &tag)?
let h = match Merkle::from_base32(tag.as_bytes()) {
None => super::find_hash(&repo.changes_dir, &tag)?,
Some(v) => v,
libpijul::changestore::filesystem::push_filename(&mut repo.changes_dir, &h);
debug!("repo = {:?}", repo.changes_dir);
let mut f = std::fs::File::open(&repo.changes_dir)?;
let size = std::fs::metadata(&repo.changes_dir)?.len();
let path = fmt_filename(&mut path_buf, &repo.changes_dir, &h);
debug!("repo = {:?}", path);
let mut f = std::fs::File::open(&path)?;
let size = std::fs::metadata(&path)?.len();
pub fn push_filename(changes_dir: &mut PathBuf, hash: &Hash) {
let h32 = hash.to_base32();
let (a, b) = h32.split_at(2);
changes_dir.push(a);
changes_dir.push(b);
changes_dir.set_extension("change");
impl<T> CacheEntry for &T
where
T: CacheEntry,
{
fn hash(&self) -> String {
(*self).hash()
}
fn ext(&self) -> &str {
(*self).ext()
}
pub fn push_tag_filename(changes_dir: &mut PathBuf, hash: &Merkle) {
let h32 = hash.to_base32();
let (a, b) = h32.split_at(2);
changes_dir.push(a);
changes_dir.push(b);
changes_dir.set_extension("tag");
impl CacheEntry for Hash {
fn hash(&self) -> String {
self.to_base32()
}
fn ext(&self) -> &str {
"change"
}
pub fn filename(&self, hash: &Hash) -> PathBuf {
let mut path = self.changes_dir.clone();
push_filename(&mut path, hash);
pub fn filename<T>(&self, entry: &T) -> PathBuf
where
T: CacheEntry,
{
let mut path = PathBuf::new();
self.fmt_filename(&mut path, entry);
pub fn tag_filename(&self, hash: &Merkle) -> PathBuf {
let mut path = self.changes_dir.clone();
push_tag_filename(&mut path, hash);
path
pub fn fmt_filename<'a, T>(&self, buf: &'a mut PathBuf, entry: &T) -> &'a Path
where
T: CacheEntry,
{
fmt_filename(buf, &self.changes_dir, entry)