From 331ebf4cef21e50b6df990a32ee77b53d36ebdf4 Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Sun, 12 Feb 2023 11:49:05 -0800 Subject: [PATCH] cli: use reverse-alphabet hex for branch name in `jj git push --change` --- CHANGELOG.md | 11 +++++------ src/cli_util.rs | 5 ++++- tests/test_git_push.rs | 12 ++++++------ 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5aec7aaa4..1b2be1ddd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -50,12 +50,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * The builtin `jj update` and `jj up` aliases for `jj checkout` have been deleted. -* Change IDs are now in rendered using letters from the end of the alphabet - (backwards from 'z' through 'k') instead of the usual hex digits ('0' through - '9' and 'a' through 'f'). This is to clarify the distinction between change - IDs and commit IDs, and to allow more efficient lookup of unique prefixes. - This change doesn't affect the storage format; existing repositories will - remain usable. +* Change IDs are now rendered using letters from the end of the alphabet (from + 'z' through 'k') instead of the usual hex digits ('0' through '9' and 'a' + through 'f'). This is to clarify the distinction between change IDs and commit + IDs, and to allow more efficient lookup of unique prefixes. This change + doesn't affect the storage format; existing repositories will remain usable. ### New features diff --git a/src/cli_util.rs b/src/cli_util.rs index 5d427267f..56d7f8831 100644 --- a/src/cli_util.rs +++ b/src/cli_util.rs @@ -32,6 +32,7 @@ use jujutsu_lib::backend::{BackendError, ChangeId, CommitId, ObjectId, TreeId}; use jujutsu_lib::commit::Commit; use jujutsu_lib::git::{GitExportError, GitImportError}; use jujutsu_lib::gitignore::GitIgnoreFile; +use jujutsu_lib::hex_util::to_reverse_hex; use jujutsu_lib::matchers::{EverythingMatcher, Matcher, PrefixMatcher, Visit}; use jujutsu_lib::op_heads_store::{self, OpHeadResolutionError, OpHeadsStore}; use jujutsu_lib::op_store::{OpStore, OpStoreError, OperationId, RefTarget, WorkspaceId}; @@ -1619,7 +1620,9 @@ pub fn short_commit_hash(commit_id: &CommitId) -> String { } pub fn short_change_hash(change_id: &ChangeId) -> String { - change_id.hex()[0..12].to_string() + // TODO: We could avoid the unwrap() and make this more efficient by converting + // straight from binary. + to_reverse_hex(&change_id.hex()[0..12]).unwrap() } pub fn short_operation_hash(operation_id: &OperationId) -> String { diff --git a/tests/test_git_push.rs b/tests/test_git_push.rs index 9b039d79f..944105499 100644 --- a/tests/test_git_push.rs +++ b/tests/test_git_push.rs @@ -221,9 +221,9 @@ fn test_git_push_changes() { let stdout = test_env.jj_cmd_success(&workspace_root, &["git", "push", "--change", "@"]); insta::assert_snapshot!(stdout, @r###" - Creating branch push-1b76972398e6 for revision @ + Creating branch push-yostqsxwqrlt for revision @ Branch changes to push to origin: - Add branch push-1b76972398e6 to 28d7620ea63a + Add branch push-yostqsxwqrlt to 28d7620ea63a "###); // test pushing two changes at once std::fs::write(workspace_root.join("file"), "modified2").unwrap(); @@ -232,10 +232,10 @@ fn test_git_push_changes() { &["git", "push", "--change", "@", "--change", "@-"], ); insta::assert_snapshot!(stdout, @r###" - Creating branch push-19b790168e73 for revision @- + Creating branch push-yqosqzytrlsw for revision @- Branch changes to push to origin: - Force branch push-1b76972398e6 from 28d7620ea63a to 48d8c7948133 - Add branch push-19b790168e73 to fa16a14170fb + Force branch push-yostqsxwqrlt from 28d7620ea63a to 48d8c7948133 + Add branch push-yqosqzytrlsw to fa16a14170fb "###); // specifying the same change twice doesn't break things std::fs::write(workspace_root.join("file"), "modified3").unwrap(); @@ -245,7 +245,7 @@ fn test_git_push_changes() { ); insta::assert_snapshot!(stdout, @r###" Branch changes to push to origin: - Force branch push-1b76972398e6 from 48d8c7948133 to b5f030322b1d + Force branch push-yostqsxwqrlt from 48d8c7948133 to b5f030322b1d "###); }