Skip to content

Commit 006cdd6

Browse files
author
Stephan Dilly
authored
support bare repos (gitui-org#1028)
1 parent ecabee0 commit 006cdd6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+1506
-801
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ The way this works got changed and simplified ([See docs](https://github.com/ext
3030
- dedicated fuzzy finder up/down keys to allow vim overrides ([#993](https://github.com/extrawurst/gitui/pull/993))
3131
- pull will also download tags ([#1013](https://github.com/extrawurst/gitui/pull/1013))
3232
- allow editing file from filetree ([#989](https://github.com/extrawurst/gitui/pull/989))
33+
- support bare repos (new `workdir` argument) ([#1026](https://github.com/extrawurst/gitui/pull/1026))
3334

3435
### Fixed
3536
- honor options (for untracked files) in `stage_all` command ([#933](https://github.com/extrawurst/gitui/issues/933))

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 <some_path>
5+
# ARGS=-l -d ~/code/git-bare-test.git -w ~/code/git-bare-test
66

77
profile:
88
cargo run --features=timing,pprof -- ${ARGS}

asyncgit/src/blame.rs

+12-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use crate::{
22
error::Result,
33
hash,
4-
sync::{self, FileBlame},
5-
AsyncGitNotification, CWD,
4+
sync::{self, FileBlame, RepoPath},
5+
AsyncGitNotification,
66
};
77
use crossbeam_channel::Sender;
88
use std::{
@@ -34,12 +34,17 @@ pub struct AsyncBlame {
3434
last: Arc<Mutex<Option<LastResult<BlameParams, FileBlame>>>>,
3535
sender: Sender<AsyncGitNotification>,
3636
pending: Arc<AtomicUsize>,
37+
repo: RepoPath,
3738
}
3839

3940
impl AsyncBlame {
4041
///
41-
pub fn new(sender: &Sender<AsyncGitNotification>) -> Self {
42+
pub fn new(
43+
repo: RepoPath,
44+
sender: &Sender<AsyncGitNotification>,
45+
) -> Self {
4246
Self {
47+
repo,
4348
current: Arc::new(Mutex::new(Request(0, None))),
4449
last: Arc::new(Mutex::new(None)),
4550
sender: sender.clone(),
@@ -96,11 +101,13 @@ impl AsyncBlame {
96101
let arc_last = Arc::clone(&self.last);
97102
let sender = self.sender.clone();
98103
let arc_pending = Arc::clone(&self.pending);
104+
let repo = self.repo.clone();
99105

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

102108
rayon_core::spawn(move || {
103109
let notify = Self::get_blame_helper(
110+
&repo,
104111
params,
105112
&arc_last,
106113
&arc_current,
@@ -130,6 +137,7 @@ impl AsyncBlame {
130137
}
131138

132139
fn get_blame_helper(
140+
repo_path: &RepoPath,
133141
params: BlameParams,
134142
arc_last: &Arc<
135143
Mutex<Option<LastResult<BlameParams, FileBlame>>>,
@@ -138,7 +146,7 @@ impl AsyncBlame {
138146
hash: u64,
139147
) -> Result<bool> {
140148
let file_blame =
141-
sync::blame::blame_file(CWD, &params.file_path)?;
149+
sync::blame::blame_file(repo_path, &params.file_path)?;
142150

143151
let mut notify = false;
144152
{

asyncgit/src/cached/branchname.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,27 @@
11
use crate::{
22
error::Result,
3-
sync::{self, branch::get_branch_name},
3+
sync::{self, branch::get_branch_name, RepoPathRef},
44
};
55
use sync::Head;
66

77
///
88
pub struct BranchName {
99
last_result: Option<(Head, String)>,
10-
repo_path: String,
10+
repo: RepoPathRef,
1111
}
1212

1313
impl BranchName {
1414
///
15-
pub fn new(path: &str) -> Self {
15+
pub const fn new(repo: RepoPathRef) -> Self {
1616
Self {
17-
repo_path: path.to_string(),
17+
repo,
1818
last_result: None,
1919
}
2020
}
2121

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

2726
if let Some((last_head, branch_name)) =
2827
self.last_result.as_ref()
@@ -41,7 +40,7 @@ impl BranchName {
4140
}
4241

4342
fn fetch(&mut self, head: Head) -> Result<String> {
44-
let name = get_branch_name(self.repo_path.as_str())?;
43+
let name = get_branch_name(&self.repo.borrow())?;
4544
self.last_result = Some((head, name.clone()));
4645
Ok(name)
4746
}

asyncgit/src/commit_files.rs

+16-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::{
22
error::Result,
3-
sync::{self, CommitId},
4-
AsyncGitNotification, StatusItem, CWD,
3+
sync::{self, CommitId, RepoPath},
4+
AsyncGitNotification, StatusItem,
55
};
66
use crossbeam_channel::Sender;
77
use std::sync::{
@@ -42,12 +42,17 @@ pub struct AsyncCommitFiles {
4242
Arc<Mutex<Option<Request<CommitFilesParams, ResultType>>>>,
4343
sender: Sender<AsyncGitNotification>,
4444
pending: Arc<AtomicUsize>,
45+
repo: RepoPath,
4546
}
4647

4748
impl AsyncCommitFiles {
4849
///
49-
pub fn new(sender: &Sender<AsyncGitNotification>) -> Self {
50+
pub fn new(
51+
repo: RepoPath,
52+
sender: &Sender<AsyncGitNotification>,
53+
) -> Self {
5054
Self {
55+
repo,
5156
current: Arc::new(Mutex::new(None)),
5257
sender: sender.clone(),
5358
pending: Arc::new(AtomicUsize::new(0)),
@@ -89,11 +94,12 @@ impl AsyncCommitFiles {
8994
let arc_current = Arc::clone(&self.current);
9095
let sender = self.sender.clone();
9196
let arc_pending = Arc::clone(&self.pending);
97+
let repo = self.repo.clone();
9298

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

95101
rayon_core::spawn(move || {
96-
Self::fetch_helper(params, &arc_current)
102+
Self::fetch_helper(&repo, params, &arc_current)
97103
.expect("failed to fetch");
98104

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

109115
fn fetch_helper(
116+
repo_path: &RepoPath,
110117
params: CommitFilesParams,
111118
arc_current: &Arc<
112119
Mutex<Option<Request<CommitFilesParams, ResultType>>>,
113120
>,
114121
) -> Result<()> {
115-
let res =
116-
sync::get_commit_files(CWD, params.id, params.other)?;
122+
let res = sync::get_commit_files(
123+
repo_path,
124+
params.id,
125+
params.other,
126+
)?;
117127

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

asyncgit/src/diff.rs

+15-7
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use crate::{
22
error::Result,
33
hash,
4-
sync::{self, diff::DiffOptions, CommitId},
5-
AsyncGitNotification, FileDiff, CWD,
4+
sync::{self, diff::DiffOptions, CommitId, RepoPath},
5+
AsyncGitNotification, FileDiff,
66
};
77
use crossbeam_channel::Sender;
88
use std::{
@@ -51,12 +51,17 @@ pub struct AsyncDiff {
5151
last: Arc<Mutex<Option<LastResult<DiffParams, FileDiff>>>>,
5252
sender: Sender<AsyncGitNotification>,
5353
pending: Arc<AtomicUsize>,
54+
repo: RepoPath,
5455
}
5556

5657
impl AsyncDiff {
5758
///
58-
pub fn new(sender: &Sender<AsyncGitNotification>) -> Self {
59+
pub fn new(
60+
repo: RepoPath,
61+
sender: &Sender<AsyncGitNotification>,
62+
) -> Self {
5963
Self {
64+
repo,
6065
current: Arc::new(Mutex::new(Request(0, None))),
6166
last: Arc::new(Mutex::new(None)),
6267
sender: sender.clone(),
@@ -109,11 +114,13 @@ impl AsyncDiff {
109114
let arc_last = Arc::clone(&self.last);
110115
let sender = self.sender.clone();
111116
let arc_pending = Arc::clone(&self.pending);
117+
let repo = self.repo.clone();
112118

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

115121
rayon_core::spawn(move || {
116122
let notify = Self::get_diff_helper(
123+
&repo,
117124
params,
118125
&arc_last,
119126
&arc_current,
@@ -143,6 +150,7 @@ impl AsyncDiff {
143150
}
144151

145152
fn get_diff_helper(
153+
repo_path: &RepoPath,
146154
params: DiffParams,
147155
arc_last: &Arc<
148156
Mutex<Option<LastResult<DiffParams, FileDiff>>>,
@@ -152,24 +160,24 @@ impl AsyncDiff {
152160
) -> Result<bool> {
153161
let res = match params.diff_type {
154162
DiffType::Stage => sync::diff::get_diff(
155-
CWD,
163+
repo_path,
156164
&params.path,
157165
true,
158166
Some(params.options),
159167
)?,
160168
DiffType::WorkDir => sync::diff::get_diff(
161-
CWD,
169+
repo_path,
162170
&params.path,
163171
false,
164172
Some(params.options),
165173
)?,
166174
DiffType::Commit(id) => sync::diff::get_diff_commit(
167-
CWD,
175+
repo_path,
168176
id,
169177
params.path.clone(),
170178
)?,
171179
DiffType::Commits(ids) => sync::diff::get_diff_commits(
172-
CWD,
180+
repo_path,
173181
ids,
174182
params.path.clone(),
175183
)?,

asyncgit/src/fetch_job.rs

+11-5
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
use crate::{
44
asyncjob::{AsyncJob, RunParams},
55
error::Result,
6-
sync::cred::BasicAuthCredential,
76
sync::remotes::fetch_all,
8-
AsyncGitNotification, ProgressPercent, CWD,
7+
sync::{cred::BasicAuthCredential, RepoPath},
8+
AsyncGitNotification, ProgressPercent,
99
};
1010

1111
use std::sync::{Arc, Mutex};
@@ -16,18 +16,21 @@ enum JobState {
1616
}
1717

1818
///
19-
#[derive(Clone, Default)]
19+
#[derive(Clone)]
2020
pub struct AsyncFetchJob {
2121
state: Arc<Mutex<Option<JobState>>>,
22+
repo: RepoPath,
2223
}
2324

2425
///
2526
impl AsyncFetchJob {
2627
///
2728
pub fn new(
29+
repo: RepoPath,
2830
basic_credential: Option<BasicAuthCredential>,
2931
) -> Self {
3032
Self {
33+
repo,
3134
state: Arc::new(Mutex::new(Some(JobState::Request(
3235
basic_credential,
3336
)))),
@@ -61,8 +64,11 @@ impl AsyncJob for AsyncFetchJob {
6164
*state = state.take().map(|state| match state {
6265
JobState::Request(basic_credentials) => {
6366
//TODO: support progress
64-
let result =
65-
fetch_all(CWD, &basic_credentials, &None);
67+
let result = fetch_all(
68+
&self.repo,
69+
&basic_credentials,
70+
&None,
71+
);
6672

6773
JobState::Response(result)
6874
}

asyncgit/src/lib.rs

-3
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,6 @@ pub enum AsyncGitNotification {
9494
Fetch,
9595
}
9696

97-
/// current working directory `./`
98-
pub static CWD: &str = "./";
99-
10097
/// helper function to calculate the hash of an arbitrary type that implements the `Hash` trait
10198
pub fn hash<T: Hash + ?Sized>(v: &T) -> u64 {
10299
let mut hasher = DefaultHasher::new();

asyncgit/src/pull.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ use crate::{
33
sync::{
44
cred::BasicAuthCredential,
55
remotes::{fetch, push::ProgressNotification},
6+
RepoPath,
67
},
7-
AsyncGitNotification, RemoteProgress, CWD,
8+
AsyncGitNotification, RemoteProgress,
89
};
910
use crossbeam_channel::{unbounded, Sender};
1011
use std::{
@@ -33,12 +34,17 @@ pub struct AsyncPull {
3334
last_result: Arc<Mutex<Option<(usize, String)>>>,
3435
progress: Arc<Mutex<Option<ProgressNotification>>>,
3536
sender: Sender<AsyncGitNotification>,
37+
repo: RepoPath,
3638
}
3739

3840
impl AsyncPull {
3941
///
40-
pub fn new(sender: &Sender<AsyncGitNotification>) -> Self {
42+
pub fn new(
43+
repo: RepoPath,
44+
sender: &Sender<AsyncGitNotification>,
45+
) -> Self {
4146
Self {
47+
repo,
4248
state: Arc::new(Mutex::new(None)),
4349
last_result: Arc::new(Mutex::new(None)),
4450
progress: Arc::new(Mutex::new(None)),
@@ -79,6 +85,7 @@ impl AsyncPull {
7985
let arc_res = Arc::clone(&self.last_result);
8086
let arc_progress = Arc::clone(&self.progress);
8187
let sender = self.sender.clone();
88+
let repo = self.repo.clone();
8289

8390
thread::spawn(move || {
8491
let (progress_sender, receiver) = unbounded();
@@ -91,7 +98,7 @@ impl AsyncPull {
9198
);
9299

93100
let res = fetch(
94-
CWD,
101+
&repo,
95102
&params.branch,
96103
params.basic_credential,
97104
Some(progress_sender.clone()),

0 commit comments

Comments
 (0)