Skip to content

Commit

Permalink
Sets depth=1 to Git clone/fetch
Browse files Browse the repository at this point in the history
This is to avoid exhausting the resources while cloning very large
repos (such as github.com/openshift/origin).

The above case is consuming ~3GB memory during the cloning process.

Signed-off-by: Bruno Pimentel <bpimente@redhat.com>
  • Loading branch information
brunoapimentel committed Dec 13, 2021
1 parent 3600456 commit 3d7b776
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion cachito/workers/scm.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,13 @@ def clone_and_archive(self, gitsubmodule=False):
self.url,
clone_path,
no_checkout=True,
# Clone with depth 1 to save resources on large repos
depth=1,
# Don't allow git to prompt for a username if we don't have access
env={"GIT_TERMINAL_PROMPT": "0"},
)

repo.remote().fetch(refspec=self.ref, depth=1)
except: # noqa E722
log.exception("Cloning the Git repository from %s failed", self.url)
raise CachitoError("Cloning the Git repository failed")
Expand Down Expand Up @@ -190,7 +194,7 @@ def update_and_archive(self, previous_archive, gitsubmodule=False):
try:
# The reference must be specified to handle commits which are not part
# of a branch.
repo.remote().fetch(refspec=self.ref)
repo.remote().fetch(refspec=self.ref, depth=1)
except: # noqa E722
log.exception("Failed to fetch from remote %s", self.url)
raise CachitoError("Failed to fetch from the remote Git repository")
Expand Down

0 comments on commit 3d7b776

Please sign in to comment.