Skip to content

Commit

Permalink
git-push: remove redundant hash map lookup from print-changes loop
Browse files Browse the repository at this point in the history
  • Loading branch information
yuja committed Sep 14, 2024
1 parent 2f78c25 commit a48ecf3
Showing 1 changed file with 10 additions and 22 deletions.
32 changes: 10 additions & 22 deletions cli/src/commands/git/push.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use std::collections::HashMap;
use std::collections::HashSet;
use std::fmt;
use std::io;
Expand Down Expand Up @@ -384,27 +383,16 @@ fn print_commits_ready_to_push(
repo: &dyn Repo,
bookmark_updates: &[(String, BookmarkPushUpdate)],
) -> io::Result<()> {
let mut bookmark_push_direction = HashMap::new();
for (bookmark_name, update) in bookmark_updates {
let BookmarkPushUpdate {
old_target: Some(old_target),
new_target: Some(new_target),
} = update
else {
continue;
};
let to_direction = |old_target: &CommitId, new_target: &CommitId| {
assert_ne!(old_target, new_target);
bookmark_push_direction.insert(
bookmark_name.to_string(),
if repo.index().is_ancestor(old_target, new_target) {
BookmarkMoveDirection::Forward
} else if repo.index().is_ancestor(new_target, old_target) {
BookmarkMoveDirection::Backward
} else {
BookmarkMoveDirection::Sideways
},
);
}
if repo.index().is_ancestor(old_target, new_target) {
BookmarkMoveDirection::Forward
} else if repo.index().is_ancestor(new_target, old_target) {
BookmarkMoveDirection::Backward
} else {
BookmarkMoveDirection::Sideways
}
};

for (bookmark_name, update) in bookmark_updates {
match (&update.old_target, &update.new_target) {
Expand All @@ -417,7 +405,7 @@ fn print_commits_ready_to_push(
// among many was moved sideways (say). TODO: People on Discord
// suggest "Move bookmark ... forward by n commits",
// 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 => {
format!("Move forward bookmark {bookmark_name} from {old} to {new}")
}
Expand Down

0 comments on commit a48ecf3

Please sign in to comment.