refactor(tree): changes according to API changes of the FileInfoBuffer
This commit is contained in:
parent
52e740fab0
commit
a3ee042758
2 changed files with 18 additions and 9 deletions
|
|
@ -6,8 +6,6 @@
|
|||
#include "utilities.h"
|
||||
#include "hash.h"
|
||||
|
||||
typedef List FileInfoBuffer;
|
||||
|
||||
void snapshot_tree(PathBuffer*);
|
||||
void snapshot_tree(FileInfoBuffer*);
|
||||
|
||||
#endif // TREE_H
|
||||
|
|
|
|||
23
src/tree.c
23
src/tree.c
|
|
@ -1,27 +1,37 @@
|
|||
#include "tree.h"
|
||||
|
||||
void snapshot_tree(PathBuffer* tree) {
|
||||
PathBuffer* files = path_buffer_new();
|
||||
void snapshot_tree(FileInfoBuffer* tree) {
|
||||
FileInfoBuffer* files = file_info_buffer_new();
|
||||
char relative[PATH_MAX] = "";
|
||||
char* root = find_root(relative);
|
||||
if (!root) {
|
||||
perror("ERROR: unable to find root directory of the repository!");
|
||||
path_buffer_free(files);
|
||||
file_info_buffer_free(files);
|
||||
return;
|
||||
}
|
||||
|
||||
walk(root, relative, relative, files, 1, root);
|
||||
path_buffer_sort(files);
|
||||
file_info_buffer_sort(files);
|
||||
|
||||
for (int i = 0; i < files->len; i++) {
|
||||
printf("%s\n", ((FileInfo*)files->items + i)->name);
|
||||
}
|
||||
|
||||
char tmp[1024];
|
||||
size_t offset = 0;
|
||||
|
||||
offset += snprintf(tmp, sizeof(tmp), "%zu:", files->len);
|
||||
offset += snprintf(tmp, sizeof(tmp), "%zu ", files->len);
|
||||
|
||||
for (size_t idx = 0; idx < files->len; idx++) {
|
||||
size_t remaining = sizeof(tmp) - offset;
|
||||
|
||||
int written = snprintf(tmp + offset, remaining, "%s:", files->items[idx]);
|
||||
char base_file[strlen(((FileInfo*)files->items + idx)->name)+2];
|
||||
snprintf(base_file, sizeof(base_file), "%s_0", ((FileInfo*)files->items + idx)->name);
|
||||
|
||||
char file_hash[41];
|
||||
object_hash(FileObject, base_file, file_hash);
|
||||
|
||||
int written = snprintf(tmp + offset, remaining, "%o %s %s ", ((FileInfo*)files->items + idx)->mode, ((FileInfo*)files->items + idx)->name, file_hash);
|
||||
if (written < 0 || (size_t)written >= remaining) {
|
||||
perror("ERROR: buffer overflow in snapshot_tree!\n");
|
||||
return;
|
||||
|
|
@ -33,6 +43,7 @@ void snapshot_tree(PathBuffer* tree) {
|
|||
char hash[41];
|
||||
object_hash(TreeObject, tmp, hash);
|
||||
|
||||
printf("content: %s\n", tmp);
|
||||
printf("hash: %s\n", hash);
|
||||
|
||||
char dir_path[PATH_MAX];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue