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 "utilities.h"
|
||||||
#include "hash.h"
|
#include "hash.h"
|
||||||
|
|
||||||
typedef List FileInfoBuffer;
|
void snapshot_tree(FileInfoBuffer*);
|
||||||
|
|
||||||
void snapshot_tree(PathBuffer*);
|
|
||||||
|
|
||||||
#endif // TREE_H
|
#endif // TREE_H
|
||||||
|
|
|
||||||
23
src/tree.c
23
src/tree.c
|
|
@ -1,27 +1,37 @@
|
||||||
#include "tree.h"
|
#include "tree.h"
|
||||||
|
|
||||||
void snapshot_tree(PathBuffer* tree) {
|
void snapshot_tree(FileInfoBuffer* tree) {
|
||||||
PathBuffer* files = path_buffer_new();
|
FileInfoBuffer* files = file_info_buffer_new();
|
||||||
char relative[PATH_MAX] = "";
|
char relative[PATH_MAX] = "";
|
||||||
char* root = find_root(relative);
|
char* root = find_root(relative);
|
||||||
if (!root) {
|
if (!root) {
|
||||||
perror("ERROR: unable to find root directory of the repository!");
|
perror("ERROR: unable to find root directory of the repository!");
|
||||||
path_buffer_free(files);
|
file_info_buffer_free(files);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
walk(root, relative, relative, files, 1, root);
|
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];
|
char tmp[1024];
|
||||||
size_t offset = 0;
|
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++) {
|
for (size_t idx = 0; idx < files->len; idx++) {
|
||||||
size_t remaining = sizeof(tmp) - offset;
|
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) {
|
if (written < 0 || (size_t)written >= remaining) {
|
||||||
perror("ERROR: buffer overflow in snapshot_tree!\n");
|
perror("ERROR: buffer overflow in snapshot_tree!\n");
|
||||||
return;
|
return;
|
||||||
|
|
@ -33,6 +43,7 @@ void snapshot_tree(PathBuffer* tree) {
|
||||||
char hash[41];
|
char hash[41];
|
||||||
object_hash(TreeObject, tmp, hash);
|
object_hash(TreeObject, tmp, hash);
|
||||||
|
|
||||||
|
printf("content: %s\n", tmp);
|
||||||
printf("hash: %s\n", hash);
|
printf("hash: %s\n", hash);
|
||||||
|
|
||||||
char dir_path[PATH_MAX];
|
char dir_path[PATH_MAX];
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue