Skip to content

support bare repos #1028

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Dec 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ The way this works got changed and simplified ([See docs](https://github.com/ext
- dedicated fuzzy finder up/down keys to allow vim overrides ([#993](https://github.com/extrawurst/gitui/pull/993))
- pull will also download tags ([#1013](https://github.com/extrawurst/gitui/pull/1013))
- allow editing file from filetree ([#989](https://github.com/extrawurst/gitui/pull/989))
- support bare repos (new `workdir` argument) ([#1026](https://github.com/extrawurst/gitui/pull/1026))

### Fixed
- honor options (for untracked files) in `stage_all` command ([#933](https://github.com/extrawurst/gitui/issues/933))
Expand Down
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 <some_path>
# ARGS=-l -d ~/code/git-bare-test.git -w ~/code/git-bare-test

profile:
cargo run --features=timing,pprof -- ${ARGS}
Expand Down
16 changes: 12 additions & 4 deletions asyncgit/src/blame.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::{
error::Result,
hash,
sync::{self, FileBlame},
AsyncGitNotification, CWD,
sync::{self, FileBlame, RepoPath},
AsyncGitNotification,
};
use crossbeam_channel::Sender;
use std::{
Expand Down Expand Up @@ -34,12 +34,17 @@ pub struct AsyncBlame {
last: Arc<Mutex<Option<LastResult<BlameParams, FileBlame>>>>,
sender: Sender<AsyncGitNotification>,
pending: Arc<AtomicUsize>,
repo: RepoPath,
}

impl AsyncBlame {
///
pub fn new(sender: &Sender<AsyncGitNotification>) -> Self {
pub fn new(
repo: RepoPath,
sender: &Sender<AsyncGitNotification>,
) -> Self {
Self {
repo,
current: Arc::new(Mutex::new(Request(0, None))),
last: Arc::new(Mutex::new(None)),
sender: sender.clone(),
Expand Down Expand Up @@ -96,11 +101,13 @@ impl AsyncBlame {
let arc_last = Arc::clone(&self.last);
let sender = self.sender.clone();
let arc_pending = Arc::clone(&self.pending);
let repo = self.repo.clone();

self.pending.fetch_add(1, Ordering::Relaxed);

rayon_core::spawn(move || {
let notify = Self::get_blame_helper(
&repo,
params,
&arc_last,
&arc_current,
Expand Down Expand Up @@ -130,6 +137,7 @@ impl AsyncBlame {
}

fn get_blame_helper(
repo_path: &RepoPath,
params: BlameParams,
arc_last: &Arc<
Mutex<Option<LastResult<BlameParams, FileBlame>>>,
Expand All @@ -138,7 +146,7 @@ impl AsyncBlame {
hash: u64,
) -> Result<bool> {
let file_blame =
sync::blame::blame_file(CWD, &params.file_path)?;
sync::blame::blame_file(repo_path, &params.file_path)?;

let mut notify = false;
{
Expand Down
13 changes: 6 additions & 7 deletions asyncgit/src/cached/branchname.rs
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
use crate::{
error::Result,
sync::{self, branch::get_branch_name},
sync::{self, branch::get_branch_name, RepoPathRef},
};
use sync::Head;

///
pub struct BranchName {
last_result: Option<(Head, String)>,
repo_path: String,
repo: RepoPathRef,
}

impl BranchName {
///
pub fn new(path: &str) -> Self {
pub const fn new(repo: RepoPathRef) -> Self {
Self {
repo_path: path.to_string(),
repo,
last_result: None,
}
}

///
pub fn lookup(&mut self) -> Result<String> {
let current_head =
sync::get_head_tuple(self.repo_path.as_str())?;
let current_head = sync::get_head_tuple(&self.repo.borrow())?;

if let Some((last_head, branch_name)) =
self.last_result.as_ref()
Expand All @@ -41,7 +40,7 @@ impl BranchName {
}

fn fetch(&mut self, head: Head) -> Result<String> {
let name = get_branch_name(self.repo_path.as_str())?;
let name = get_branch_name(&self.repo.borrow())?;
self.last_result = Some((head, name.clone()));
Ok(name)
}
Expand Down
22 changes: 16 additions & 6 deletions asyncgit/src/commit_files.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{
error::Result,
sync::{self, CommitId},
AsyncGitNotification, StatusItem, CWD,
sync::{self, CommitId, RepoPath},
AsyncGitNotification, StatusItem,
};
use crossbeam_channel::Sender;
use std::sync::{
Expand Down Expand Up @@ -42,12 +42,17 @@ pub struct AsyncCommitFiles {
Arc<Mutex<Option<Request<CommitFilesParams, ResultType>>>>,
sender: Sender<AsyncGitNotification>,
pending: Arc<AtomicUsize>,
repo: RepoPath,
}

impl AsyncCommitFiles {
///
pub fn new(sender: &Sender<AsyncGitNotification>) -> Self {
pub fn new(
repo: RepoPath,
sender: &Sender<AsyncGitNotification>,
) -> Self {
Self {
repo,
current: Arc::new(Mutex::new(None)),
sender: sender.clone(),
pending: Arc::new(AtomicUsize::new(0)),
Expand Down Expand Up @@ -89,11 +94,12 @@ impl AsyncCommitFiles {
let arc_current = Arc::clone(&self.current);
let sender = self.sender.clone();
let arc_pending = Arc::clone(&self.pending);
let repo = self.repo.clone();

self.pending.fetch_add(1, Ordering::Relaxed);

rayon_core::spawn(move || {
Self::fetch_helper(params, &arc_current)
Self::fetch_helper(&repo, params, &arc_current)
.expect("failed to fetch");

arc_pending.fetch_sub(1, Ordering::Relaxed);
Expand All @@ -107,13 +113,17 @@ impl AsyncCommitFiles {
}

fn fetch_helper(
repo_path: &RepoPath,
params: CommitFilesParams,
arc_current: &Arc<
Mutex<Option<Request<CommitFilesParams, ResultType>>>,
>,
) -> Result<()> {
let res =
sync::get_commit_files(CWD, params.id, params.other)?;
let res = sync::get_commit_files(
repo_path,
params.id,
params.other,
)?;

log::trace!("get_commit_files: {:?} ({})", params, res.len());

Expand Down
22 changes: 15 additions & 7 deletions asyncgit/src/diff.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::{
error::Result,
hash,
sync::{self, diff::DiffOptions, CommitId},
AsyncGitNotification, FileDiff, CWD,
sync::{self, diff::DiffOptions, CommitId, RepoPath},
AsyncGitNotification, FileDiff,
};
use crossbeam_channel::Sender;
use std::{
Expand Down Expand Up @@ -51,12 +51,17 @@ pub struct AsyncDiff {
last: Arc<Mutex<Option<LastResult<DiffParams, FileDiff>>>>,
sender: Sender<AsyncGitNotification>,
pending: Arc<AtomicUsize>,
repo: RepoPath,
}

impl AsyncDiff {
///
pub fn new(sender: &Sender<AsyncGitNotification>) -> Self {
pub fn new(
repo: RepoPath,
sender: &Sender<AsyncGitNotification>,
) -> Self {
Self {
repo,
current: Arc::new(Mutex::new(Request(0, None))),
last: Arc::new(Mutex::new(None)),
sender: sender.clone(),
Expand Down Expand Up @@ -109,11 +114,13 @@ impl AsyncDiff {
let arc_last = Arc::clone(&self.last);
let sender = self.sender.clone();
let arc_pending = Arc::clone(&self.pending);
let repo = self.repo.clone();

self.pending.fetch_add(1, Ordering::Relaxed);

rayon_core::spawn(move || {
let notify = Self::get_diff_helper(
&repo,
params,
&arc_last,
&arc_current,
Expand Down Expand Up @@ -143,6 +150,7 @@ impl AsyncDiff {
}

fn get_diff_helper(
repo_path: &RepoPath,
params: DiffParams,
arc_last: &Arc<
Mutex<Option<LastResult<DiffParams, FileDiff>>>,
Expand All @@ -152,24 +160,24 @@ impl AsyncDiff {
) -> Result<bool> {
let res = match params.diff_type {
DiffType::Stage => sync::diff::get_diff(
CWD,
repo_path,
&params.path,
true,
Some(params.options),
)?,
DiffType::WorkDir => sync::diff::get_diff(
CWD,
repo_path,
&params.path,
false,
Some(params.options),
)?,
DiffType::Commit(id) => sync::diff::get_diff_commit(
CWD,
repo_path,
id,
params.path.clone(),
)?,
DiffType::Commits(ids) => sync::diff::get_diff_commits(
CWD,
repo_path,
ids,
params.path.clone(),
)?,
Expand Down
16 changes: 11 additions & 5 deletions asyncgit/src/fetch_job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
use crate::{
asyncjob::{AsyncJob, RunParams},
error::Result,
sync::cred::BasicAuthCredential,
sync::remotes::fetch_all,
AsyncGitNotification, ProgressPercent, CWD,
sync::{cred::BasicAuthCredential, RepoPath},
AsyncGitNotification, ProgressPercent,
};

use std::sync::{Arc, Mutex};
Expand All @@ -16,18 +16,21 @@ enum JobState {
}

///
#[derive(Clone, Default)]
#[derive(Clone)]
pub struct AsyncFetchJob {
state: Arc<Mutex<Option<JobState>>>,
repo: RepoPath,
}

///
impl AsyncFetchJob {
///
pub fn new(
repo: RepoPath,
basic_credential: Option<BasicAuthCredential>,
) -> Self {
Self {
repo,
state: Arc::new(Mutex::new(Some(JobState::Request(
basic_credential,
)))),
Expand Down Expand Up @@ -61,8 +64,11 @@ impl AsyncJob for AsyncFetchJob {
*state = state.take().map(|state| match state {
JobState::Request(basic_credentials) => {
//TODO: support progress
let result =
fetch_all(CWD, &basic_credentials, &None);
let result = fetch_all(
&self.repo,
&basic_credentials,
&None,
);

JobState::Response(result)
}
Expand Down
3 changes: 0 additions & 3 deletions asyncgit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,6 @@ pub enum AsyncGitNotification {
Fetch,
}

/// current working directory `./`
pub static CWD: &str = "./";

/// helper function to calculate the hash of an arbitrary type that implements the `Hash` trait
pub fn hash<T: Hash + ?Sized>(v: &T) -> u64 {
let mut hasher = DefaultHasher::new();
Expand Down
13 changes: 10 additions & 3 deletions asyncgit/src/pull.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ use crate::{
sync::{
cred::BasicAuthCredential,
remotes::{fetch, push::ProgressNotification},
RepoPath,
},
AsyncGitNotification, RemoteProgress, CWD,
AsyncGitNotification, RemoteProgress,
};
use crossbeam_channel::{unbounded, Sender};
use std::{
Expand Down Expand Up @@ -33,12 +34,17 @@ pub struct AsyncPull {
last_result: Arc<Mutex<Option<(usize, String)>>>,
progress: Arc<Mutex<Option<ProgressNotification>>>,
sender: Sender<AsyncGitNotification>,
repo: RepoPath,
}

impl AsyncPull {
///
pub fn new(sender: &Sender<AsyncGitNotification>) -> Self {
pub fn new(
repo: RepoPath,
sender: &Sender<AsyncGitNotification>,
) -> Self {
Self {
repo,
state: Arc::new(Mutex::new(None)),
last_result: Arc::new(Mutex::new(None)),
progress: Arc::new(Mutex::new(None)),
Expand Down Expand Up @@ -79,6 +85,7 @@ impl AsyncPull {
let arc_res = Arc::clone(&self.last_result);
let arc_progress = Arc::clone(&self.progress);
let sender = self.sender.clone();
let repo = self.repo.clone();

thread::spawn(move || {
let (progress_sender, receiver) = unbounded();
Expand All @@ -91,7 +98,7 @@ impl AsyncPull {
);

let res = fetch(
CWD,
&repo,
&params.branch,
params.basic_credential,
Some(progress_sender.clone()),
Expand Down
Loading