mirror of
https://github.com/martinvonz/jj.git
synced 2025-02-08 21:48:08 +00:00
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:
parent
8a440d8042
commit
b3fe52305a
1 changed files with 10 additions and 19 deletions
|
@ -172,14 +172,20 @@ pub enum GitExportError {
|
||||||
InternalGitError(#[from] git2::Error),
|
InternalGitError(#[from] git2::Error),
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Reflect changes between two Jujutsu repo views in the underlying Git repo.
|
/// Reflect changes made in the Jujutsu repo compared to our current view of the
|
||||||
/// Returns a list of names of branches that failed to export.
|
/// 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
|
// TODO: Also indicate why we failed to export these branches
|
||||||
fn export_changes(
|
pub fn export_refs(
|
||||||
mut_repo: &mut MutableRepo,
|
mut_repo: &mut MutableRepo,
|
||||||
old_view: &View,
|
|
||||||
git_repo: &git2::Repository,
|
git_repo: &git2::Repository,
|
||||||
) -> Result<Vec<String>, GitExportError> {
|
) -> 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 new_view = mut_repo.view();
|
||||||
let old_branches: HashSet<_> = old_view.branches().keys().cloned().collect();
|
let old_branches: HashSet<_> = old_view.branches().keys().cloned().collect();
|
||||||
let new_branches: HashSet<_> = new_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)
|
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)]
|
#[derive(Error, Debug, PartialEq)]
|
||||||
pub enum GitFetchError {
|
pub enum GitFetchError {
|
||||||
#[error("No git remote named '{0}'")]
|
#[error("No git remote named '{0}'")]
|
||||||
|
|
Loading…
Reference in a new issue