fix(commit): make object hashes branch aware and thus dont error status out
This commit is contained in:
parent
42b8858558
commit
fae8489871
5 changed files with 45 additions and 15 deletions
|
|
@ -55,7 +55,7 @@ File* slice_file(File*, uint64_t, uint64_t);
|
|||
File* copy_file(File* original);
|
||||
int insert_line(File*, char*, size_t);
|
||||
int delete_line(File*, size_t);
|
||||
int snapshot_file(char*, char*, size_t, char*);
|
||||
int snapshot_file(char*, char*, size_t, char*, char*);
|
||||
void free_file(File*);
|
||||
FileInfoBuffer* file_info_buffer_new();
|
||||
int file_info_buffer_push(FileInfoBuffer*, FileInfo);
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@
|
|||
|
||||
char* get_object(char*, size_t*);
|
||||
void* parse_object(char*, ObjectType, size_t*, char*);
|
||||
int save_diff(ActionList*, char*, char*, size_t, char*);
|
||||
int save_diff(ActionList*, char*, char*, size_t, char*, char*);
|
||||
int read_diff(char*, char*, ActionList*);
|
||||
int save_file_diff(char*, char*, size_t, char*, ActionList*);
|
||||
File* apply_diff(File*, ActionList*);
|
||||
|
|
|
|||
|
|
@ -420,7 +420,7 @@ int commit(int argc, char** argv) {
|
|||
changes->insertions += modified_file->lines;
|
||||
|
||||
char file_hash[41];
|
||||
snapshot_file(files->items[idx], root, 0, file_hash);
|
||||
snapshot_file(files->items[idx], root, 0, branch, file_hash);
|
||||
flat_map_put(file_hash_map, files->items[idx], file_hash);
|
||||
continue;
|
||||
}
|
||||
|
|
@ -545,7 +545,7 @@ int commit(int argc, char** argv) {
|
|||
|
||||
if (diff->len > 200) {
|
||||
char new_base_hash[41];
|
||||
snapshot_file(files->items[idx], root, base_file->base_num+1, new_base_hash);
|
||||
snapshot_file(files->items[idx], root, base_file->base_num+1, branch, new_base_hash);
|
||||
|
||||
flat_map_put(file_hash_map, files->items[idx], new_base_hash);
|
||||
|
||||
|
|
@ -559,12 +559,28 @@ int commit(int argc, char** argv) {
|
|||
continue;
|
||||
}
|
||||
else {
|
||||
save_diff(diff, files->items[idx], root, base_file->diff_num, base_file_hash);
|
||||
save_diff(diff, files->items[idx], root, base_file->diff_num, base_file_hash, branch);
|
||||
|
||||
char diff_hash[41];
|
||||
char id[3 + snprintf(NULL, 0, "%lu", base_file->diff_num) + strlen(files->items[idx]) + strlen(branch)];
|
||||
snprintf(id, sizeof(id), "%s %lu %s", (char*)files->items[idx], base_file->diff_num, branch);
|
||||
object_hash(BaseFileObject, id, diff_hash);
|
||||
size_t id_len = snprintf(NULL, 0, "%s %zu %s", (char*)files->items[idx], base_file->diff_num, branch) + 1;
|
||||
char* id = calloc(id_len, sizeof(char));
|
||||
if (!id) {
|
||||
free_action_list(diff);
|
||||
free_file(modified_file);
|
||||
free_file(basefile);
|
||||
free(commit_message);
|
||||
list_free(files);
|
||||
base_file_buffer_free(base_files);
|
||||
free(branch);
|
||||
free(root);
|
||||
free_config(&config);
|
||||
free(changes);
|
||||
return 1;
|
||||
}
|
||||
|
||||
snprintf(id, id_len, "%s %zu %s", (char*)files->items[idx], base_file->diff_num, branch);
|
||||
object_hash(FileDiffObject, id, diff_hash);
|
||||
free(id);
|
||||
|
||||
flat_map_put(file_hash_map, files->items[idx], diff_hash);
|
||||
|
||||
|
|
|
|||
16
src/file.c
16
src/file.c
|
|
@ -181,7 +181,7 @@ int delete_line(File* file, size_t idx) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
int snapshot_file(char* path, char* root, size_t basefile_id, char* hash) {
|
||||
int snapshot_file(char* path, char* root, size_t basefile_id, char* branch, char* hash) {
|
||||
File* file = new_file(path);
|
||||
if (!file) return 1;
|
||||
|
||||
|
|
@ -221,9 +221,17 @@ int snapshot_file(char* path, char* root, size_t basefile_id, char* hash) {
|
|||
free(concat_file);
|
||||
concat_file = NULL;
|
||||
|
||||
char id[2 + snprintf(NULL, 0, "%d", basefile_id) + strlen(path)];
|
||||
snprintf(id, sizeof(id), "%s %d", path, basefile_id);
|
||||
size_t id_len = snprintf(NULL, 0, "%s %zu %s", path, basefile_id, branch) + 1;
|
||||
char* id = calloc(id_len, sizeof(char));
|
||||
if (!id) {
|
||||
free(final_content);
|
||||
free_file(file);
|
||||
return 0;
|
||||
}
|
||||
|
||||
snprintf(id, id_len, "%s %zu %s", path, basefile_id, branch);
|
||||
object_hash(BaseFileObject, id, hash);
|
||||
free(id);
|
||||
|
||||
char dir_path[PATH_MAX];
|
||||
char file_path[PATH_MAX];
|
||||
|
|
@ -323,4 +331,4 @@ FileInfo* file_info_buffer_search(FileInfoBuffer* buffer, const char* filename)
|
|||
FileInfo search_key = {.mode = 0, .name = (char*)filename};
|
||||
|
||||
return (FileInfo*)list_binary_search(buffer, &search_key, compare_file_info);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
12
src/object.c
12
src/object.c
|
|
@ -152,7 +152,7 @@ static int mkdir_recursive(const char *path, mode_t mode) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int save_diff(ActionList* diff, char* path, char* root, size_t diff_id, char* basefile_hash) {
|
||||
int save_diff(ActionList* diff, char* path, char* root, size_t diff_id, char* basefile_hash, char* branch) {
|
||||
size_t buffer_size = 41;
|
||||
|
||||
buffer_size += 1 + snprintf(NULL, 0, "%d", diff->len);
|
||||
|
|
@ -204,10 +204,16 @@ int save_diff(ActionList* diff, char* path, char* root, size_t diff_id, char* ba
|
|||
);
|
||||
}
|
||||
|
||||
char id[2+snprintf(NULL, 0, "%d", diff_id)+strlen(path)];
|
||||
snprintf(id, sizeof(id), "%s %d", path, diff_id);
|
||||
size_t id_len = snprintf(NULL, 0, "%s %zu %s", path, diff_id, branch) + 1;
|
||||
char* id = calloc(id_len, sizeof(char));
|
||||
if (!id) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
snprintf(id, id_len, "%s %zu %s", path, diff_id, branch);
|
||||
char hash[41];
|
||||
object_hash(FileDiffObject, id, hash);
|
||||
free(id);
|
||||
|
||||
char dir_path[PATH_MAX];
|
||||
char file_path[PATH_MAX];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue