@@ -84,6 +84,10 @@ static int add_children(struct path_walk_context *ctx,
8484 if (S_ISGITLINK (entry .mode ))
8585 continue ;
8686
87+ /* If the caller doesn't want blobs, then don't bother. */
88+ if (!ctx -> info -> blobs && type == OBJ_BLOB )
89+ continue ;
90+
8791 if (type == OBJ_TREE ) {
8892 struct tree * child = lookup_tree (ctx -> repo , & entry .oid );
8993 o = child ? & child -> object : NULL ;
@@ -140,9 +144,11 @@ static int walk_path(struct path_walk_context *ctx,
140144
141145 list = strmap_get (& ctx -> paths_to_lists , path );
142146
143- /* Evaluate function pointer on this data. */
144- ret = ctx -> info -> path_fn (path , & list -> oids , list -> type ,
145- ctx -> info -> path_fn_data );
147+ /* Evaluate function pointer on this data, if requested. */
148+ if ((list -> type == OBJ_TREE && ctx -> info -> trees ) ||
149+ (list -> type == OBJ_BLOB && ctx -> info -> blobs ))
150+ ret = ctx -> info -> path_fn (path , & list -> oids , list -> type ,
151+ ctx -> info -> path_fn_data );
146152
147153 /* Expand data for children. */
148154 if (list -> type == OBJ_TREE ) {
@@ -184,6 +190,7 @@ int walk_objects_by_path(struct path_walk_info *info)
184190 size_t commits_nr = 0 , paths_nr = 0 ;
185191 struct commit * c ;
186192 struct type_and_oid_list * root_tree_list ;
193+ struct type_and_oid_list * commit_list ;
187194 struct path_walk_context ctx = {
188195 .repo = info -> revs -> repo ,
189196 .revs = info -> revs ,
@@ -194,19 +201,32 @@ int walk_objects_by_path(struct path_walk_info *info)
194201
195202 trace2_region_enter ("path-walk" , "commit-walk" , info -> revs -> repo );
196203
204+ CALLOC_ARRAY (commit_list , 1 );
205+ commit_list -> type = OBJ_COMMIT ;
206+
197207 /* Insert a single list for the root tree into the paths. */
198208 CALLOC_ARRAY (root_tree_list , 1 );
199209 root_tree_list -> type = OBJ_TREE ;
200210 strmap_put (& ctx .paths_to_lists , root_path , root_tree_list );
201-
202211 if (prepare_revision_walk (info -> revs ))
203212 die (_ ("failed to setup revision walk" ));
204213
205214 while ((c = get_revision (info -> revs ))) {
206- struct object_id * oid = get_commit_tree_oid ( c ) ;
207- struct tree * t = lookup_tree ( info -> revs -> repo , oid ) ;
215+ struct object_id * oid ;
216+ struct tree * t ;
208217 commits_nr ++ ;
209218
219+ if (info -> commits )
220+ oid_array_append (& commit_list -> oids ,
221+ & c -> object .oid );
222+
223+ /* If we only care about commits, then skip trees. */
224+ if (!info -> trees && !info -> blobs )
225+ continue ;
226+
227+ oid = get_commit_tree_oid (c );
228+ t = lookup_tree (info -> revs -> repo , oid );
229+
210230 if (t )
211231 oid_array_append (& root_tree_list -> oids , oid );
212232 else
@@ -216,6 +236,13 @@ int walk_objects_by_path(struct path_walk_info *info)
216236 trace2_data_intmax ("path-walk" , ctx .repo , "commits" , commits_nr );
217237 trace2_region_leave ("path-walk" , "commit-walk" , info -> revs -> repo );
218238
239+ /* Track all commits. */
240+ if (info -> commits )
241+ ret = info -> path_fn ("" , & commit_list -> oids , OBJ_COMMIT ,
242+ info -> path_fn_data );
243+ oid_array_clear (& commit_list -> oids );
244+ free (commit_list );
245+
219246 string_list_append (& ctx .path_stack , root_path );
220247
221248 trace2_region_enter ("path-walk" , "path-walk" , info -> revs -> repo );
0 commit comments