Skip to content

Commit 99c9aa9

Browse files
matvoregitster
authored andcommitted
revision: mark non-user-given objects instead
Currently, list-objects.c incorrectly treats all root trees of commits as USER_GIVEN. Also, it would be easier to mark objects that are non-user-given instead of user-given, since the places in the code where we access an object through a reference are more obvious than the places where we access an object that was given by the user. Resolve these two problems by introducing a flag NOT_USER_GIVEN that marks blobs and trees that are non-user-given, replacing USER_GIVEN. (Only blobs and trees are marked because this mark is only used when filtering objects, and filtering of other types of objects is not supported yet.) This fixes a bug in that git rev-list behaved differently from git pack-objects. pack-objects would *not* filter objects given explicitly on the command line and rev-list would filter. This was because the two commands used a different function to add objects to the rev_info struct. This seems to have been an oversight, and pack-objects has the correct behavior, so I added a test to make sure that rev-list now behaves properly. Signed-off-by: Matthew DeVore <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7c0fe33 commit 99c9aa9

File tree

4 files changed

+39
-16
lines changed

4 files changed

+39
-16
lines changed

list-objects.c

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ static void process_blob(struct traversal_context *ctx,
5353

5454
pathlen = path->len;
5555
strbuf_addstr(path, name);
56-
if (!(obj->flags & USER_GIVEN) && ctx->filter_fn)
56+
if ((obj->flags & NOT_USER_GIVEN) && ctx->filter_fn)
5757
r = ctx->filter_fn(LOFS_BLOB, obj,
5858
path->buf, &path->buf[pathlen],
5959
ctx->filter_data);
@@ -120,17 +120,19 @@ static void process_tree_contents(struct traversal_context *ctx,
120120
continue;
121121
}
122122

123-
if (S_ISDIR(entry.mode))
124-
process_tree(ctx,
125-
lookup_tree(the_repository, entry.oid),
126-
base, entry.path);
123+
if (S_ISDIR(entry.mode)) {
124+
struct tree *t = lookup_tree(the_repository, entry.oid);
125+
t->object.flags |= NOT_USER_GIVEN;
126+
process_tree(ctx, t, base, entry.path);
127+
}
127128
else if (S_ISGITLINK(entry.mode))
128129
process_gitlink(ctx, entry.oid->hash,
129130
base, entry.path);
130-
else
131-
process_blob(ctx,
132-
lookup_blob(the_repository, entry.oid),
133-
base, entry.path);
131+
else {
132+
struct blob *b = lookup_blob(the_repository, entry.oid);
133+
b->object.flags |= NOT_USER_GIVEN;
134+
process_blob(ctx, b, base, entry.path);
135+
}
134136
}
135137
}
136138

@@ -171,7 +173,7 @@ static void process_tree(struct traversal_context *ctx,
171173
}
172174

173175
strbuf_addstr(base, name);
174-
if (!(obj->flags & USER_GIVEN) && ctx->filter_fn)
176+
if ((obj->flags & NOT_USER_GIVEN) && ctx->filter_fn)
175177
r = ctx->filter_fn(LOFS_BEGIN_TREE, obj,
176178
base->buf, &base->buf[baselen],
177179
ctx->filter_data);
@@ -185,7 +187,7 @@ static void process_tree(struct traversal_context *ctx,
185187
if (!failed_parse)
186188
process_tree_contents(ctx, tree, base);
187189

188-
if (!(obj->flags & USER_GIVEN) && ctx->filter_fn) {
190+
if ((obj->flags & NOT_USER_GIVEN) && ctx->filter_fn) {
189191
r = ctx->filter_fn(LOFS_END_TREE, obj,
190192
base->buf, &base->buf[baselen],
191193
ctx->filter_data);
@@ -301,8 +303,11 @@ static void do_traverse(struct traversal_context *ctx)
301303
* an uninteresting boundary commit may not have its tree
302304
* parsed yet, but we are not going to show them anyway
303305
*/
304-
if (get_commit_tree(commit))
305-
add_pending_tree(ctx->revs, get_commit_tree(commit));
306+
if (get_commit_tree(commit)) {
307+
struct tree *tree = get_commit_tree(commit);
308+
tree->object.flags |= NOT_USER_GIVEN;
309+
add_pending_tree(ctx->revs, tree);
310+
}
306311
ctx->show_commit(commit, ctx->show_data);
307312

308313
if (ctx->revs->tree_blobs_in_commit_order)

revision.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,6 @@ static void add_pending_object_with_path(struct rev_info *revs,
175175
strbuf_release(&buf);
176176
return; /* do not add the commit itself */
177177
}
178-
obj->flags |= USER_GIVEN;
179178
add_object_array_with_path(obj, name, &revs->pending, mode, path);
180179
}
181180

revision.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,16 @@
2020
#define SYMMETRIC_LEFT (1u<<8)
2121
#define PATCHSAME (1u<<9)
2222
#define BOTTOM (1u<<10)
23-
#define USER_GIVEN (1u<<25) /* given directly by the user */
23+
/*
24+
* Indicates object was reached by traversal. i.e. not given by user on
25+
* command-line or stdin.
26+
* NEEDSWORK: NOT_USER_GIVEN doesn't apply to commits because we only support
27+
* filtering trees and blobs, but it may be useful to support filtering commits
28+
* in the future.
29+
*/
30+
#define NOT_USER_GIVEN (1u<<25)
2431
#define TRACK_LINEAR (1u<<26)
25-
#define ALL_REV_FLAGS (((1u<<11)-1) | USER_GIVEN | TRACK_LINEAR)
32+
#define ALL_REV_FLAGS (((1u<<11)-1) | NOT_USER_GIVEN | TRACK_LINEAR)
2633

2734
#define DECORATE_SHORT_REFS 1
2835
#define DECORATE_FULL_REFS 2

t/t6112-rev-list-filters-objects.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,18 @@ test_expect_success 'verify blob:none omits all 5 blobs' '
3030
test_cmp observed expected
3131
'
3232

33+
test_expect_success 'specify blob explicitly prevents filtering' '
34+
file_3=$(git -C r1 ls-files -s file.3 |
35+
awk -f print_2.awk) &&
36+
37+
file_4=$(git -C r1 ls-files -s file.4 |
38+
awk -f print_2.awk) &&
39+
40+
git -C r1 rev-list --objects --filter=blob:none HEAD $file_3 >observed &&
41+
grep -q "$file_3" observed &&
42+
test_must_fail grep -q "$file_4" observed
43+
'
44+
3345
test_expect_success 'verify emitted+omitted == all' '
3446
git -C r1 rev-list HEAD --objects \
3547
| awk -f print_1.awk \

0 commit comments

Comments
 (0)