[PATCH] Update to use pathspec in read_tree_recursive calls

Dan McGee dpmcgee at gmail.com
Thu Jun 16 16:46:44 CEST 2011


This is needed after commit f0096c06 in the git.git repo (a post 1.7.4
change).

Signed-off-by: Dan McGee <dpmcgee at gmail.com>
---

This updates the previously sent patch for the read_tree_recursive() call in
ui-plain.c.

 shared.c   |   10 +++++-----
 ui-blob.c  |   16 +++++++++++-----
 ui-plain.c |    5 ++++-
 ui-tree.c  |   10 ++++++++--
 4 files changed, 28 insertions(+), 13 deletions(-)

diff --git a/shared.c b/shared.c
index 0add2e5..ddbb217 100644
--- a/shared.c
+++ b/shared.c
@@ -307,7 +307,6 @@ void cgit_diff_tree(const unsigned char *old_sha1,
 		    filepair_fn fn, const char *prefix, int ignorews)
 {
 	struct diff_options opt;
-	int prefixlen;
 
 	diff_setup(&opt);
 	opt.output_format = DIFF_FORMAT_CALLBACK;
@@ -319,10 +318,10 @@ void cgit_diff_tree(const unsigned char *old_sha1,
 	opt.format_callback = cgit_diff_tree_cb;
 	opt.format_callback_data = fn;
 	if (prefix) {
-		opt.nr_paths = 1;
-		opt.paths = &prefix;
-		prefixlen = strlen(prefix);
-		opt.pathlens = &prefixlen;
+		const char *paths[] = {prefix, NULL};
+		init_pathspec(&opt.pathspec, paths);
+	} else {
+		init_pathspec(&opt.pathspec, NULL);
 	}
 	diff_setup_done(&opt);
 
@@ -332,6 +331,7 @@ void cgit_diff_tree(const unsigned char *old_sha1,
 		diff_root_tree_sha1(new_sha1, "", &opt);
 	diffcore_std(&opt);
 	diff_flush(&opt);
+	free_pathspec(&opt.pathspec);
 }
 
 void cgit_diff_commit(struct commit *commit, filepair_fn fn, const char *prefix)
diff --git a/ui-blob.c b/ui-blob.c
index ec435e1..f3b0d0d 100644
--- a/ui-blob.c
+++ b/ui-blob.c
@@ -32,16 +32,19 @@ int cgit_print_file(char *path, const char *head)
 	char *buf;
 	unsigned long size;
 	struct commit *commit;
-	const char *paths[] = {path, NULL};
 	if (get_sha1(head, sha1))
 		return -1;
 	type = sha1_object_info(sha1, &size);
 	if(type == OBJ_COMMIT && path) {
+		struct pathspec pathspec;
+		const char *paths[] = {path, NULL};
 		commit = lookup_commit_reference(sha1);
 		match_path = path;
 		matched_sha1 = sha1;
 		found_path = 0;
-		read_tree_recursive(commit->tree, "", 0, 0, paths, walk_tree, NULL);
+		init_pathspec(&pathspec, paths);
+		read_tree_recursive(commit->tree, "", 0, 0, &pathspec, walk_tree, NULL);
+		free_pathspec(&pathspec);
 		if (!found_path)
 			return -1;
 		type = sha1_object_info(sha1, &size);
@@ -63,7 +66,6 @@ void cgit_print_blob(const char *hex, char *path, const char *head)
 	char *buf;
 	unsigned long size;
 	struct commit *commit;
-	const char *paths[] = {path, NULL};
 
 	if (hex) {
 		if (get_sha1_hex(hex, sha1)){
@@ -80,11 +82,15 @@ void cgit_print_blob(const char *hex, char *path, const char *head)
 	type = sha1_object_info(sha1, &size);
 
 	if((!hex) && type == OBJ_COMMIT && path) {
+		struct pathspec pathspec;
+		const char *paths[] = {path, NULL};
 		commit = lookup_commit_reference(sha1);
 		match_path = path;
 		matched_sha1 = sha1;
-		read_tree_recursive(commit->tree, "", 0, 0, paths, walk_tree, NULL);
-		type = sha1_object_info(sha1,&size);
+		init_pathspec(&pathspec, paths);
+		read_tree_recursive(commit->tree, "", 0, 0, &pathspec, walk_tree, NULL);
+		free_pathspec(&pathspec);
+		type = sha1_object_info(sha1, &size);
 	}
 
 	if (type == OBJ_BAD) {
diff --git a/ui-plain.c b/ui-plain.c
index 2abd210..1fc44cc 100644
--- a/ui-plain.c
+++ b/ui-plain.c
@@ -147,6 +147,7 @@ void cgit_print_plain(struct cgit_context *ctx)
 	const char *rev = ctx->qry.sha1;
 	unsigned char sha1[20];
 	struct commit *commit;
+	struct pathspec pathspec;
 	const char *paths[] = {ctx->qry.path, NULL};
 
 	if (!rev)
@@ -168,7 +169,9 @@ void cgit_print_plain(struct cgit_context *ctx)
 	}
 	else
 		match_baselen = basedir_len(paths[0]);
-	read_tree_recursive(commit->tree, "", 0, 0, paths, walk_tree, NULL);
+	init_pathspec(&pathspec, paths);
+	read_tree_recursive(commit->tree, "", 0, 0, &pathspec, walk_tree, NULL);
+	free_pathspec(&pathspec);
 	if (!match)
 		html_status(404, "Not found", 0);
 	else if (match == 2)
diff --git a/ui-tree.c b/ui-tree.c
index b1adcc7..a799556 100644
--- a/ui-tree.c
+++ b/ui-tree.c
@@ -202,6 +202,7 @@ static void ls_tail()
 static void ls_tree(const unsigned char *sha1, char *path)
 {
 	struct tree *tree;
+	struct pathspec pathspec;
 
 	tree = parse_tree_indirect(sha1);
 	if (!tree) {
@@ -211,7 +212,9 @@ static void ls_tree(const unsigned char *sha1, char *path)
 	}
 
 	ls_head();
-	read_tree_recursive(tree, "", 0, 1, NULL, ls_item, NULL);
+	init_pathspec(&pathspec, NULL);
+	read_tree_recursive(tree, "", 0, 1, &pathspec, ls_item, NULL);
+	free_pathspec(&pathspec);
 	ls_tail();
 }
 
@@ -252,6 +255,7 @@ void cgit_print_tree(const char *rev, char *path)
 {
 	unsigned char sha1[20];
 	struct commit *commit;
+	struct pathspec pathspec;
 	const char *paths[] = {path, NULL};
 
 	if (!rev)
@@ -274,6 +278,8 @@ void cgit_print_tree(const char *rev, char *path)
 	}
 
 	match_path = path;
-	read_tree_recursive(commit->tree, "", 0, 0, paths, walk_tree, NULL);
+	init_pathspec(&pathspec, paths);
+	read_tree_recursive(commit->tree, "", 0, 0, &pathspec, walk_tree, NULL);
+	free_pathspec(&pathspec);
 	ls_tail();
 }
-- 
1.7.5.2





More information about the CGit mailing list