From 2d44206472423f1abaa8ea403f884297806a9b94 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Mon, 23 Aug 2021 19:47:14 -0500 Subject: [PATCH 1/2] perf: Only backup when needed To reduce noise when browsing backups, let's only do it when we make a real change. Rather than detecting when a script will be a no-op, we are relying on the processing from the script leading to no permament changes. Its a bit simpler. As of right now though, we always do permament changes. --- src/bin/git-stack/stack.rs | 22 +++++++++++++--------- src/git/commands.rs | 4 ++++ 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/bin/git-stack/stack.rs b/src/bin/git-stack/stack.rs index d3cbd58..368bebe 100644 --- a/src/bin/git-stack/stack.rs +++ b/src/bin/git-stack/stack.rs @@ -253,20 +253,14 @@ pub fn stack(args: &crate::args::Args, colored_stdout: bool) -> proc_exit::ExitR } } - const BACKUP_NAME: &str = "git-stack"; let mut success = true; + let mut backed_up = false; + const BACKUP_NAME: &str = "git-stack"; if state.rebase { if state.repo.is_dirty() { return Err(proc_exit::Code::USAGE_ERR.with_message("Working tree is dirty, aborting")); } - let mut backups = git_stack::backup::Stack::new(BACKUP_NAME, &state.repo); - backups.capacity(state.backup_capacity); - let mut backup = git_stack::backup::Backup::from_repo(&state.repo) - .with_code(proc_exit::Code::FAILURE)?; - backup.insert_parent(&state.repo, &state.branches, &state.protected_branches); - backups.push(backup)?; - let head_branch = state .repo .head_branch() @@ -291,6 +285,16 @@ pub fn stack(args: &crate::args::Args, colored_stdout: bool) -> proc_exit::ExitR } } } + if executor.is_dirty() { + backed_up = true; + + let mut backups = git_stack::backup::Stack::new(BACKUP_NAME, &state.repo); + backups.capacity(state.backup_capacity); + let mut backup = git_stack::backup::Backup::from_repo(&state.repo) + .with_code(proc_exit::Code::FAILURE)?; + backup.insert_parent(&state.repo, &state.branches, &state.protected_branches); + backups.push(backup)?; + } executor .close(&mut state.repo, &head_branch.name) .with_code(proc_exit::Code::FAILURE)?; @@ -304,7 +308,7 @@ pub fn stack(args: &crate::args::Args, colored_stdout: bool) -> proc_exit::ExitR show(&state, colored_stdout).with_code(proc_exit::Code::FAILURE)?; - if state.rebase { + if backed_up { log::info!("To undo, run `git branch-backup pop {}", BACKUP_NAME); } diff --git a/src/git/commands.rs b/src/git/commands.rs index dd904ce..8a11d06 100644 --- a/src/git/commands.rs +++ b/src/git/commands.rs @@ -67,6 +67,10 @@ impl Executor { } } + pub fn is_dirty(&self) -> bool { + !self.branches.is_empty() || !self.delete_branches.is_empty() || self.detached + } + pub fn run_script<'s>( &mut self, repo: &mut dyn crate::git::Repo, From bc48aa8c3f403126dc3ee759435fca24ea5c54b0 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Mon, 23 Aug 2021 21:24:19 -0500 Subject: [PATCH 2/2] perf(git): Only recreate branches when needed This will help us better detect when we don't need to do backups because there will be fewer permament changes being made. --- src/git/commands.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/git/commands.rs b/src/git/commands.rs index 8a11d06..974fac0 100644 --- a/src/git/commands.rs +++ b/src/git/commands.rs @@ -156,8 +156,11 @@ impl Executor { } } Command::CreateBranch(name) => { - let branch_oid = self.head_oid; - self.branches.push((branch_oid, name.to_owned())); + let new_branch_oid = self.head_oid; + let old_branch = repo.find_local_branch(name); + if Some(new_branch_oid) != old_branch.map(|b| b.id) { + self.branches.push((new_branch_oid, name.to_owned())); + } } Command::DeleteBranch(name) => { self.delete_branches.push(name.to_owned()); pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy