Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
extrawurst committed Aug 26, 2023
1 parent d1418bb commit 1fca82c
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 64 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
.PHONY: debug build-release release-linux-musl test clippy clippy-pedantic install install-debug

ARGS=-l
# ARGS=-l -d ~/code/extern/pbrt-v4
# ARGS=-l -d ~/code/extern/linux
# ARGS=-l -d ~/code/git-bare-test.git -w ~/code/git-bare-test

profile:
Expand Down
30 changes: 12 additions & 18 deletions asyncgit/src/revlog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use std::{
};

///
#[derive(PartialEq, Eq)]
#[derive(PartialEq, Eq, Debug)]
pub enum FetchStatus {
/// previous fetch still running
Pending,
Expand Down Expand Up @@ -106,14 +106,6 @@ impl AsyncLog {
Ok(self.current.lock()?.duration)
}

///
pub fn position(&self, id: CommitId) -> Result<Option<usize>> {
let list = &self.current.lock()?.commits;
let position = list.iter().position(|&x| x == id);

Ok(position)
}

///
pub fn is_pending(&self) -> bool {
self.pending.load(Ordering::Relaxed)
Expand Down Expand Up @@ -151,6 +143,8 @@ impl AsyncLog {
return Ok(FetchStatus::NoChange);
}

self.pending.store(true, Ordering::Relaxed);

self.clear()?;

let arc_current = Arc::clone(&self.current);
Expand All @@ -160,8 +154,6 @@ impl AsyncLog {
let filter = self.filter.clone();
let repo_path = self.repo.clone();

self.pending.store(true, Ordering::Relaxed);

if let Ok(head) = repo(&self.repo)?.head() {
*self.current_head.lock()? =
head.target().map(CommitId::new);
Expand Down Expand Up @@ -200,17 +192,16 @@ impl AsyncLog {
let r = repo(repo_path)?;
let mut walker =
LogWalker::new(&r, LIMIT_COUNT)?.filter(filter);

loop {
entries.clear();
let res_is_err = walker.read(&mut entries).is_err();
let read = walker.read(&mut entries)?;

if !res_is_err {
let mut current = arc_current.lock()?;
current.commits.extend(entries.iter());
current.duration = start_time.elapsed();
}
let mut current = arc_current.lock()?;
current.commits.extend(entries.iter());
current.duration = start_time.elapsed();

if res_is_err || entries.len() <= 1 {
if read == 0 {
break;
}
Self::notify(sender);
Expand All @@ -221,9 +212,12 @@ impl AsyncLog {
} else {
SLEEP_FOREGROUND
};

thread::sleep(sleep_duration);
}

log::trace!("revlog visited: {}", walker.visited());

Ok(())
}

Expand Down
5 changes: 5 additions & 0 deletions asyncgit/src/sync/logwalker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,11 @@ impl<'a> LogWalker<'a> {
})
}

///
pub fn visited(&self) -> usize {
self.visited.len()
}

///
#[must_use]
pub fn filter(self, filter: Option<LogWalkerFilter>) -> Self {
Expand Down
28 changes: 18 additions & 10 deletions src/components/commitlist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ impl CommitList {
}

///
pub fn selected_entry_marked(&self) -> bool {
fn selected_entry_marked(&self) -> bool {
self.selected_entry()
.and_then(|e| self.is_marked(&e.id))
.unwrap_or_default()
Expand Down Expand Up @@ -156,6 +156,7 @@ impl CommitList {
commits
}

///
pub fn copy_commit_hash(&self) -> Result<()> {
let marked = self.marked.as_slice();
let yank: Option<String> = match marked {
Expand Down Expand Up @@ -235,11 +236,7 @@ impl CommitList {

self.selection = new_selection;

if self
.selected_entry()
.map(|entry| entry.highlighted)
.unwrap_or_default()
{
if self.selection_highlighted() {
return Ok(true);
}
}
Expand Down Expand Up @@ -558,10 +555,7 @@ impl CommitList {
self.selection.saturating_sub(self.items.index_offset())
}

pub fn select_entry(&mut self, position: usize) {
self.selection = position;
}

///
pub fn checkout(&mut self) {
if let Some(commit_hash) =
self.selected_entry().map(|entry| entry.id)
Expand All @@ -574,6 +568,7 @@ impl CommitList {
}
}

///
pub fn set_local_branches(
&mut self,
local_branches: Vec<BranchInfo>,
Expand All @@ -588,6 +583,7 @@ impl CommitList {
}
}

///
pub fn set_remote_branches(
&mut self,
remote_branches: Vec<BranchInfo>,
Expand Down Expand Up @@ -707,6 +703,18 @@ impl CommitList {
self.select_next_highlight();
self.fetch_commits();
}

///
pub fn select_commit(&mut self, id: CommitId) -> Result<()> {
let position = self.commits.iter().position(|&x| x == id);

if let Some(position) = position {
self.selection = position;
Ok(())
} else {
anyhow::bail!("Could not select commit. It might not be loaded yet or it might be on a different branch.");
}
}
}

impl DrawableComponent for CommitList {
Expand Down
2 changes: 0 additions & 2 deletions src/components/utils/logitems.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,6 @@ impl ItemBatch {
commits: Vec<CommitInfo>,
highlighted: &Option<HashSet<CommitId>>,
) {
log::debug!("highlighted: {:?}", highlighted);

self.items.clear();
self.items.extend(commits.into_iter().map(|c| {
let id = c.id;
Expand Down
47 changes: 14 additions & 33 deletions src/tabs/revlog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use std::{collections::HashSet, rc::Rc, time::Duration};
use sync::CommitTags;

struct LogSearchResult {
commits: Vec<CommitId>,
commits: usize,
options: LogFilterSearchOptions,
duration: Duration,
}
Expand Down Expand Up @@ -134,11 +134,7 @@ impl Revlog {
self.list.clear();
}

if self.update_search_state()? {
if let Some(search) = self.search_result_set() {
self.list.set_highlighting(Some(search));
}
}
self.update_search_state()?;

self.list
.refresh_extend_data(self.git_log.extract_items()?);
Expand Down Expand Up @@ -221,16 +217,9 @@ impl Revlog {
})
}

///
pub fn select_commit(&mut self, id: CommitId) -> Result<()> {
let position = self.git_log.position(id)?;

if let Some(position) = position {
self.list.select_entry(position);

Ok(())
} else {
anyhow::bail!("Could not select commit in revlog. It might not be loaded yet or it might be on a different branch.");
}
self.list.select_commit(id)
}

fn revert_commit(&self) -> Result<()> {
Expand Down Expand Up @@ -273,7 +262,7 @@ impl Revlog {
Some(filter),
);

async_find.fetch()?;
assert_eq!(async_find.fetch()?, FetchStatus::Started);

self.search = LogSearch::Searching(async_find, options);

Expand All @@ -283,32 +272,24 @@ impl Revlog {
Ok(())
}

fn search_result_set(&self) -> Option<HashSet<CommitId>> {
if let LogSearch::Results(results) = &self.search {
Some(
results
.commits
.iter()
.map(CommitId::clone)
.collect::<HashSet<_>>(),
)
} else {
None
}
}

fn update_search_state(&mut self) -> Result<bool> {
let changes = match &self.search {
LogSearch::Off | LogSearch::Results(_) => false,
LogSearch::Searching(search, options) => {
if search.is_pending() {
false
} else {
let results = search.get_items()?;
let results = search.extract_items()?;
let commits = results.len();
let duration = search.get_last_duration()?;

self.list.set_highlighting(Some(
results.into_iter().collect::<HashSet<_>>(),
));

self.search =
LogSearch::Results(LogSearchResult {
commits: results,
commits,
options: options.clone(),
duration,
});
Expand Down Expand Up @@ -336,7 +317,7 @@ impl Revlog {
format!(
"'{}' (hits: {}) (duration: {:?})",
results.options.search_pattern.clone(),
results.commits.len(),
results.commits,
results.duration,
)
}
Expand Down

0 comments on commit 1fca82c

Please sign in to comment.