11#include <fmt/format.h>
31 stream.seekg(0, std::ios_base::end);
33 stream.seekg(0, std::ios_base::beg);
46 const std::optional<Vector<char>> buffer =
read_file(path);
50 return XXH3_128bits(buffer->data(), buffer->size());
109 if (cached_hash->last_modified == stat.st_mtime) {
110 return cached_hash->hash;
116 if (
id.runtime->src_blend_modifification_time != 0) {
117 if (stat.st_mtime !=
id.runtime->src_blend_modifification_time) {
140 XXH3_state_t *hash_state = XXH3_createState();
141 XXH3_128bits_reset(hash_state);
142 XXH3_128bits_update(hash_state, id_name.
data(), id_name.
size());
143 XXH3_128bits_update(hash_state, &*file_hash,
sizeof(XXH128_hash_t));
144 XXH128_hash_t shallow_hash = XXH3_128bits_digest(hash_state);
145 XXH3_freeState(hash_state);
158 if (!
id.deep_hash.is_null()) {
159 r_hashes.
add(&
id,
id.deep_hash);
162 current_stack.
add(&
id);
165 if (!id_shallow_hash) {
169 XXH3_state_t *hash_state = XXH3_createState();
171 XXH3_128bits_reset(hash_state);
172 XXH3_128bits_update(hash_state, &*id_shallow_hash,
sizeof(XXH128_hash_t));
176 const_cast<Main *
>(&bmain),
177 const_cast<ID *
>(&
id),
196 if (!referenced_id) {
199 const int random_data = 452942579;
200 XXH3_128bits_update(hash_state, &random_data,
sizeof(
int));
205 if (current_stack.
contains(referenced_id)) {
207 const int random_data = 234632342;
208 XXH3_128bits_update(hash_state, &random_data,
sizeof(
int));
213 if (!referenced_id_hash) {
217 XXH3_128bits_update(hash_state, referenced_id_hash->
data,
sizeof(
IDHash));
227 const XXH128_hash_t new_deep_hash_xxh128 = XXH3_128bits_digest(hash_state);
228 static_assert(
sizeof(
IDHash) ==
sizeof(XXH128_hash_t));
229 memcpy(new_deep_hash.
data, &new_deep_hash_xxh128,
sizeof(
IDHash));
230 r_hashes.
add(&
id, new_deep_hash);
236 for (
const ID *
id : ids) {
248 for (
const ID *
id : ids) {
260 for (
const uint8_t
byte :
hash.data) {
261 hex_str += fmt::format(
"{:02x}",
byte);
@ IDWALK_CB_EMBEDDED_NOT_OWNING
void BKE_library_foreach_ID_link(Main *bmain, ID *id, blender::FunctionRef< LibraryIDLinkCallback > callback, void *user_data, LibraryForeachIDFlag flag)
int BLI_stat(const char *path, BLI_stat_t *buffer) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
int BLI_open(const char *filepath, int oflag, int pmode) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
File and directory operations.
#define BLI_SCOPED_DEFER(function_to_defer)
void * BLI_mmap_get_pointer(BLI_mmap_file *file) ATTR_WARN_UNUSED_RESULT
void BLI_mmap_free(BLI_mmap_file *file) ATTR_NONNULL(1)
bool BLI_mmap_any_io_error(const BLI_mmap_file *file) ATTR_WARN_UNUSED_RESULT
BLI_mmap_file * BLI_mmap_open(int fd) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
size_t BLI_mmap_get_length(const BLI_mmap_file *file) ATTR_WARN_UNUSED_RESULT
#define ID_IS_LINKED(_id)
BMesh const char void * data
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
bool add_as(ForwardKey &&key)
const Value * lookup_ptr(const Key &key) const
bool add_overwrite(const Key &key, const Value &value)
bool add(const Key &key, const Value &value)
const Value * lookup_ptr_as(const ForwardKey &key) const
bool contains(const Key &key) const
bool contains(const Key &key) const
bool remove(const Key &key)
constexpr bool is_empty() const
constexpr int64_t size() const
constexpr const char * data() const
constexpr const char * c_str() const
static std::optional< XXH128_hash_t > get_source_file_hash(const ID &id, DeepHashErrors &r_errors)
static std::optional< XXH128_hash_t > compute_file_hash_with_file_read(const StringRefNull path)
static void compute_deep_hash_recursive(const Main &bmain, const ID &id, Set< const ID * > ¤t_stack, Map< const ID *, IDHash > &r_hashes, DeepHashErrors &r_errors)
static std::optional< XXH128_hash_t > compute_file_hash(const StringRefNull path)
static std::optional< XXH128_hash_t > get_id_shallow_hash(const ID &id, DeepHashErrors &r_errors)
static std::optional< XXH128_hash_t > compute_file_hash_with_memory_map(const StringRefNull path)
std::variant< ValidDeepHashes, DeepHashErrors > IDHashResult
static std::optional< Vector< char > > read_file(const StringRefNull path)
IDHashResult compute_linked_id_deep_hashes(const Main &bmain, Span< const ID * > root_ids)
std::string id_hash_to_hex(const IDHash &hash)
LibraryForeachIDCallbackFlag cb_flag
VectorSet< std::string > updated_files
VectorSet< std::string > missing_files