@@ -61,12 +61,15 @@ static void process_tree(struct rev_info *revs,
61
61
struct tree * tree ,
62
62
show_object_fn show ,
63
63
struct name_path * path ,
64
+ struct strbuf * base ,
64
65
const char * name )
65
66
{
66
67
struct object * obj = & tree -> object ;
67
68
struct tree_desc desc ;
68
69
struct name_entry entry ;
69
70
struct name_path me ;
71
+ int all_interesting = (revs -> diffopt .pathspec .nr == 0 );
72
+ int baselen = base -> len ;
70
73
71
74
if (!revs -> tree_objects )
72
75
return ;
@@ -82,13 +85,32 @@ static void process_tree(struct rev_info *revs,
82
85
me .elem = name ;
83
86
me .elem_len = strlen (name );
84
87
88
+ if (!all_interesting ) {
89
+ strbuf_addstr (base , name );
90
+ if (base -> len )
91
+ strbuf_addch (base , '/' );
92
+ }
93
+
85
94
init_tree_desc (& desc , tree -> buffer , tree -> size );
86
95
87
96
while (tree_entry (& desc , & entry )) {
97
+ if (!all_interesting ) {
98
+ int showit = tree_entry_interesting (& entry ,
99
+ base , 0 ,
100
+ & revs -> diffopt .pathspec );
101
+
102
+ if (showit < 0 )
103
+ break ;
104
+ else if (!showit )
105
+ continue ;
106
+ else if (showit == 2 )
107
+ all_interesting = 1 ;
108
+ }
109
+
88
110
if (S_ISDIR (entry .mode ))
89
111
process_tree (revs ,
90
112
lookup_tree (entry .sha1 ),
91
- show , & me , entry .path );
113
+ show , & me , base , entry .path );
92
114
else if (S_ISGITLINK (entry .mode ))
93
115
process_gitlink (revs , entry .sha1 ,
94
116
show , & me , entry .path );
@@ -97,6 +119,7 @@ static void process_tree(struct rev_info *revs,
97
119
lookup_blob (entry .sha1 ),
98
120
show , & me , entry .path );
99
121
}
122
+ strbuf_setlen (base , baselen );
100
123
free (tree -> buffer );
101
124
tree -> buffer = NULL ;
102
125
}
@@ -146,7 +169,9 @@ void traverse_commit_list(struct rev_info *revs,
146
169
{
147
170
int i ;
148
171
struct commit * commit ;
172
+ struct strbuf base ;
149
173
174
+ strbuf_init (& base , PATH_MAX );
150
175
while ((commit = get_revision (revs )) != NULL ) {
151
176
add_pending_tree (revs , commit -> tree );
152
177
show_commit (commit , data );
@@ -164,7 +189,7 @@ void traverse_commit_list(struct rev_info *revs,
164
189
}
165
190
if (obj -> type == OBJ_TREE ) {
166
191
process_tree (revs , (struct tree * )obj , show_object ,
167
- NULL , name );
192
+ NULL , & base , name );
168
193
continue ;
169
194
}
170
195
if (obj -> type == OBJ_BLOB ) {
@@ -181,4 +206,5 @@ void traverse_commit_list(struct rev_info *revs,
181
206
revs -> pending .alloc = 0 ;
182
207
revs -> pending .objects = NULL ;
183
208
}
209
+ strbuf_release (& base );
184
210
}
0 commit comments