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

git-push: remove redundant hash map lookup from print-changes loop

This commit is contained in:
Yuya Nishihara 2024-09-14 11:45:44 +09:00
parent 2f78c25d35
commit a48ecf3e62

View file

@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
use std::collections::HashMap;
use std::collections::HashSet; use std::collections::HashSet;
use std::fmt; use std::fmt;
use std::io; use std::io;
@ -384,27 +383,16 @@ fn print_commits_ready_to_push(
repo: &dyn Repo, repo: &dyn Repo,
bookmark_updates: &[(String, BookmarkPushUpdate)], bookmark_updates: &[(String, BookmarkPushUpdate)],
) -> io::Result<()> { ) -> io::Result<()> {
let mut bookmark_push_direction = HashMap::new(); let to_direction = |old_target: &CommitId, new_target: &CommitId| {
for (bookmark_name, update) in bookmark_updates {
let BookmarkPushUpdate {
old_target: Some(old_target),
new_target: Some(new_target),
} = update
else {
continue;
};
assert_ne!(old_target, new_target); assert_ne!(old_target, new_target);
bookmark_push_direction.insert( if repo.index().is_ancestor(old_target, new_target) {
bookmark_name.to_string(), BookmarkMoveDirection::Forward
if repo.index().is_ancestor(old_target, new_target) { } else if repo.index().is_ancestor(new_target, old_target) {
BookmarkMoveDirection::Forward BookmarkMoveDirection::Backward
} else if repo.index().is_ancestor(new_target, old_target) { } else {
BookmarkMoveDirection::Backward BookmarkMoveDirection::Sideways
} else { }
BookmarkMoveDirection::Sideways };
},
);
}
for (bookmark_name, update) in bookmark_updates { for (bookmark_name, update) in bookmark_updates {
match (&update.old_target, &update.new_target) { match (&update.old_target, &update.new_target) {
@ -417,7 +405,7 @@ fn print_commits_ready_to_push(
// among many was moved sideways (say). TODO: People on Discord // among many was moved sideways (say). TODO: People on Discord
// suggest "Move bookmark ... forward by n commits", // suggest "Move bookmark ... forward by n commits",
// possibly "Move bookmark ... sideways (X forward, Y back)". // possibly "Move bookmark ... sideways (X forward, Y back)".
let msg = match bookmark_push_direction.get(bookmark_name).unwrap() { let msg = match to_direction(old_target, new_target) {
BookmarkMoveDirection::Forward => { BookmarkMoveDirection::Forward => {
format!("Move forward bookmark {bookmark_name} from {old} to {new}") format!("Move forward bookmark {bookmark_name} from {old} to {new}")
} }