+ struct pathspec_item path_items = {
+ .match = path,
+ .len = strlen(path)
+ };
+ struct pathspec paths = {
+ .nr = 1,
+ .items = &path_items
+ };
+ struct walk_tree_context walk_tree_ctx = {
+ .match_path = path,
+ .matched_oid = &oid,
+ .found_path = 0,
+ .file_only = file_only
+ };
+
+ if (get_oid(head, &oid))
+ return -1;
+ type = oid_object_info(the_repository, &oid, &size);
+ if (type == OBJ_COMMIT) {
+ commit = lookup_commit_reference(the_repository, &oid);
+ read_tree_recursive(commit->maybe_tree, "", 0, 0, &paths, walk_tree, &walk_tree_ctx);
+ if (!walk_tree_ctx.found_path)
+ return -1;
+ type = oid_object_info(the_repository, &oid, &size);
+ }
+ if (type == OBJ_BAD)
+ return -1;
+ buf = read_object_file(&oid, &type, &size);
+ if (!buf)
+ return -1;
+ buf[size] = '\0';
+ html_raw(buf, size);
+ free(buf);
+ return 0;
+}
+
+void cgit_print_blob(const char *hex, char *path, const char *head, int file_only)
+{
+ struct object_id oid;
+ enum object_type type;
+ char *buf;
+ unsigned long size;
+ struct commit *commit;
+ struct pathspec_item path_items = {
+ .match = path,
+ .len = path ? strlen(path) : 0
+ };
+ struct pathspec paths = {
+ .nr = 1,
+ .items = &path_items
+ };
+ struct walk_tree_context walk_tree_ctx = {
+ .match_path = path,
+ .matched_oid = &oid,
+ .found_path = 0,
+ .file_only = file_only
+ };