Skip to content

Commit 9a2a4f9

Browse files
pks-tgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 628d81b commit 9a2a4f9

File tree

3 files changed

+62
-3
lines changed

3 files changed

+62
-3
lines changed

list-objects-filter.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,16 @@ static enum list_objects_filter_result filter_blobs_none(
8282
default:
8383
BUG("unknown filter_situation: %d", filter_situation);
8484

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+
8595
case LOFS_BEGIN_TREE:
8696
assert(obj->type == OBJ_TREE);
8797
/* always include all tree objects */
@@ -173,6 +183,16 @@ static enum list_objects_filter_result filter_trees_depth(
173183
default:
174184
BUG("unknown filter_situation: %d", filter_situation);
175185

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;
195+
176196
case LOFS_END_TREE:
177197
assert(obj->type == OBJ_TREE);
178198
filter_data->current_depth--;
@@ -267,6 +287,16 @@ static enum list_objects_filter_result filter_blobs_limit(
267287
default:
268288
BUG("unknown filter_situation: %d", filter_situation);
269289

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+
270300
case LOFS_BEGIN_TREE:
271301
assert(obj->type == OBJ_TREE);
272302
/* always include all tree objects */
@@ -371,6 +401,16 @@ static enum list_objects_filter_result filter_sparse(
371401
default:
372402
BUG("unknown filter_situation: %d", filter_situation);
373403

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;
413+
374414
case LOFS_BEGIN_TREE:
375415
assert(obj->type == OBJ_TREE);
376416
dtype = DT_DIR;

list-objects-filter.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ enum list_objects_filter_result {
5555
};
5656

5757
enum list_objects_filter_situation {
58+
LOFS_COMMIT,
59+
LOFS_TAG,
5860
LOFS_BEGIN_TREE,
5961
LOFS_END_TREE,
6062
LOFS_BLOB

list-objects.c

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,15 @@ static void process_tag(struct traversal_context *ctx,
217217
struct tag *tag,
218218
const char *name)
219219
{
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);
222229
}
223230

224231
static void mark_edge_parents_uninteresting(struct commit *commit,
@@ -368,6 +375,12 @@ static void do_traverse(struct traversal_context *ctx)
368375
strbuf_init(&csp, PATH_MAX);
369376

370377
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+
371384
/*
372385
* an uninteresting boundary commit may not have its tree
373386
* parsed yet, but we are not going to show them anyway
@@ -382,7 +395,11 @@ static void do_traverse(struct traversal_context *ctx)
382395
die(_("unable to load root tree for commit %s"),
383396
oid_to_hex(&commit->object.oid));
384397
}
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);
386403

387404
if (ctx->revs->tree_blobs_in_commit_order)
388405
/*

0 commit comments

Comments
 (0)