ok/jj
1
0
Fork 0
forked from mirrors/jj

git: inline export_changes()

The function doesn't do much at all now and there's a single caller,
so let's inline it.

I tried to clean up the code a bit futher so it wouldn't even create
the `old_view`, but it was harder than I had hoped. I might get back
to it later.
This commit is contained in:
Martin von Zweigbergk 2022-12-02 23:04:20 -08:00 committed by Martin von Zweigbergk
parent 8a440d8042
commit b3fe52305a

View file

@ -172,14 +172,20 @@ pub enum GitExportError {
InternalGitError(#[from] git2::Error),
}
/// Reflect changes between two Jujutsu repo views in the underlying Git repo.
/// Returns a list of names of branches that failed to export.
/// Reflect changes made in the Jujutsu repo compared to our current view of the
/// Git repo in `mut_repo.view().git_refs()`. Returns a list of names of
/// branches that failed to export.
// TODO: Also indicate why we failed to export these branches
fn export_changes(
pub fn export_refs(
mut_repo: &mut MutableRepo,
old_view: &View,
git_repo: &git2::Repository,
) -> Result<Vec<String>, GitExportError> {
let mut old_view = View::new(op_store::View::default());
for (git_ref, git_ref_target) in mut_repo.view().git_refs() {
if let Some(branch_name) = git_ref.strip_prefix("refs/heads/") {
old_view.set_local_branch(branch_name.to_string(), git_ref_target.clone());
}
}
let new_view = mut_repo.view();
let old_branches: HashSet<_> = old_view.branches().keys().cloned().collect();
let new_branches: HashSet<_> = new_view.branches().keys().cloned().collect();
@ -304,21 +310,6 @@ fn export_changes(
Ok(failed_branches)
}
/// Reflect changes made in the Jujutsu repo compared to our current view of the
/// Git repo in `mut_repo.view().git_refs()`.
pub fn export_refs(
mut_repo: &mut MutableRepo,
git_repo: &git2::Repository,
) -> Result<Vec<String>, GitExportError> {
let mut last_export_view = View::new(op_store::View::default());
for (git_ref, git_ref_target) in mut_repo.view().git_refs() {
if let Some(branch_name) = git_ref.strip_prefix("refs/heads/") {
last_export_view.set_local_branch(branch_name.to_string(), git_ref_target.clone());
}
}
export_changes(mut_repo, &last_export_view, git_repo)
}
#[derive(Error, Debug, PartialEq)]
pub enum GitFetchError {
#[error("No git remote named '{0}'")]