Optimisation in hash_object
This commit is contained in:
2
src/fs.c
2
src/fs.c
@@ -9,8 +9,8 @@
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <zlib.h>
|
#include <zlib.h>
|
||||||
|
|
||||||
#include "includes.h"
|
|
||||||
#include "fs.h"
|
#include "fs.h"
|
||||||
|
#include "includes.h"
|
||||||
#include "objects.h"
|
#include "objects.h"
|
||||||
|
|
||||||
int local_repo_exist()
|
int local_repo_exist()
|
||||||
|
|||||||
2
src/fs.h
2
src/fs.h
@@ -1,6 +1,8 @@
|
|||||||
#ifndef FS_H
|
#ifndef FS_H
|
||||||
#define FS_H 1
|
#define FS_H 1
|
||||||
|
|
||||||
|
#include "objects.h"
|
||||||
|
|
||||||
#define LOCAL_REPO ".cgit"
|
#define LOCAL_REPO ".cgit"
|
||||||
#define DEFAULT_DIR_MODE 0755
|
#define DEFAULT_DIR_MODE 0755
|
||||||
#define DEFAULT_FILE_MODE 0444
|
#define DEFAULT_FILE_MODE 0444
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <openssl/evp.h>
|
#include <openssl/sha.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@@ -54,27 +54,18 @@ int full_object(struct object *obj, char *buffer, size_t buffer_size)
|
|||||||
void hash_object(struct object *obj, char* result)
|
void hash_object(struct object *obj, char* result)
|
||||||
{
|
{
|
||||||
unsigned char md_buffer[DIGEST_LENGTH] = {0};
|
unsigned char md_buffer[DIGEST_LENGTH] = {0};
|
||||||
EVP_MD_CTX *ctx = EVP_MD_CTX_new();
|
size_t data_size = object_size(obj);
|
||||||
|
char* data = malloc(data_size);
|
||||||
|
full_object(obj, data, data_size);
|
||||||
|
|
||||||
char* hr_size = malloc(decimal_len(obj->size) + 1);
|
SHA1(data, data_size, md_buffer);
|
||||||
sprintf(hr_size, "%li", obj->size);
|
|
||||||
|
|
||||||
EVP_DigestInit(ctx, EVP_sha1());
|
|
||||||
EVP_DigestUpdate(ctx, obj->object_type, strlen(obj->object_type));
|
|
||||||
EVP_DigestUpdate(ctx, " ", 1);
|
|
||||||
EVP_DigestUpdate(ctx, hr_size, decimal_len(obj->size));
|
|
||||||
EVP_DigestUpdate(ctx, "\0", 1);
|
|
||||||
EVP_DigestUpdate(ctx, obj->content, obj->size);
|
|
||||||
|
|
||||||
EVP_DigestFinal(ctx, md_buffer, NULL);
|
|
||||||
free(hr_size);
|
|
||||||
|
|
||||||
for (int i = 0; i < DIGEST_LENGTH; i++)
|
for (int i = 0; i < DIGEST_LENGTH; i++)
|
||||||
{
|
{
|
||||||
sprintf((result + 2 * i), "%.2x", md_buffer[i]);
|
sprintf((result + 2 * i), "%.2x", md_buffer[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
EVP_MD_CTX_free(ctx);
|
free(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
int uncompress_object(struct object *obj, char* compressed, uLongf comp_size)
|
int uncompress_object(struct object *obj, char* compressed, uLongf comp_size)
|
||||||
|
|||||||
Reference in New Issue
Block a user