Skip to content

Commit c82950b

Browse files
committed
cleanup
1 parent 719aacc commit c82950b

3 files changed

Lines changed: 43 additions & 31 deletions

File tree

src/git.rs

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
use std::process::{Command, ExitStatus};
2-
use std::time::Instant;
1+
use std::{
2+
process::{Command, ExitStatus},
3+
time::Instant,
4+
};
35

46
use anyhow::{Context, Result, anyhow, bail};
57

6-
use crate::git2_ops::GitRepo;
7-
use crate::stats::record_git_command;
8+
use crate::{git2_ops::GitRepo, stats::record_git_command};
89

910
pub const DEFAULT_REMOTE: &str = "origin";
1011

@@ -150,10 +151,10 @@ pub(crate) fn git_branch_status(
150151
let exists = git_branch_exists(repo, branch);
151152
let parent_branch = match parent_branch {
152153
Some(parent_branch) => parent_branch.to_string(),
153-
None => git_remote_main(repo, DEFAULT_REMOTE)?,
154+
None => repo.remote_main(DEFAULT_REMOTE)?,
154155
};
155156
let is_descendent = exists && is_ancestor(repo, &parent_branch, branch)?;
156-
let upstream_symbolic_name = git_get_upstream(repo, branch);
157+
let upstream_symbolic_name = repo.get_upstream(branch);
157158
let upstream_synced = upstream_symbolic_name
158159
.as_ref()
159160
.is_some_and(|upstream| shas_match(repo, upstream, branch));
@@ -214,8 +215,8 @@ pub(crate) struct GitTrunk {
214215
pub(crate) main_branch: String,
215216
}
216217

217-
pub(crate) fn git_trunk(repo: &GitRepo) -> Result<GitTrunk> {
218-
let remote_main = git_remote_main(repo, DEFAULT_REMOTE)?;
218+
pub(crate) fn git_trunk(git_repo: &GitRepo) -> Result<GitTrunk> {
219+
let remote_main = git_repo.remote_main(DEFAULT_REMOTE)?;
219220
let main_branch = after_text(&remote_main, format!("{DEFAULT_REMOTE}/"))
220221
.ok_or(anyhow!("no branch?"))?
221222
.to_string();
@@ -224,12 +225,3 @@ pub(crate) fn git_trunk(repo: &GitRepo) -> Result<GitTrunk> {
224225
main_branch,
225226
})
226227
}
227-
228-
/// Returns a string of the form "origin/main".
229-
pub(crate) fn git_remote_main(repo: &GitRepo, remote: &str) -> Result<String> {
230-
repo.remote_main(remote)
231-
}
232-
233-
pub(crate) fn git_get_upstream(repo: &GitRepo, branch: &str) -> Option<String> {
234-
repo.get_upstream(branch)
235-
}

src/main.rs

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ use git::{
1212
git_checkout_main,
1313
git_diff_stats,
1414
git_fetch,
15-
git_get_upstream,
16-
git_remote_main,
1715
git_sha,
1816
is_ancestor,
1917
run_git_status,
@@ -182,7 +180,7 @@ fn inner_main() -> Result<()> {
182180

183181
let run_version = format!("{}", chrono::Utc::now().timestamp());
184182
let current_branch = git.current_branch()?;
185-
let current_upstream = git_get_upstream(&git, "");
183+
let current_upstream = git.get_upstream("");
186184
tracing::debug!(run_version, current_branch, current_upstream);
187185

188186
match args.command {
@@ -310,12 +308,14 @@ fn recur_tree(
310308
parent_branch: Option<&str>,
311309
verbose: bool,
312310
) -> Result<()> {
313-
let Ok(branch_status) = git_branch_status(git, parent_branch, &branch.name).with_context(|| {
314-
format!(
315-
"attempting to fetch the branch status of {}",
316-
branch.name.red()
317-
)
318-
}) else {
311+
let Ok(branch_status) =
312+
git_branch_status(git, parent_branch, &branch.name).with_context(|| {
313+
format!(
314+
"attempting to fetch the branch status of {}",
315+
branch.name.red()
316+
)
317+
})
318+
else {
319319
tracing::warn!("Branch {} does not exist", branch.name);
320320
return Ok(());
321321
};
@@ -499,6 +499,7 @@ fn status(
499499
Ok(())
500500
}
501501

502+
#[allow(clippy::too_many_arguments)]
502503
fn restack(
503504
git: &GitRepo,
504505
mut state: State,
@@ -534,7 +535,13 @@ fn restack(
534535
branch.name,
535536
parent
536537
);
537-
if push && !shas_match(git, &format!("{DEFAULT_REMOTE}/{}", branch.name), &branch.name) {
538+
if push
539+
&& !shas_match(
540+
git,
541+
&format!("{DEFAULT_REMOTE}/{}", branch.name),
542+
&branch.name,
543+
)
544+
{
538545
run_git(&[
539546
"push",
540547
match branch.stack_method {

src/state.rs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ use crate::{
1818
GitTrunk,
1919
after_text,
2020
git_branch_exists,
21-
git_remote_main,
2221
git_sha,
2322
git_trunk,
2423
is_ancestor,
@@ -258,7 +257,11 @@ impl State {
258257

259258
/// Auto-cleanup missing branches silently during status display.
260259
/// Returns true if any branches were cleaned up.
261-
pub(crate) fn auto_cleanup_missing_branches(&mut self, git: &GitRepo, repo: &str) -> Result<bool> {
260+
pub(crate) fn auto_cleanup_missing_branches(
261+
&mut self,
262+
git: &GitRepo,
263+
repo: &str,
264+
) -> Result<bool> {
262265
let Some(tree) = self.trees.get_mut(repo) else {
263266
return Ok(false);
264267
};
@@ -397,7 +400,12 @@ impl State {
397400
let mut removed_branches = Vec::new();
398401
let mut remounted_branches = Vec::new();
399402

400-
cleanup_tree_recursive(&repo_git, tree, &mut removed_branches, &mut remounted_branches);
403+
cleanup_tree_recursive(
404+
&repo_git,
405+
tree,
406+
&mut removed_branches,
407+
&mut remounted_branches,
408+
);
401409

402410
std::env::set_current_dir(original_dir)?;
403411

@@ -642,7 +650,12 @@ impl State {
642650
/// Try to auto-mount the current branch if it's not in the tree.
643651
/// Returns Ok(true) if the branch was auto-mounted, Ok(false) if it was already in the tree,
644652
/// or Err if auto-mount failed.
645-
pub(crate) fn try_auto_mount(&mut self, git: &GitRepo, repo: &str, branch_name: &str) -> Result<bool> {
653+
pub(crate) fn try_auto_mount(
654+
&mut self,
655+
git: &GitRepo,
656+
repo: &str,
657+
branch_name: &str,
658+
) -> Result<bool> {
646659
// Ensure the tree exists for this repo
647660
self.ensure_trunk(git, repo)?;
648661

0 commit comments

Comments
 (0)