diff --git a/urmoms.c b/urmoms.c index 6a81e93..62eebca 100644 --- a/urmoms.c +++ b/urmoms.c @@ -561,21 +561,14 @@ writeatom(FILE *fp) } int -writeblob(const git_index_entry *entry) +writeblob(git_object *obj, const char *filename, git_off_t filesize) { char fpath[PATH_MAX]; - char ref[PATH_MAX]; char tmp[PATH_MAX] = ""; char *p; - git_object *obj = NULL; FILE *fp; - snprintf(fpath, sizeof(fpath), "file/%s.html", entry->path); - snprintf(ref, sizeof(ref), "HEAD:%s", entry->path); - - if (git_revparse_single(&obj, repo, ref)) - return 1; - + snprintf(fpath, sizeof(fpath), "file/%s.html", filename); if (mkdirp(dirname(fpath))) return 1; @@ -589,7 +582,11 @@ writeblob(const git_index_entry *entry) fp = efopen(fpath, "w"); writeheader(fp); - fprintf(fp, "
%s (%" PRIu32 "b)
", fp); + xmlencode(fp, filename, strlen(filename)); + fprintf(fp, " (%" PRIu32 "b)", filesize); + fputs("
Binary file
\n"); } else { @@ -597,7 +594,6 @@ writeblob(const git_index_entry *entry) if (ferror(fp)) err(1, "fwrite"); } - git_object_free(obj); writefooter(fp); fclose(fp); @@ -606,35 +602,89 @@ writeblob(const git_index_entry *entry) return 0; } +int +writefilestree(FILE *fp, git_tree *tree, const char *path) +{ + const git_tree_entry *entry = NULL; + const char *filename; + char filepath[PATH_MAX]; + git_object *obj = NULL; + git_off_t filesize; + size_t count, i; + int ret; + + count = git_tree_entrycount(tree); + for (i = 0; i < count; i++) { + if (!(entry = git_tree_entry_byindex(tree, i))) + return -1; + + filename = git_tree_entry_name(entry); + if (git_tree_entry_to_object(&obj, repo, entry)) + return -1; + switch (git_object_type(obj)) { + case GIT_OBJ_BLOB: + break; + case GIT_OBJ_TREE: + ret = writefilestree(fp, (git_tree *)obj, filename); + git_object_free(obj); + if (ret) + return ret; + continue; + default: + git_object_free(obj); + continue; + } + if (path[0]) { + snprintf(filepath, sizeof(filepath), "%s/%s", path, filename); + filename = filepath; + } + + filesize = git_blob_rawsize((git_blob *)obj); + + fputs("Mode | Name | Size |
", fp); - fprintf(fp, "%u", entry->mode); /* TODO: fancy print, like: "-rw-r--r--" */ - fprintf(fp, " | path, strlen(entry->path)); - fputs(".html\">", fp); - xmlencode(fp, entry->path, strlen(entry->path)); - fputs(" | ", fp); - fprintf(fp, "%" PRIu32, entry->file_size); - fputs(" |