mirror of
https://github.com/martinvonz/jj.git
synced 2025-02-08 13:39:56 +00:00
git: use HashMap to track failed branches internally in export_refs()
This helps to filter out unexported refs in the next commit.
This commit is contained in:
parent
4d2402831a
commit
aaf1bbcb4a
1 changed files with 13 additions and 23 deletions
|
@ -463,7 +463,7 @@ pub enum FailedRefExportReason {
|
||||||
struct RefsToExport {
|
struct RefsToExport {
|
||||||
branches_to_update: BTreeMap<RefName, (Option<Oid>, Oid)>,
|
branches_to_update: BTreeMap<RefName, (Option<Oid>, Oid)>,
|
||||||
branches_to_delete: BTreeMap<RefName, Oid>,
|
branches_to_delete: BTreeMap<RefName, Oid>,
|
||||||
failed_branches: Vec<FailedRefExport>,
|
failed_branches: HashMap<RefName, FailedRefExportReason>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Export changes to branches made in the Jujutsu repo compared to our last
|
/// Export changes to branches made in the Jujutsu repo compared to our last
|
||||||
|
@ -520,10 +520,7 @@ pub fn export_some_refs(
|
||||||
for (parsed_ref_name, old_oid) in branches_to_delete {
|
for (parsed_ref_name, old_oid) in branches_to_delete {
|
||||||
let git_ref_name = to_git_ref_name(&parsed_ref_name).unwrap();
|
let git_ref_name = to_git_ref_name(&parsed_ref_name).unwrap();
|
||||||
if let Err(reason) = delete_git_ref(git_repo, &git_ref_name, old_oid) {
|
if let Err(reason) = delete_git_ref(git_repo, &git_ref_name, old_oid) {
|
||||||
failed_branches.push(FailedRefExport {
|
failed_branches.insert(parsed_ref_name, reason);
|
||||||
name: parsed_ref_name,
|
|
||||||
reason,
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
let new_target = RefTarget::absent();
|
let new_target = RefTarget::absent();
|
||||||
if let RefName::LocalBranch(branch) = &parsed_ref_name {
|
if let RefName::LocalBranch(branch) = &parsed_ref_name {
|
||||||
|
@ -539,10 +536,7 @@ pub fn export_some_refs(
|
||||||
for (parsed_ref_name, (old_oid, new_oid)) in branches_to_update {
|
for (parsed_ref_name, (old_oid, new_oid)) in branches_to_update {
|
||||||
let git_ref_name = to_git_ref_name(&parsed_ref_name).unwrap();
|
let git_ref_name = to_git_ref_name(&parsed_ref_name).unwrap();
|
||||||
if let Err(reason) = update_git_ref(git_repo, &git_ref_name, old_oid, new_oid) {
|
if let Err(reason) = update_git_ref(git_repo, &git_ref_name, old_oid, new_oid) {
|
||||||
failed_branches.push(FailedRefExport {
|
failed_branches.insert(parsed_ref_name, reason);
|
||||||
name: parsed_ref_name,
|
|
||||||
reason,
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
let new_target = RefTarget::normal(CommitId::from_bytes(new_oid.as_bytes()));
|
let new_target = RefTarget::normal(CommitId::from_bytes(new_oid.as_bytes()));
|
||||||
if let RefName::LocalBranch(branch) = &parsed_ref_name {
|
if let RefName::LocalBranch(branch) = &parsed_ref_name {
|
||||||
|
@ -555,7 +549,12 @@ pub fn export_some_refs(
|
||||||
mut_repo.set_git_ref_target(&git_ref_name, new_target);
|
mut_repo.set_git_ref_target(&git_ref_name, new_target);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
failed_branches.sort_by_key(|failed| failed.name.clone());
|
|
||||||
|
let failed_branches = failed_branches
|
||||||
|
.into_iter()
|
||||||
|
.map(|(name, reason)| FailedRefExport { name, reason })
|
||||||
|
.sorted_unstable_by(|a, b| a.name.cmp(&b.name))
|
||||||
|
.collect();
|
||||||
Ok(failed_branches)
|
Ok(failed_branches)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -567,7 +566,7 @@ fn diff_refs_to_export(
|
||||||
) -> RefsToExport {
|
) -> RefsToExport {
|
||||||
let mut branches_to_update = BTreeMap::new();
|
let mut branches_to_update = BTreeMap::new();
|
||||||
let mut branches_to_delete = BTreeMap::new();
|
let mut branches_to_delete = BTreeMap::new();
|
||||||
let mut failed_branches = vec![];
|
let mut failed_branches = HashMap::new();
|
||||||
let root_commit_target = RefTarget::normal(root_commit_id.clone());
|
let root_commit_target = RefTarget::normal(root_commit_id.clone());
|
||||||
let jj_repo_iter_all_branches = view.branches().iter().flat_map(|(branch, target)| {
|
let jj_repo_iter_all_branches = view.branches().iter().flat_map(|(branch, target)| {
|
||||||
itertools::chain(
|
itertools::chain(
|
||||||
|
@ -607,10 +606,7 @@ fn diff_refs_to_export(
|
||||||
view.get_git_ref(&name)
|
view.get_git_ref(&name)
|
||||||
} else {
|
} else {
|
||||||
// Invalid branch name in Git sense
|
// Invalid branch name in Git sense
|
||||||
failed_branches.push(FailedRefExport {
|
failed_branches.insert(ref_name, FailedRefExportReason::InvalidGitName);
|
||||||
name: ref_name,
|
|
||||||
reason: FailedRefExportReason::InvalidGitName,
|
|
||||||
});
|
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
if new_target == old_target {
|
if new_target == old_target {
|
||||||
|
@ -618,10 +614,7 @@ fn diff_refs_to_export(
|
||||||
}
|
}
|
||||||
if *new_target == root_commit_target {
|
if *new_target == root_commit_target {
|
||||||
// Git doesn't have a root commit
|
// Git doesn't have a root commit
|
||||||
failed_branches.push(FailedRefExport {
|
failed_branches.insert(ref_name, FailedRefExportReason::OnRootCommit);
|
||||||
name: ref_name,
|
|
||||||
reason: FailedRefExportReason::OnRootCommit,
|
|
||||||
});
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
let old_oid = if let Some(id) = old_target.as_normal() {
|
let old_oid = if let Some(id) = old_target.as_normal() {
|
||||||
|
@ -629,10 +622,7 @@ fn diff_refs_to_export(
|
||||||
} else if old_target.has_conflict() {
|
} else if old_target.has_conflict() {
|
||||||
// The old git ref should only be a conflict if there were concurrent import
|
// The old git ref should only be a conflict if there were concurrent import
|
||||||
// operations while the value changed. Don't overwrite these values.
|
// operations while the value changed. Don't overwrite these values.
|
||||||
failed_branches.push(FailedRefExport {
|
failed_branches.insert(ref_name, FailedRefExportReason::ConflictedOldState);
|
||||||
name: ref_name,
|
|
||||||
reason: FailedRefExportReason::ConflictedOldState,
|
|
||||||
});
|
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
assert!(old_target.is_absent());
|
assert!(old_target.is_absent());
|
||||||
|
|
Loading…
Reference in a new issue