Git fork

list-objects: support filtering by tag and commit

Object filters currently only support filtering blobs or trees based on
some criteria. This commit lays the foundation to also allow filtering
of tags and commits.

No change in behaviour is expected from this commit given that there are
no filters yet for those object types.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

authored by

Patrick Steinhardt and committed by
Junio C Hamano
9a2a4f95 628d81be

+62 -3
+40
list-objects-filter.c
··· 82 82 default: 83 83 BUG("unknown filter_situation: %d", filter_situation); 84 84 85 + case LOFS_TAG: 86 + assert(obj->type == OBJ_TAG); 87 + /* always include all tag objects */ 88 + return LOFR_MARK_SEEN | LOFR_DO_SHOW; 89 + 90 + case LOFS_COMMIT: 91 + assert(obj->type == OBJ_COMMIT); 92 + /* always include all commit objects */ 93 + return LOFR_MARK_SEEN | LOFR_DO_SHOW; 94 + 85 95 case LOFS_BEGIN_TREE: 86 96 assert(obj->type == OBJ_TREE); 87 97 /* always include all tree objects */ ··· 172 182 switch (filter_situation) { 173 183 default: 174 184 BUG("unknown filter_situation: %d", filter_situation); 185 + 186 + case LOFS_TAG: 187 + assert(obj->type == OBJ_TAG); 188 + /* always include all tag objects */ 189 + return LOFR_MARK_SEEN | LOFR_DO_SHOW; 190 + 191 + case LOFS_COMMIT: 192 + assert(obj->type == OBJ_COMMIT); 193 + /* always include all commit objects */ 194 + return LOFR_MARK_SEEN | LOFR_DO_SHOW; 175 195 176 196 case LOFS_END_TREE: 177 197 assert(obj->type == OBJ_TREE); ··· 267 287 default: 268 288 BUG("unknown filter_situation: %d", filter_situation); 269 289 290 + case LOFS_TAG: 291 + assert(obj->type == OBJ_TAG); 292 + /* always include all tag objects */ 293 + return LOFR_MARK_SEEN | LOFR_DO_SHOW; 294 + 295 + case LOFS_COMMIT: 296 + assert(obj->type == OBJ_COMMIT); 297 + /* always include all commit objects */ 298 + return LOFR_MARK_SEEN | LOFR_DO_SHOW; 299 + 270 300 case LOFS_BEGIN_TREE: 271 301 assert(obj->type == OBJ_TREE); 272 302 /* always include all tree objects */ ··· 370 400 switch (filter_situation) { 371 401 default: 372 402 BUG("unknown filter_situation: %d", filter_situation); 403 + 404 + case LOFS_TAG: 405 + assert(obj->type == OBJ_TAG); 406 + /* always include all tag objects */ 407 + return LOFR_MARK_SEEN | LOFR_DO_SHOW; 408 + 409 + case LOFS_COMMIT: 410 + assert(obj->type == OBJ_COMMIT); 411 + /* always include all commit objects */ 412 + return LOFR_MARK_SEEN | LOFR_DO_SHOW; 373 413 374 414 case LOFS_BEGIN_TREE: 375 415 assert(obj->type == OBJ_TREE);
+2
list-objects-filter.h
··· 55 55 }; 56 56 57 57 enum list_objects_filter_situation { 58 + LOFS_COMMIT, 59 + LOFS_TAG, 58 60 LOFS_BEGIN_TREE, 59 61 LOFS_END_TREE, 60 62 LOFS_BLOB
+20 -3
list-objects.c
··· 217 217 struct tag *tag, 218 218 const char *name) 219 219 { 220 - tag->object.flags |= SEEN; 221 - ctx->show_object(&tag->object, name, ctx->show_data); 220 + enum list_objects_filter_result r; 221 + 222 + r = list_objects_filter__filter_object(ctx->revs->repo, LOFS_TAG, 223 + &tag->object, NULL, NULL, 224 + ctx->filter); 225 + if (r & LOFR_MARK_SEEN) 226 + tag->object.flags |= SEEN; 227 + if (r & LOFR_DO_SHOW) 228 + ctx->show_object(&tag->object, name, ctx->show_data); 222 229 } 223 230 224 231 static void mark_edge_parents_uninteresting(struct commit *commit, ··· 368 375 strbuf_init(&csp, PATH_MAX); 369 376 370 377 while ((commit = get_revision(ctx->revs)) != NULL) { 378 + enum list_objects_filter_result r; 379 + 380 + r = list_objects_filter__filter_object(ctx->revs->repo, 381 + LOFS_COMMIT, &commit->object, 382 + NULL, NULL, ctx->filter); 383 + 371 384 /* 372 385 * an uninteresting boundary commit may not have its tree 373 386 * parsed yet, but we are not going to show them anyway ··· 382 395 die(_("unable to load root tree for commit %s"), 383 396 oid_to_hex(&commit->object.oid)); 384 397 } 385 - ctx->show_commit(commit, ctx->show_data); 398 + 399 + if (r & LOFR_MARK_SEEN) 400 + commit->object.flags |= SEEN; 401 + if (r & LOFR_DO_SHOW) 402 + ctx->show_commit(commit, ctx->show_data); 386 403 387 404 if (ctx->revs->tree_blobs_in_commit_order) 388 405 /*