From cd551bea34e0965653bce9358fc9a8dfd1ea9953 Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Sat, 14 Jan 2023 13:50:45 +0900 Subject: [PATCH] backend: make random ChangeId fully random, remove UUID mask bits --- lib/src/settings.rs | 5 +---- tests/test_git_push.rs | 4 ++-- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/lib/src/settings.rs b/lib/src/settings.rs index f7ec56268..d68452f43 100644 --- a/lib/src/settings.rs +++ b/lib/src/settings.rs @@ -155,10 +155,7 @@ impl UserSettings { pub struct JJRng(Mutex); impl JJRng { pub fn new_change_id(&self) -> ChangeId { - let mut random_bytes: [u8; 16] = self.gen(); - // TODO: make it fully random - random_bytes[6] = (random_bytes[6] & 0x0f) | ((4 as u8) << 4); // Version: 4 - random_bytes[8] = (random_bytes[8] & 0x3f) | 0x80; // Variant::RFC4122 + let random_bytes: [u8; 16] = self.gen(); ChangeId::new(random_bytes.into()) } diff --git a/tests/test_git_push.rs b/tests/test_git_push.rs index 94bb1fb83..4b31c8684 100644 --- a/tests/test_git_push.rs +++ b/tests/test_git_push.rs @@ -246,14 +246,14 @@ fn test_git_push_existing_long_branch() { std::fs::write(workspace_root.join("file"), "contents").unwrap(); test_env.jj_cmd_success( &workspace_root, - &["branch", "create", "push-19b790168e7347a7ba98deae21e807c0"], + &["branch", "create", "push-19b790168e73f7a73a98deae21e807c0"], ); let stdout = test_env.jj_cmd_success(&workspace_root, &["git", "push", "--change=@"]); insta::assert_snapshot!(stdout, @r###" Branch changes to push to origin: - Add branch push-19b790168e7347a7ba98deae21e807c0 to fa16a14170fb + Add branch push-19b790168e73f7a73a98deae21e807c0 to fa16a14170fb "###); }