Skip to content

Commit 0fdec13

Browse files
authored
Fix: search in log (gitui-org#1838)
1 parent 5b2b8c7 commit 0fdec13

File tree

7 files changed

+205
-198
lines changed

7 files changed

+205
-198
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
.PHONY: debug build-release release-linux-musl test clippy clippy-pedantic install install-debug
33

44
ARGS=-l
5-
# ARGS=-l -d ~/code/extern/pbrt-v4
5+
# ARGS=-l -d ~/code/extern/linux
66
# ARGS=-l -d ~/code/git-bare-test.git -w ~/code/git-bare-test
77

88
profile:

asyncgit/src/revlog.rs

+28-18
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::{
22
error::Result,
33
sync::{repo, CommitId, LogWalker, LogWalkerFilter, RepoPath},
4-
AsyncGitNotification,
4+
AsyncGitNotification, Error,
55
};
66
use crossbeam_channel::Sender;
77
use scopetime::scope_time;
@@ -15,7 +15,7 @@ use std::{
1515
};
1616

1717
///
18-
#[derive(PartialEq, Eq)]
18+
#[derive(PartialEq, Eq, Debug)]
1919
pub enum FetchStatus {
2020
/// previous fetch still running
2121
Pending,
@@ -40,6 +40,7 @@ pub struct AsyncLog {
4040
pending: Arc<AtomicBool>,
4141
background: Arc<AtomicBool>,
4242
filter: Option<LogWalkerFilter>,
43+
partial_extract: AtomicBool,
4344
repo: RepoPath,
4445
}
4546

@@ -65,6 +66,7 @@ impl AsyncLog {
6566
pending: Arc::new(AtomicBool::new(false)),
6667
background: Arc::new(AtomicBool::new(false)),
6768
filter,
69+
partial_extract: AtomicBool::new(false),
6870
}
6971
}
7072

@@ -89,21 +91,26 @@ impl AsyncLog {
8991

9092
///
9193
pub fn get_items(&self) -> Result<Vec<CommitId>> {
94+
if self.partial_extract.load(Ordering::Relaxed) {
95+
return Err(Error::Generic(String::from("Faulty usage of AsyncLog: Cannot partially extract items and rely on get_items slice to still work!")));
96+
}
97+
9298
let list = &self.current.lock()?.commits;
9399
Ok(list.clone())
94100
}
95101

96102
///
97-
pub fn get_last_duration(&self) -> Result<Duration> {
98-
Ok(self.current.lock()?.duration)
103+
pub fn extract_items(&self) -> Result<Vec<CommitId>> {
104+
self.partial_extract.store(true, Ordering::Relaxed);
105+
let list = &mut self.current.lock()?.commits;
106+
let result = list.clone();
107+
list.clear();
108+
Ok(result)
99109
}
100110

101111
///
102-
pub fn position(&self, id: CommitId) -> Result<Option<usize>> {
103-
let list = &self.current.lock()?.commits;
104-
let position = list.iter().position(|&x| x == id);
105-
106-
Ok(position)
112+
pub fn get_last_duration(&self) -> Result<Duration> {
113+
Ok(self.current.lock()?.duration)
107114
}
108115

109116
///
@@ -143,6 +150,8 @@ impl AsyncLog {
143150
return Ok(FetchStatus::NoChange);
144151
}
145152

153+
self.pending.store(true, Ordering::Relaxed);
154+
146155
self.clear()?;
147156

148157
let arc_current = Arc::clone(&self.current);
@@ -152,8 +161,6 @@ impl AsyncLog {
152161
let filter = self.filter.clone();
153162
let repo_path = self.repo.clone();
154163

155-
self.pending.store(true, Ordering::Relaxed);
156-
157164
if let Ok(head) = repo(&self.repo)?.head() {
158165
*self.current_head.lock()? =
159166
head.target().map(CommitId::new);
@@ -192,17 +199,16 @@ impl AsyncLog {
192199
let r = repo(repo_path)?;
193200
let mut walker =
194201
LogWalker::new(&r, LIMIT_COUNT)?.filter(filter);
202+
195203
loop {
196204
entries.clear();
197-
let res_is_err = walker.read(&mut entries).is_err();
205+
let read = walker.read(&mut entries)?;
198206

199-
if !res_is_err {
200-
let mut current = arc_current.lock()?;
201-
current.commits.extend(entries.iter());
202-
current.duration = start_time.elapsed();
203-
}
207+
let mut current = arc_current.lock()?;
208+
current.commits.extend(entries.iter());
209+
current.duration = start_time.elapsed();
204210

205-
if res_is_err || entries.len() <= 1 {
211+
if read == 0 {
206212
break;
207213
}
208214
Self::notify(sender);
@@ -213,15 +219,19 @@ impl AsyncLog {
213219
} else {
214220
SLEEP_FOREGROUND
215221
};
222+
216223
thread::sleep(sleep_duration);
217224
}
218225

226+
log::trace!("revlog visited: {}", walker.visited());
227+
219228
Ok(())
220229
}
221230

222231
fn clear(&mut self) -> Result<()> {
223232
self.current.lock()?.commits.clear();
224233
*self.current_head.lock()? = None;
234+
self.partial_extract.store(false, Ordering::Relaxed);
225235
Ok(())
226236
}
227237

asyncgit/src/sync/logwalker.rs

+5
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,11 @@ impl<'a> LogWalker<'a> {
261261
})
262262
}
263263

264+
///
265+
pub fn visited(&self) -> usize {
266+
self.visited.len()
267+
}
268+
264269
///
265270
#[must_use]
266271
pub fn filter(self, filter: Option<LogWalkerFilter>) -> Self {

0 commit comments

Comments
 (0)