forked from mirrors/jj
view: use get_git_ref(name) where extra .clone() wouldn't matter
Perhaps, all view.get_<kind>(name) functions can return reference, but I'm not willing to change the interface at this point. I'll revisit this after migrating Option<RefTarget> to new Conflict-based type.
This commit is contained in:
parent
005f3b90ee
commit
5ed070a78a
2 changed files with 18 additions and 21 deletions
|
@ -131,7 +131,7 @@ impl View {
|
|||
RefName::LocalBranch(name) => self.get_local_branch(name),
|
||||
RefName::RemoteBranch { branch, remote } => self.get_remote_branch(branch, remote),
|
||||
RefName::Tag(name) => self.get_tag(name),
|
||||
RefName::GitRef(name) => self.git_refs().get(name).cloned(),
|
||||
RefName::GitRef(name) => self.get_git_ref(name),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -152,28 +152,28 @@ fn test_import_refs() {
|
|||
|
||||
assert_eq!(view.git_refs().len(), 6);
|
||||
assert_eq!(
|
||||
view.git_refs().get("refs/heads/main"),
|
||||
Some(RefTarget::Normal(jj_id(&commit2))).as_ref()
|
||||
view.get_git_ref("refs/heads/main"),
|
||||
Some(RefTarget::Normal(jj_id(&commit2)))
|
||||
);
|
||||
assert_eq!(
|
||||
view.git_refs().get("refs/heads/feature1"),
|
||||
Some(RefTarget::Normal(jj_id(&commit3))).as_ref()
|
||||
view.get_git_ref("refs/heads/feature1"),
|
||||
Some(RefTarget::Normal(jj_id(&commit3)))
|
||||
);
|
||||
assert_eq!(
|
||||
view.git_refs().get("refs/heads/feature2"),
|
||||
Some(RefTarget::Normal(jj_id(&commit4))).as_ref()
|
||||
view.get_git_ref("refs/heads/feature2"),
|
||||
Some(RefTarget::Normal(jj_id(&commit4)))
|
||||
);
|
||||
assert_eq!(
|
||||
view.git_refs().get("refs/remotes/origin/main"),
|
||||
Some(RefTarget::Normal(jj_id(&commit1))).as_ref()
|
||||
view.get_git_ref("refs/remotes/origin/main"),
|
||||
Some(RefTarget::Normal(jj_id(&commit1)))
|
||||
);
|
||||
assert_eq!(
|
||||
view.git_refs().get("refs/remotes/origin/feature3"),
|
||||
Some(RefTarget::Normal(jj_id(&commit6))).as_ref()
|
||||
view.get_git_ref("refs/remotes/origin/feature3"),
|
||||
Some(RefTarget::Normal(jj_id(&commit6)))
|
||||
);
|
||||
assert_eq!(
|
||||
view.git_refs().get("refs/tags/v1.0"),
|
||||
Some(RefTarget::Normal(jj_id(&commit5))).as_ref()
|
||||
view.get_git_ref("refs/tags/v1.0"),
|
||||
Some(RefTarget::Normal(jj_id(&commit5)))
|
||||
);
|
||||
assert_eq!(view.git_head(), Some(&RefTarget::Normal(jj_id(&commit2))));
|
||||
}
|
||||
|
@ -263,18 +263,15 @@ fn test_import_refs_reimport() {
|
|||
assert!(view.tags().is_empty());
|
||||
|
||||
assert_eq!(view.git_refs().len(), 3);
|
||||
assert_eq!(view.get_git_ref("refs/heads/main"), Some(commit2_target));
|
||||
assert_eq!(
|
||||
view.git_refs().get("refs/heads/main"),
|
||||
Some(commit2_target).as_ref()
|
||||
);
|
||||
assert_eq!(
|
||||
view.git_refs().get("refs/remotes/origin/main"),
|
||||
Some(commit1_target).as_ref()
|
||||
view.get_git_ref("refs/remotes/origin/main"),
|
||||
Some(commit1_target)
|
||||
);
|
||||
let commit5_target = RefTarget::Normal(jj_id(&commit5));
|
||||
assert_eq!(
|
||||
view.git_refs().get("refs/heads/feature2"),
|
||||
Some(commit5_target).as_ref()
|
||||
view.get_git_ref("refs/heads/feature2"),
|
||||
Some(commit5_target)
|
||||
);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue