예제 #1
0
파일: ui-plain.c 프로젝트: MarkLodato/cgit
void cgit_print_plain(struct cgit_context *ctx)
{
	const char *rev = ctx->qry.sha1;
	unsigned char sha1[20];
	struct commit *commit;
	const char *paths[] = {ctx->qry.path, NULL};

	if (!rev)
		rev = ctx->qry.head;

	if (get_sha1(rev, sha1)) {
		html_status(404, "Not found", 0);
		return;
	}
	commit = lookup_commit_reference(sha1);
	if (!commit || parse_commit(commit)) {
		html_status(404, "Not found", 0);
		return;
	}
	if (!paths[0]) {
		paths[0] = "";
		match_baselen = -1;
		print_dir(commit->tree->object.sha1, "", "");
	}
	else
		match_baselen = basedir_len(paths[0]);
	read_tree_recursive(commit->tree, "", 0, 0, paths, walk_tree, NULL);
	if (!match)
		html_status(404, "Not found", 0);
	else if (match == 2)
		print_dir_tail();
}
예제 #2
0
파일: ui-plain.c 프로젝트: ifzz/cgit
void cgit_print_plain(void)
{
	const char *rev = ctx.qry.sha1;
	unsigned char sha1[20];
	struct commit *commit;
	struct pathspec_item path_items = {
		.match = ctx.qry.path,
		.len = ctx.qry.path ? strlen(ctx.qry.path) : 0
	};
	struct pathspec paths = {
		.nr = 1,
		.items = &path_items
	};
	struct walk_tree_context walk_tree_ctx = {
		.match = 0
	};

	if (!rev)
		rev = ctx.qry.head;

	if (get_sha1(rev, sha1)) {
		cgit_print_error_page(404, "Not found", "Not found");
		return;
	}
	commit = lookup_commit_reference(sha1);
	if (!commit || parse_commit(commit)) {
		cgit_print_error_page(404, "Not found", "Not found");
		return;
	}
	if (!path_items.match) {
		path_items.match = "";
		walk_tree_ctx.match_baselen = -1;
		print_dir(commit->tree->object.sha1, "", 0, "");
		walk_tree_ctx.match = 2;
	}
	else
		walk_tree_ctx.match_baselen = basedir_len(path_items.match);
	read_tree_recursive(commit->tree, "", 0, 0, &paths, walk_tree, &walk_tree_ctx);
	if (!walk_tree_ctx.match)
		cgit_print_error_page(404, "Not found", "Not found");
	else if (walk_tree_ctx.match == 2)
		print_dir_tail();
}