[PATCH 1/2] Update to use pathspec in read_tree_recursive calls
Dan McGee
dpmcgee at gmail.com
Thu Jun 2 21:01:12 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>
---
These aren't needed right away, but thought I'd save anyone the trouble going
forward moving to a newer version of git. These have been working for me for a
week or so.
shared.c | 10 +++++-----
ui-blob.c | 16 +++++++++++-----
ui-tree.c | 10 ++++++++--
3 files changed, 24 insertions(+), 12 deletions(-)
diff --git a/shared.c b/shared.c
index be2ae59..8316bfd 100644
--- a/shared.c
+++ b/shared.c
@@ -305,7 +305,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;
@@ -317,10 +316,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);
@@ -330,6 +329,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-tree.c b/ui-tree.c
index 2d8d2f3..1f18c21 100644
--- a/ui-tree.c
+++ b/ui-tree.c
@@ -207,6 +207,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) {
@@ -216,7 +217,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();
}
@@ -257,6 +260,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)
@@ -279,6 +283,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