tree-diff: do not assume we use only one pathspec
The way tree-diff was set up assumed we would use only one set of pathspec during the entire life of the program. Move the pathspec related static variables out to diff_options structure so that we can filter commits with one set of paths while show the actual diffs using different set of paths. I suspect this breaks blame.c, and makes "git log paths..." to default to the --full-diff, the latter of which is dealt with the next commit. Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Apr 10, 2006 at 16:39 UTC
a8baa7b9f5c8e338c09d63097f14372aca68e13f
4 files changed
+32
-24
diff-tree.c
+1
-1
@@ -120,7 +120,7 @@ int main(int argc, const char **argv)
120
if (opt->diffopt.output_format == DIFF_FORMAT_PATCH)
121
opt->diffopt.recursive = 1;
122
123
- diff_tree_setup_paths(get_pathspec(prefix, argv));
123
+ diff_tree_setup_paths(get_pathspec(prefix, argv), opt);
124
diff_setup_done(&opt->diffopt);
125
126
switch (nr_sha1) {
diff.h
+5
-1
@@ -38,11 +38,15 @@ struct diff_options {
38
int setup;
39
int abbrev;
40
41
+ int nr_paths;
42
+ const char **paths;
43
+ int *pathlens;
44
change_fn_t change;
45
add_remove_fn_t add_remove;
46
};
47
45
-extern void diff_tree_setup_paths(const char **paths);
48
+extern void diff_tree_setup_paths(const char **paths, struct diff_options *);
49
+extern void diff_tree_release_paths(struct diff_options *);
50
extern int diff_tree(struct tree_desc *t1, struct tree_desc *t2,
51
const char *base, struct diff_options *opt);
52
extern int diff_tree_sha1(const unsigned char *old, const unsigned char *new,
revision.c
+1
-1
@@ -707,7 +707,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch
707
revs->limited = 1;
708
709
if (revs->prune_data) {
710
- diff_tree_setup_paths(revs->prune_data);
710
+ diff_tree_setup_paths(revs->prune_data, &diff_opt);
711
revs->prune_fn = try_to_simplify_commit;
712
}
713
tree-diff.c
+25
-21
@@ -5,11 +5,6 @@
5
#include "diff.h"
6
#include "tree.h"
7
8
-// What paths are we interested in?
9
-static int nr_paths = 0;
10
-static const char **paths = NULL;
11
-static int *pathlens = NULL;
12
-
8
static char *malloc_base(const char *base, const char *path, int pathlen)
9
{
10
int baselen = strlen(base);
@@ -72,14 +67,14 @@ static int compare_tree_entry(struct tree_desc *t1, struct tree_desc *t2, const
67
return 0;
68
}
69
75
-static int interesting(struct tree_desc *desc, const char *base)
70
+static int interesting(struct tree_desc *desc, const char *base, struct diff_options *opt)
71
{
72
const char *path;
73
unsigned mode;
74
int i;
75
int baselen, pathlen;
76
82
- if (!nr_paths)
77
+ if (!opt->nr_paths)
78
return 1;
79
80
(void)tree_entry_extract(desc, &path, &mode);
@@ -87,9 +82,9 @@ static int interesting(struct tree_desc *desc, const char *base)
82
pathlen = strlen(path);
83
baselen = strlen(base);
84
90
- for (i=0; i < nr_paths; i++) {
91
- const char *match = paths[i];
92
- int matchlen = pathlens[i];
85
+ for (i=0; i < opt->nr_paths; i++) {
86
+ const char *match = opt->paths[i];
87
+ int matchlen = opt->pathlens[i];
88
89
if (baselen >= matchlen) {
90
/* If it doesn't match, move along... */
@@ -129,7 +124,7 @@ static int interesting(struct tree_desc *desc, const char *base)
124
static void show_tree(struct diff_options *opt, const char *prefix, struct tree_desc *desc, const char *base)
125
{
126
while (desc->size) {
132
- if (interesting(desc, base))
127
+ if (interesting(desc, base, opt))
128
show_entry(opt, prefix, desc, base);
129
update_tree_entry(desc);
130
}
@@ -167,11 +162,11 @@ static int show_entry(struct diff_options *opt, const char *prefix, struct tree_
162
int diff_tree(struct tree_desc *t1, struct tree_desc *t2, const char *base, struct diff_options *opt)
163
{
164
while (t1->size | t2->size) {
170
- if (nr_paths && t1->size && !interesting(t1, base)) {
165
+ if (opt->nr_paths && t1->size && !interesting(t1, base, opt)) {
166
update_tree_entry(t1);
167
continue;
168
}
174
- if (nr_paths && t2->size && !interesting(t2, base)) {
169
+ if (opt->nr_paths && t2->size && !interesting(t2, base, opt)) {
170
update_tree_entry(t2);
171
continue;
172
}
@@ -229,19 +224,28 @@ static int count_paths(const char **paths)
224
return i;
225
}
226
232
-void diff_tree_setup_paths(const char **p)
227
+void diff_tree_release_paths(struct diff_options *opt)
228
{
229
+ free(opt->pathlens);
230
+}
231
+
232
+void diff_tree_setup_paths(const char **p, struct diff_options *opt)
233
+{
234
+ opt->nr_paths = 0;
235
+ opt->pathlens = NULL;
236
+ opt->paths = NULL;
237
+
238
if (p) {
239
int i;
240
237
- paths = p;
238
- nr_paths = count_paths(paths);
239
- if (nr_paths == 0) {
240
- pathlens = NULL;
241
+ opt->paths = p;
242
+ opt->nr_paths = count_paths(p);
243
+ if (opt->nr_paths == 0) {
244
+ opt->pathlens = NULL;
245
return;
246
}
243
- pathlens = xmalloc(nr_paths * sizeof(int));
244
- for (i=0; i<nr_paths; i++)
245
- pathlens[i] = strlen(paths[i]);
247
+ opt->pathlens = xmalloc(opt->nr_paths * sizeof(int));
248
+ for (i=0; i < opt->nr_paths; i++)
249
+ opt->pathlens[i] = strlen(p[i]);
250
}
251
}