Skip to content

Commit dd1202d

Browse files
author
fossdd
committed
Update pijul
1 parent 19f6a0e commit dd1202d

File tree

13 files changed

+104
-62
lines changed

13 files changed

+104
-62
lines changed

Cargo.lock

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

libpijul/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "libpijul"
33
description = "Core library of Pijul, a distributed version control system based on a sound theory of collaborative work."
4-
version = "1.0.0-beta.2"
4+
version = "1.0.0-beta.3"
55

66
repository = "https://nest.pijul.com/pijul/libpijul"
77
documentation = "https://docs.rs/libpijul"

libpijul/src/find_alive.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ pub(crate) fn find_alive_down<'a, T: GraphTxnT>(
4848
}
4949
debug!("elt = {:?}, vertex = {:?}", elt, vertex);
5050
let elt_index = stack.len();
51+
let mut has_alive_blocks = false;
5152
for v in iter_adj_all(txn, &channel, *vertex)? {
5253
let v = v?;
5354
if v.flag().contains(EdgeFlags::FOLDER) {
@@ -80,8 +81,15 @@ pub(crate) fn find_alive_down<'a, T: GraphTxnT>(
8081
break;
8182
}
8283
}
84+
} else if v.flag().contains(EdgeFlags::DELETED) {
85+
if !has_alive_blocks {
86+
stack.push((*v, None))
87+
}
88+
} else if v.flag().contains(EdgeFlags::BLOCK) {
89+
has_alive_blocks = true;
90+
stack.push((*v, None));
8391
} else {
84-
stack.push((*v, None))
92+
stack.push((*v, None));
8593
}
8694
}
8795
}

libpijul/src/record.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -407,12 +407,12 @@ impl Builder {
407407
Position::ROOT.to_option()
408408
} else if let Some(vertex) = get_inodes_::<_, C, W>(&txn, &channel, &item.inode)? {
409409
{
410-
let mut txn = txn.write();
411-
let mut channel = channel.r.write();
412-
let mut graph = txn.graph(&mut *channel);
410+
let txn = txn.read();
411+
let channel = channel.r.read();
412+
let graph = txn.graph(&*channel);
413413
self.delete_obsolete_children(
414-
&mut *txn,
415-
&mut graph,
414+
&*txn,
415+
&graph,
416416
working_copy,
417417
changes,
418418
&item.full_path,

pijul/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "pijul"
33
description = "A distributed version control system."
4-
version = "1.0.0-beta.1"
4+
version = "1.0.0-beta.2"
55
authors = ["Pierre-Étienne Meunier <pe@pijul.org>"]
66
edition = "2018"
77
repository = "https://nest.pijul.com/pijul/pijul"
@@ -52,7 +52,7 @@ openssl = [ "thrussh/openssl", "thrussh-keys/openssl" ]
5252
human-panic = "1.0"
5353
clap = { version = "3.1", features = [ "derive", "cargo" ] }
5454
anyhow = "1.0"
55-
libpijul = { path = "../libpijul", version = "1.0.0-beta.2", features = [ "tarball" ] }
55+
libpijul = { path = "../libpijul", version = "1.0.0-beta.3", features = [ "tarball" ] }
5656
chrono = { version = "0.4" }
5757
ignore = "0.4"
5858
env_logger = "0.8"

pijul/src/commands/change.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ impl Change {
4343
}
4444
};
4545
let change = changes.get_change(&hash).unwrap();
46-
let colors = super::diff::is_colored();
46+
let colors = super::diff::is_colored(repo.config.pager.as_ref());
4747
change.write(
4848
&changes,
4949
Some(hash),

pijul/src/commands/credit.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,13 @@ impl Credit {
5050
let path = root.strip_prefix(&repo_path.as_path())?.to_str().unwrap();
5151
txn.follow_oldest_path(&repo.changes, &channel, &path)?
5252
};
53-
super::pager();
53+
>>>>>>> 1 [YXAVFTPP]
54+
>>>>>>> 1 [YXAVFTPP]
5455
std::mem::drop(txn);
56+
57+
super::pager(repo.config.pager.as_ref());
58+
59+
<<<<<<< 1
5560
match libpijul::output::output_file(
5661
&repo.changes,
5762
&txn_,
@@ -174,3 +179,8 @@ impl<W: std::io::Write, T: TxnTExt> VertexBuffer for Creditor<W, T> {
174179
Ok(())
175180
}
176181
}
182+
======= 1 [U6TQX5Z2]
183+
>>>>>>> 2 [U6TQX5Z2]
184+
super::pager(repo.config.pager.as_ref());
185+
<<<<<<< 2
186+
<<<<<<< 1

pijul/src/commands/diff.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ impl Diff {
132132
change.dependencies = dependencies;
133133
change.extra_known = extra_known;
134134

135-
let colors = is_colored();
135+
let colors = is_colored(repo.config.pager.as_ref());
136136
if self.json {
137137
let mut changes = BTreeMap::new();
138138
for ch in change.changes.iter() {
@@ -336,7 +336,7 @@ impl<W: termcolor::WriteColor> libpijul::change::WriteChangeLine for Colored<W>
336336
}
337337
}
338338

339-
pub fn is_colored() -> bool {
339+
pub fn is_colored(repo_config_pager: Option<&crate::config::Choice>) -> bool {
340340
let mut colors = atty::is(atty::Stream::Stdout);
341341
if let Ok((global, _)) = crate::config::Global::load() {
342342
match global.colors {
@@ -347,11 +347,11 @@ pub fn is_colored() -> bool {
347347
match global.pager {
348348
Some(crate::config::Choice::Never) => colors = false,
349349
_ => {
350-
super::pager();
350+
super::pager(repo_config_pager);
351351
}
352352
}
353353
} else {
354-
colors &= super::pager();
354+
colors &= super::pager(repo_config_pager);
355355
}
356356
colors
357357
}

pijul/src/commands/git.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -601,13 +601,18 @@ fn git_reset<'a, T: TxnTExt + MutTxnTExt>(
601601
}
602602
}
603603
if !has_parents {
604-
for t in new_tree.iter() {
605-
debug!("t = {:?}", t.name());
606-
if let Some(n) = t.name() {
607-
let n = Path::new(n).to_path_buf();
608-
prefixes.insert(n);
609-
}
610-
}
604+
use git2::{TreeWalkMode, TreeWalkResult};
605+
new_tree
606+
.walk(TreeWalkMode::PreOrder, |x, t| {
607+
debug!("t = {:?} {:?}", x, t.name());
608+
if let Some(n) = t.name() {
609+
let mut m = Path::new(x).to_path_buf();
610+
m.push(n);
611+
prefixes.insert(m);
612+
}
613+
TreeWalkResult::Ok
614+
})
615+
.unwrap();
611616
}
612617
stats.git_diff_time = git_diff_time.elapsed();
613618
debug!("record prefixes {:?}", prefixes);

pijul/src/commands/log.rs

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ impl TryFrom<Log> for LogIterator {
5555
type Error = anyhow::Error;
5656
fn try_from(cmd: Log) -> Result<LogIterator, Self::Error> {
5757
let repo = Repository::find_root(cmd.repo_path.clone())?;
58-
let repo_path = repo.path.clone();
5958
let txn = repo.pristine.txn_begin()?;
6059
let channel_name = if let Some(ref c) = cmd.channel {
6160
c
@@ -76,7 +75,6 @@ impl TryFrom<Log> for LogIterator {
7675
} else {
7776
bail!("No such channel: {:?}", channel_name)
7877
};
79-
let changes = repo.changes;
8078
let limit = cmd.limit.unwrap_or(std::usize::MAX);
8179
let offset = cmd.offset.unwrap_or(0);
8280

@@ -91,9 +89,8 @@ impl TryFrom<Log> for LogIterator {
9189

9290
Ok(Self {
9391
txn,
92+
repo,
9493
cmd,
95-
changes,
96-
repo_path,
9794
id_path,
9895
global_id_path,
9996
channel_ref,
@@ -269,10 +266,10 @@ impl std::fmt::Display for LogEntry {
269266
/// a full implementation of Iterator because serde's serialize method requires
270267
/// self to be an immutable reference.
271268
struct LogIterator {
272-
txn: Txn,
273-
changes: libpijul::changestore::filesystem::FileSystem,
269+
/// The parsed CLI command
274270
cmd: Log,
275-
repo_path: PathBuf,
271+
txn: Txn,
272+
repo: Repository,
276273
id_path: PathBuf,
277274
global_id_path: Option<PathBuf>,
278275
channel_ref: ChannelRef<Txn>,
@@ -326,7 +323,7 @@ impl LogIterator {
326323
let mut id_path = self.id_path.clone();
327324
let mut global_id_path = self.global_id_path.clone();
328325

329-
let inodes = get_inodes(&self.txn, &self.repo_path, &self.cmd.filters)?;
326+
let inodes = get_inodes(&self.txn, &self.repo.path, &self.cmd.filters)?;
330327
let mut offset = self.offset;
331328
let mut limit = self.limit;
332329
for pr in self.txn.reverse_log(&*self.channel_ref.read(), None)? {
@@ -380,7 +377,7 @@ impl LogIterator {
380377
if self.cmd.hash_only {
381378
return Ok(LogEntry::Hash(h));
382379
}
383-
let header = self.changes.get_header(&h.into())?;
380+
let header = self.repo.changes.get_header(&h.into())?;
384381
let authors = header
385382
.authors
386383
.into_iter()
@@ -451,21 +448,20 @@ impl Log {
451448
// serialization to a serde target format, this now delegates
452449
// mostly to [`LogIterator`].
453450
pub fn run(self) -> Result<(), anyhow::Error> {
451+
let log_iter = LogIterator::try_from(self)?;
454452
let mut stdout = std::io::stdout();
455-
match self.output_format.as_ref().map(|s| s.as_str()) {
453+
454+
super::pager(log_iter.repo.config.pager.as_ref());
455+
456+
match log_iter.cmd.output_format.as_ref().map(|s| s.as_str()) {
456457
Some(s) if s.eq_ignore_ascii_case("json") => {
457-
serde_json::to_writer_pretty(&mut stdout, &LogIterator::try_from(self)?)?
458-
}
459-
_ => {
460-
super::pager();
461-
LogIterator::try_from(self)?.for_each(|entry| {
462-
match write!(&mut stdout, "{}", entry) {
463-
Ok(_) => Ok(()),
464-
Err(e) if e.kind() == std::io::ErrorKind::BrokenPipe => Ok(()),
465-
Err(e) => Err(e),
466-
}
467-
})?
458+
serde_json::to_writer_pretty(&mut stdout, &log_iter)?
468459
}
460+
_ => log_iter.for_each(|entry| match write!(&mut stdout, "{}", entry) {
461+
Ok(_) => Ok(()),
462+
Err(e) if e.kind() == std::io::ErrorKind::BrokenPipe => Ok(()),
463+
Err(e) => Err(e),
464+
})?,
469465
}
470466
Ok(())
471467
}

pijul/src/commands/mod.rs

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -120,24 +120,46 @@ fn pending<T: libpijul::MutTxnTExt + libpijul::TxnT + Send + Sync + 'static>(
120120
Ok(Some(hash))
121121
}
122122

123+
/// Respect the `pager` key/value pair in both the user's repository config, and their global config.
124+
/// The global configuration requires no additional arguments, but the other two are optional to cover
125+
/// cases in which that information is not available. Users can also disable the pager by not setting
126+
/// the `PAGER` environment variable.
123127
#[cfg(unix)]
124-
fn pager() -> bool {
125-
if let Ok(less) = std::process::Command::new("less")
126-
.args(&["--version"])
127-
.output()
128+
fn pager(repo_config_pager: Option<&crate::config::Choice>) -> bool {
129+
if let Some(crate::config::Choice::Never) = repo_config_pager {
130+
return false;
131+
} else if let Some(crate::config::Choice::Never) = crate::config::Global::load()
132+
.ok()
133+
.and_then(|(global, _)| global.pager)
128134
{
129-
let regex = regex::bytes::Regex::new("less ([0-9]+)").unwrap();
130-
if let Some(caps) = regex.captures(&less.stdout) {
131-
if std::str::from_utf8(&caps[1])
132-
.unwrap()
133-
.parse::<usize>()
134-
.unwrap()
135-
>= 530
136-
{
137-
pager::Pager::with_pager("less -RF").setup();
138-
return true;
139-
} else {
140-
pager::Pager::new().setup();
135+
return false;
136+
} else if let Ok(pager_env_var) = std::env::var("PAGER") {
137+
if !pager_env_var.is_empty() {
138+
match pager_env_var.as_str() {
139+
"less" => {
140+
if let Ok(pager_output) = std::process::Command::new(pager_env_var)
141+
.args(&["--version"])
142+
.output()
143+
{
144+
let regex = regex::bytes::Regex::new("less ([0-9]+)").unwrap();
145+
if let Some(caps) = regex.captures(&pager_output.stdout) {
146+
if std::str::from_utf8(&caps[1])
147+
.unwrap()
148+
.parse::<usize>()
149+
.unwrap()
150+
>= 530
151+
{
152+
pager::Pager::with_pager("less -RF").setup();
153+
return true;
154+
} else {
155+
pager::Pager::new().setup();
156+
}
157+
}
158+
}
159+
}
160+
owise => {
161+
pager::Pager::with_pager(owise).setup();
162+
}
141163
}
142164
}
143165
}

pijul/src/commands/tag.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ impl Tag {
247247
bail!("Channel {:?} not found", channel_name)
248248
};
249249
let mut tag_path = repo.changes_dir.clone();
250-
super::pager();
250+
super::pager(repo.config.pager.as_ref());
251251
for t in txn.rev_iter_tags(txn.tags(&*channel.read()), None)? {
252252
let (t, _) = t?;
253253
let (_, m) = txn.get_changes(&channel, (*t).into())?.unwrap();

pijul/src/remote/local.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ impl Local {
249249
if ml.modified()? < m.modified()? {
250250
std::fs::remove_file(&path)?;
251251
} else {
252+
path.pop();
252253
continue;
253254
}
254255
}

0 commit comments

Comments
 (0)