file.c (1691B)
1 #include "git/file.h" 2 3 #include <stdlib.h> 4 5 #include "git/internal.h" 6 #include "utils.h" 7 8 struct GitFile { 9 FileType type; 10 const char* mode; 11 const char* display_path; 12 const char* repo_path; 13 // Submodule commit OID. Empty string for files. 14 const char* commit_oid; 15 ssize_t size_bytes; 16 ssize_t size_lines; 17 const char* content; 18 }; 19 20 GitFile* gitfile_create(FileType type, 21 const char* mode, 22 const char* display_path, 23 const char* repo_path, 24 const char* commit_oid, 25 ssize_t size_bytes, 26 ssize_t size_lines, 27 const char* content) { 28 GitFile* file = ecalloc(1, sizeof(GitFile)); 29 file->type = type; 30 file->mode = mode; 31 file->display_path = display_path; 32 file->repo_path = repo_path; 33 file->commit_oid = commit_oid; 34 file->size_bytes = size_bytes; 35 file->size_lines = size_lines; 36 file->content = content; 37 return file; 38 } 39 40 void gitfile_free(GitFile* file) { 41 free(file); 42 } 43 44 FileType gitfile_type(const GitFile* file) { 45 return file->type; 46 } 47 48 const char* gitfile_mode(const GitFile* file) { 49 return file->mode; 50 } 51 52 const char* gitfile_display_path(const GitFile* file) { 53 return file->display_path; 54 } 55 56 const char* gitfile_repo_path(const GitFile* file) { 57 return file->repo_path; 58 } 59 60 const char* gitfile_commit_oid(const GitFile* file) { 61 return file->commit_oid; 62 } 63 64 ssize_t gitfile_size_bytes(const GitFile* file) { 65 return file->size_bytes; 66 } 67 68 ssize_t gitfile_size_lines(const GitFile* file) { 69 return file->size_lines; 70 } 71 72 const char* gitfile_content(const GitFile* file) { 73 return file->content; 74 }