Skip to content

Commit cfe8b6b

Browse files
RajivTSfacebook-github-bot
authored andcommitted
Fix bug in implementation of shallow in Mononoke Git server
Summary: As demonstrated in the previous diff, shallow clone of a submoduled repo can fail depending on the shallow boundary. This diff adds an explicit check before applying the size filter for the shallow boundary. If the object is in object is a submodule, do not perform the size check. Differential Revision: D71735051 fbshipit-source-id: 5dff655e87b05b82fb3b3909ee47bdf991922067
1 parent 6322bb8 commit cfe8b6b

3 files changed

Lines changed: 10 additions & 16 deletions

File tree

eden/mononoke/git/git_types/src/tree.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,9 @@ impl GitLeaf {
144144
}
145145

146146
pub(crate) async fn size(&self, ctx: &CoreContext, blobstore: &impl Blobstore) -> Result<u64> {
147+
if self.is_submodule() {
148+
anyhow::bail!("Fetching size of GitLeaf item that is a submodule is not supported");
149+
}
147150
let key = GitSha1::from_object_id(&self.0)?.into();
148151
let metadata = filestore::get_metadata(blobstore, ctx, &key)
149152
.await?

eden/mononoke/git/protocol/src/generator.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,11 @@ async fn boundary_trees_and_blobs(
106106
let objects = root_tree.list_all_entries((*ctx).clone(), blobstore.clone()).try_filter_map(|(path, entry)|{
107107
cloned!(ctx, blobstore, filter);
108108
async move {
109-
let size = entry.size(&ctx, &blobstore).await?;
109+
// If the entry is a submodule, then the concept of size does not apply. Assume 0 since it will be ignored anyway
110+
let size = match entry.is_submodule() {
111+
true => 0,
112+
false => entry.size(&ctx, &blobstore).await?
113+
};
110114
let kind = entry.kind();
111115
let oid = entry.oid();
112116
// If the entry corresponds to a submodules (and shows up as a commit), then we ignore it
@@ -121,7 +125,7 @@ async fn boundary_trees_and_blobs(
121125
.await
122126
.with_context(|| {
123127
format!(
124-
"Error while listing all entries from GitTree for changeset {changeset_id:?}",
128+
"Error while listing all entries from GitTree for changeset {changeset_id:?} and root tree {root_tree:?}",
125129
)
126130
})?;
127131
Ok(objects)

eden/mononoke/tests/integration/mononoke_git_server/test-mononoke-git-server-shallow-clone-with-submodule.t

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -64,17 +64,4 @@ Disable Mercurial types as they do not support git submodules
6464

6565
# Perform a shallow clone of the repo with depth = 1 and list the commits. This should fail because we try to fetch the
6666
# size of the submodule
67-
$ git_client clone $MONONOKE_GIT_SERVICE_BASE_URL/$REPONAME.git --depth=1
68-
Cloning into 'repo'...
69-
remote: Converting HAVE Git commits to Bonsais
70-
remote: Converting WANT Git commits to Bonsais
71-
remote: Collecting Bonsai commits to send to client
72-
remote: Counting number of objects to be sent in packfile
73-
remote: Error while calculating object count during fetch
74-
75-
Caused by:
76-
0: Error while listing all entries from GitTree for changeset ChangesetId(Blake2(*)) (glob)
77-
1: No metadata for de0c53cc213a98b1382aec1dcbcb01bf088273e4
78-
fatal: early EOF
79-
fatal: fetch-pack: invalid index-pack output
80-
[128]
67+
$ quiet git_client clone $MONONOKE_GIT_SERVICE_BASE_URL/$REPONAME.git --depth=1

0 commit comments

Comments
 (0)