Skip to content

Commit a0c9016

Browse files
jonathantanmygitster
authored andcommitted
upload-pack: send refs' objects despite "filter"
A filter line in a request to upload-pack filters out objects regardless of whether they are directly referenced by a "want" line or not. This means that cloning with "--filter=blob:none" (or another filter that excludes blobs) from a repository with at least one ref pointing to a blob (for example, the Git repository itself) results in output like the following: error: missing object referenced by 'refs/tags/junio-gpg-pub' and if that particular blob is not referenced by a fetched tree, the resulting clone fails fsck because there is no object from the remote to vouch that the missing object is a promisor object. Update both the protocol and the upload-pack implementation to include all explicitly specified "want" objects in the packfile regardless of the filter specification. Signed-off-by: Jonathan Tan <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent cf1e7c0 commit a0c9016

File tree

7 files changed

+42
-6
lines changed

7 files changed

+42
-6
lines changed

Documentation/technical/pack-protocol.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,9 @@ information is sent back to the client in the next step.
284284
The client can optionally request that pack-objects omit various
285285
objects from the packfile using one of several filtering techniques.
286286
These are intended for use with partial clone and partial fetch
287-
operations. See `rev-list` for possible "filter-spec" values.
287+
operations. An object that does not meet a filter-spec value is
288+
omitted unless explicitly requested in a 'want' line. See `rev-list`
289+
for possible filter-spec values.
288290

289291
Once all the 'want's and 'shallow's (and optional 'deepen') are
290292
transferred, clients MUST send a flush-pkt, to tell the server side

list-objects.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ static void process_blob(struct rev_info *revs,
4747

4848
pathlen = path->len;
4949
strbuf_addstr(path, name);
50-
if (filter_fn)
50+
if (!(obj->flags & USER_GIVEN) && filter_fn)
5151
r = filter_fn(LOFS_BLOB, obj,
5252
path->buf, &path->buf[pathlen],
5353
filter_data);
@@ -132,7 +132,7 @@ static void process_tree(struct rev_info *revs,
132132
}
133133

134134
strbuf_addstr(base, name);
135-
if (filter_fn)
135+
if (!(obj->flags & USER_GIVEN) && filter_fn)
136136
r = filter_fn(LOFS_BEGIN_TREE, obj,
137137
base->buf, &base->buf[baselen],
138138
filter_data);
@@ -171,7 +171,7 @@ static void process_tree(struct rev_info *revs,
171171
cb_data, filter_fn, filter_data);
172172
}
173173

174-
if (filter_fn) {
174+
if (!(obj->flags & USER_GIVEN) && filter_fn) {
175175
r = filter_fn(LOFS_END_TREE, obj,
176176
base->buf, &base->buf[baselen],
177177
filter_data);

object.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ struct object_array {
2727

2828
/*
2929
* object flag allocation:
30-
* revision.h: 0---------10 26
30+
* revision.h: 0---------10 2526
3131
* fetch-pack.c: 0----5
3232
* walker.c: 0-2
3333
* upload-pack.c: 4 11----------------19

revision.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ static void add_pending_object_with_path(struct rev_info *revs,
172172
strbuf_release(&buf);
173173
return; /* do not add the commit itself */
174174
}
175+
obj->flags |= USER_GIVEN;
175176
add_object_array_with_path(obj, name, &revs->pending, mode, path);
176177
}
177178

revision.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@
1919
#define SYMMETRIC_LEFT (1u<<8)
2020
#define PATCHSAME (1u<<9)
2121
#define BOTTOM (1u<<10)
22+
#define USER_GIVEN (1u<<25) /* given directly by the user */
2223
#define TRACK_LINEAR (1u<<26)
23-
#define ALL_REV_FLAGS (((1u<<11)-1) | TRACK_LINEAR)
24+
#define ALL_REV_FLAGS (((1u<<11)-1) | USER_GIVEN | TRACK_LINEAR)
2425

2526
#define DECORATE_SHORT_REFS 1
2627
#define DECORATE_FULL_REFS 2

t/t5317-pack-objects-filter-objects.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,22 @@ test_expect_success 'verify blob:limit=1k' '
160160
test_cmp observed expected
161161
'
162162

163+
test_expect_success 'verify explicitly specifying oversized blob in input' '
164+
git -C r2 ls-files -s large.1000 large.10000 \
165+
| awk -f print_2.awk \
166+
| sort >expected &&
167+
git -C r2 pack-objects --rev --stdout --filter=blob:limit=1k >filter.pack <<-EOF &&
168+
HEAD
169+
$(git -C r2 rev-parse HEAD:large.10000)
170+
EOF
171+
git -C r2 index-pack ../filter.pack &&
172+
git -C r2 verify-pack -v ../filter.pack \
173+
| grep blob \
174+
| awk -f print_1.awk \
175+
| sort >observed &&
176+
test_cmp observed expected
177+
'
178+
163179
test_expect_success 'verify blob:limit=1m' '
164180
git -C r2 ls-files -s large.1000 large.10000 \
165181
| awk -f print_2.awk \

t/t5616-partial-clone.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,4 +154,20 @@ test_expect_success 'partial clone with transfer.fsckobjects=1 uses index-pack -
154154
grep "git index-pack.*--fsck-objects" trace
155155
'
156156

157+
test_expect_success 'partial clone fetches blobs pointed to by refs even if normally filtered out' '
158+
rm -rf src dst &&
159+
git init src &&
160+
test_commit -C src x &&
161+
test_config -C src uploadpack.allowfilter 1 &&
162+
test_config -C src uploadpack.allowanysha1inwant 1 &&
163+
164+
# Create a tag pointing to a blob.
165+
BLOB=$(echo blob-contents | git -C src hash-object --stdin -w) &&
166+
git -C src tag myblob "$BLOB" &&
167+
168+
git clone --filter="blob:none" "file://$(pwd)/src" dst 2>err &&
169+
! grep "does not point to a valid object" err &&
170+
git -C dst fsck
171+
'
172+
157173
test_done

0 commit comments

Comments
 (0)