From ca2e9fe6d1dca5353b637db35d1939e2f3fcb66d Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Sat, 14 Jan 2023 16:15:05 +0900 Subject: [PATCH] git: simply use rand::random() to generate ref preventing gc We don't care the ref content as long as it is unique, so using threaded RNG should be fine. This change means refs/jj/keep will now contain refs of the following forms: - new create_no_gc_ref(): 0f8d6cd9721823906cfb55dac99d7bf5 - old create_no_gc_ref(): 0f6d93fe-0507-4db8-ad0a-6317f02e27b9 - prevent_gc(commit_id): 0f9c15100b6f1373f38186357e274a829fb6c4e2 --- lib/src/git_backend.rs | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/lib/src/git_backend.rs b/lib/src/git_backend.rs index 373571228..687e818b6 100644 --- a/lib/src/git_backend.rs +++ b/lib/src/git_backend.rs @@ -21,7 +21,6 @@ use std::sync::{Arc, Mutex}; use git2::Oid; use itertools::Itertools; use prost::Message; -use uuid::Uuid; use crate::backend::{ make_root_commit, Backend, BackendError, BackendResult, ChangeId, Commit, CommitId, Conflict, @@ -138,13 +137,8 @@ fn deserialize_extras(commit: &mut Commit, bytes: &[u8]) { /// Creates a random ref in refs/jj/. Used for preventing GC of commits we /// create. fn create_no_gc_ref() -> String { - let mut no_gc_ref = NO_GC_REF_NAMESPACE.to_owned(); - let mut uuid_buffer = Uuid::encode_buffer(); - let uuid_str = Uuid::new_v4() - .as_hyphenated() - .encode_lower(&mut uuid_buffer); - no_gc_ref.push_str(uuid_str); - no_gc_ref + let random_bytes: [u8; 16] = rand::random(); + format!("{NO_GC_REF_NAMESPACE}{}", hex::encode(random_bytes)) } fn validate_git_object_id(id: &impl ObjectId) -> Result {