void git_filebuf_cleanup(git_filebuf *file) { if (file->fd_is_open && file->fd >= 0) p_close(file->fd); if (file->fd_is_open && file->path_lock && git_path_exists(file->path_lock)) p_unlink(file->path_lock); if (file->digest) git_hash_free_ctx(file->digest); if (file->buffer) git__free(file->buffer); /* use the presence of z_buf to decide if we need to deflateEnd */ if (file->z_buf) { git__free(file->z_buf); deflateEnd(&file->zs); } if (file->path_original) git__free(file->path_original); if (file->path_lock) git__free(file->path_lock); memset(file, 0x0, sizeof(git_filebuf)); file->fd = -1; }
int git_filebuf_hash(git_oid *oid, git_filebuf *file) { assert(oid && file && file->digest); flush_buffer(file); if (verify_last_error(file) < 0) return -1; git_hash_final(oid, file->digest); git_hash_free_ctx(file->digest); file->digest = NULL; return 0; }
int git_filebuf_hash(git_oid *oid, git_filebuf *file) { int error; assert(oid && file && file->digest); if ((error = flush_buffer(file)) < GIT_SUCCESS) return git__rethrow(error, "Failed to get hash for file"); git_hash_final(oid, file->digest); git_hash_free_ctx(file->digest); file->digest = NULL; return GIT_SUCCESS; }
int git_filebuf_hash(git_oid *oid, git_filebuf *file) { int error; if (file->digest == NULL) return GIT_ERROR; if ((error = flush_buffer(file)) < GIT_SUCCESS) return error; git_hash_final(oid, file->digest); git_hash_free_ctx(file->digest); file->digest = NULL; return GIT_SUCCESS; }
void git_filebuf_cleanup(git_filebuf *file) { if (file->fd >= 0) gitfo_close(file->fd); if (file->fd >= 0 && file->path_lock && gitfo_exists(file->path_lock) == GIT_SUCCESS) gitfo_unlink(file->path_lock); if (file->digest) git_hash_free_ctx(file->digest); free(file->buffer); free(file->z_buf); deflateEnd(&file->zs); free(file->path_original); free(file->path_lock); }
void git_filebuf_cleanup(git_filebuf *file) { if (file->fd >= 0) gitfo_close(file->fd); if (gitfo_exists(file->path_lock) == GIT_SUCCESS) gitfo_unlink(file->path_lock); if (file->digest) git_hash_free_ctx(file->digest); free(file->buffer); #ifdef GIT_FILEBUF_THREADS free(file->buffer_back); #endif free(file->path_original); free(file->path_lock); }
void test_object_raw_hash__hash_by_blocks(void) { git_hash_ctx *ctx; git_oid id1, id2; cl_assert((ctx = git_hash_new_ctx()) != NULL); /* should already be init'd */ git_hash_update(ctx, hello_text, strlen(hello_text)); git_hash_final(&id2, ctx); cl_git_pass(git_oid_fromstr(&id1, hello_id)); cl_assert(git_oid_cmp(&id1, &id2) == 0); /* reinit should permit reuse */ git_hash_init(ctx); git_hash_update(ctx, bye_text, strlen(bye_text)); git_hash_final(&id2, ctx); cl_git_pass(git_oid_fromstr(&id1, bye_id)); cl_assert(git_oid_cmp(&id1, &id2) == 0); git_hash_free_ctx(ctx); }
int git_index__write(git_index *index, git_filelock *file) { static const char NULL_BYTES[] = {0, 0, 0, 0, 0, 0, 0, 0}; int error = 0; unsigned int i; git_hash_ctx *digest; git_oid hash_final; assert(index && file && file->is_locked); if ((digest = git_hash_new_ctx()) == NULL) return GIT_ENOMEM; #define WRITE_WORD(_word) {\ uint32_t network_word = htonl((_word));\ git_filelock_write(file, &network_word, 4);\ git_hash_update(digest, &network_word, 4);\ } #define WRITE_SHORT(_shrt) {\ uint16_t network_shrt = htons((_shrt));\ git_filelock_write(file, &network_shrt, 2);\ git_hash_update(digest, &network_shrt, 2);\ } #define WRITE_BYTES(_bytes, _n) {\ git_filelock_write(file, _bytes, _n);\ git_hash_update(digest, _bytes, _n);\ } WRITE_BYTES(INDEX_HEADER_SIG, 4); WRITE_WORD(INDEX_VERSION_NUMBER); WRITE_WORD(index->entry_count); for (i = 0; i < index->entry_count; ++i) { git_index_entry *entry; size_t path_length, padding; entry = &index->entries[i]; path_length = strlen(entry->path); WRITE_WORD(entry->ctime.seconds); WRITE_WORD(entry->ctime.nanoseconds); WRITE_WORD(entry->mtime.seconds); WRITE_WORD(entry->mtime.nanoseconds); WRITE_WORD(entry->dev); WRITE_WORD(entry->ino); WRITE_WORD(entry->mode); WRITE_WORD(entry->uid); WRITE_WORD(entry->gid); WRITE_WORD(entry->file_size); WRITE_BYTES(entry->oid.id, GIT_OID_RAWSZ); WRITE_SHORT(entry->flags); if (entry->flags & GIT_IDXENTRY_EXTENDED) { WRITE_SHORT(entry->flags_extended); padding = long_entry_padding(path_length); } else padding = short_entry_padding(path_length); WRITE_BYTES(entry->path, path_length); WRITE_BYTES(NULL_BYTES, padding); } #undef WRITE_WORD #undef WRITE_BYTES #undef WRITE_SHORT #undef WRITE_FLAGS /* TODO: write extensions (tree cache) */ git_hash_final(&hash_final, digest); git_hash_free_ctx(digest); git_filelock_write(file, hash_final.id, GIT_OID_RAWSZ); return error; }