Skip to content
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

git sync while on non-detached main causes a git checkout main for every stack #1155

Open
mlcui-corp opened this issue Dec 18, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@mlcui-corp
Copy link
Collaborator

Description of the bug

This causes git syncs to be significantly slower, especially if git checkout main takes a while. This isn't usually the case, unless you're in a huge monorepo.

Good (checked out at a non-main commit, or detached at main):
Attempting rebase in-memory...
[1/2] Committed as: REDACTED
[2/2] Committed as: REDACTED
branchless: processing 2 rewritten commits
In-memory rebase succeeded.
Attempting rebase in-memory...
[1/1] Committed as: REDACTED
branchless: processing 1 rewritten commit
In-memory rebase succeeded.
Attempting rebase in-memory...
[1/1] Committed as: REDACTED
branchless: processing 1 rewritten commit
In-memory rebase succeeded.
Attempting rebase in-memory...
[1/1] Committed as: REDACTED
branchless: processing 1 rewritten commit
In-memory rebase succeeded.
Attempting rebase in-memory...
[1/1] Committed as: REDACTED
branchless: processing 1 rewritten commit
In-memory rebase succeeded.
Attempting rebase in-memory...
[1/1] Committed as: REDACTED
branchless: processing 1 rewritten commit
In-memory rebase succeeded.
Attempting rebase in-memory...
[1/1] Committed as: REDACTED
branchless: processing 1 rewritten commit
In-memory rebase succeeded.
Attempting rebase in-memory...
[1/3] Committed as: REDACTED
[2/3] Committed as: REDACTED
[3/3] Committed as: REDACTED
branchless: processing 3 rewritten commits
In-memory rebase succeeded.
Attempting rebase in-memory...
[1/1] Committed as: REDACTED
branchless: processing 1 rewritten commit
In-memory rebase succeeded.
Attempting rebase in-memory...
[1/3] Committed as: REDACTED
[2/3] Committed as: REDACTED
[3/3] Committed as: REDACTED
branchless: processing 3 rewritten commits
In-memory rebase succeeded.
Attempting rebase in-memory...
Synced REDACTED...
Bad (checked out non-detached main):
Attempting rebase in-memory...
[1/2] Committed as: REDACTED
[2/2] Committed as: REDACTED
branchless: processing 2 rewritten commits
branchless: creating working copy snapshot
branchless: running command: git checkout main
Switched to branch 'main'
Your branch is up to date with 'origin/main'.
branchless: processing checkout
In-memory rebase succeeded.
Attempting rebase in-memory...
[1/1] Committed as: REDACTED
branchless: processing 1 rewritten commit
branchless: creating working copy snapshot
branchless: running command: git checkout main
Switched to branch 'main'
Your branch is up to date with 'origin/main'.
branchless: processing checkout
In-memory rebase succeeded.
Attempting rebase in-memory...
[1/1] Committed as: REDACTED
branchless: processing 1 rewritten commit
branchless: creating working copy snapshot
branchless: running command: git checkout main
Switched to branch 'main'
Your branch is up to date with 'origin/main'.
branchless: processing checkout
In-memory rebase succeeded.
Attempting rebase in-memory...
[1/1] Committed as: REDACTED
branchless: processing 1 rewritten commit
branchless: creating working copy snapshot
branchless: running command: git checkout main
Switched to branch 'main'
Your branch is up to date with 'origin/main'.
branchless: processing checkout
In-memory rebase succeeded.
Attempting rebase in-memory...
[1/1] Committed as: REDACTED
branchless: processing 1 rewritten commit
branchless: creating working copy snapshot
branchless: running command: git checkout main
Switched to branch 'main'
Your branch is up to date with 'origin/main'.
branchless: processing checkout
In-memory rebase succeeded.
Attempting rebase in-memory...
[1/1] Committed as: REDACTED
branchless: processing 1 rewritten commit
branchless: creating working copy snapshot
branchless: running command: git checkout main
Switched to branch 'main'
Your branch is up to date with 'origin/main'.
branchless: processing checkout
In-memory rebase succeeded.
Attempting rebase in-memory...
[1/1] Committed as: REDACTED
branchless: processing 1 rewritten commit
branchless: creating working copy snapshot
branchless: running command: git checkout main
Switched to branch 'main'
Your branch is up to date with 'origin/main'.
branchless: processing checkout
In-memory rebase succeeded.
Attempting rebase in-memory...
[1/3] Committed as: REDACTED
[2/3] Committed as: REDACTED
[3/3] Committed as: REDACTED
branchless: processing 3 rewritten commits
branchless: creating working copy snapshot
branchless: running command: git checkout main
Switched to branch 'main'
Your branch is up to date with 'origin/main'.
branchless: processing checkout
In-memory rebase succeeded.
Attempting rebase in-memory...
[1/1] Committed as: REDACTED
branchless: processing 1 rewritten commit
branchless: creating working copy snapshot
branchless: running command: git checkout main
Switched to branch 'main'
Your branch is up to date with 'origin/main'.
branchless: processing checkout
In-memory rebase succeeded.
Attempting rebase in-memory...
[1/3] Committed as: REDACTED
[2/3] Committed as: REDACTED
[3/3] Committed as: REDACTED
branchless: processing 3 rewritten commits
branchless: creating working copy snapshot
branchless: running command: git checkout main
Switched to branch 'main'
Your branch is up to date with 'origin/main'.
branchless: processing checkout
In-memory rebase succeeded.
Attempting rebase in-memory...
Synced REDACTED...

I also see working copy snapshots being created - not too sure if that's related.

To work around this, git switch --detach & git sync instead.

Expected behavior

git sync on main is fast in monorepos.

Actual behavior

git sync on main is slow in monorepos.

Version of rustc

No response

Automated bug report

No response

Version of git-branchless

git-branchless-opts 0.7.0 (~/.cargo/git/checkouts shows fbd9585)

Version of git

No response

@mlcui-corp mlcui-corp added the bug Something isn't working label Dec 18, 2023
@mlcui-corp
Copy link
Collaborator Author

This occurs on 35ae2b3 too.

@arxanas
Copy link
Owner

arxanas commented Dec 28, 2023

Maybe it's due to this:

repo.detach_head(&head_info)?;
}
move_branches(effects, git_run_info, repo, *event_tx_id, rewritten_oids)?;
// Call the `post-rewrite` hook only after moving branches so that we don't
// produce a spurious abandoned-branch warning.
#[allow(clippy::format_collect)]
let post_rewrite_stdin: String = rewritten_oids
.iter()
.map(|(old_oid, new_oid)| format!("{old_oid} {new_oid}\n"))
.collect();
let post_rewrite_stdin = BString::from(post_rewrite_stdin);
git_run_info.run_hook(
effects,
repo,
"post-rewrite",
*event_tx_id,
&["rebase"],
Some(post_rewrite_stdin),
)?;
let exit_code = check_out_updated_head(

We detach HEAD before moving branches and then check HEAD back out, but that's inefficient in this case. I'm not sure what the best solution is. There might be something better we can do to preserve the index state, or otherwise we could simply add a fast path in check_out_updated_head for the situation that we want to switch to a branch that points to the current commit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants