Skip to content

Commit

Permalink
tools: make v run cmd/tools/oldv.v 5b7a1e8 -c "./v version" faster …
Browse files Browse the repository at this point in the history
…(5b7a1e8 is the oldest supported commit from 2019-06-29)
  • Loading branch information
spytheman committed Aug 14, 2023
1 parent eef77e3 commit a93ef6e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
31 changes: 29 additions & 2 deletions cmd/tools/modules/vgit/vgit.v
Expand Up @@ -81,8 +81,35 @@ pub fn clone_or_pull(remote_git_url string, local_worktree_path string) {
scripting.run('git -C "${local_worktree_path}" checkout --quiet master')
scripting.run('git -C "${local_worktree_path}" pull --quiet ')
} else {
// Clone a fresh
scripting.run('git clone --filter=blob:none --quiet "${remote_git_url}" "${local_worktree_path}" ')
// Clone a fresh local tree.
if remote_git_url.starts_with('http') {
// cloning an https remote with --filter=blob:none is usually much less bandwidth intensive, at the
// expense of doing small network ops later when using checkouts.
scripting.run('git clone --filter=blob:none --quiet "${remote_git_url}" "${local_worktree_path}" ')
return
}
mut is_blobless_clone := false
remote_git_config_path := os.join_path(remote_git_url, '.git', 'config')
if os.is_dir(remote_git_url) && os.is_file(remote_git_config_path) {
lines := os.read_lines(remote_git_config_path) or { [] }
is_blobless_clone = lines.filter(it.contains('partialclonefilter = blob:none')).len > 0
}
if is_blobless_clone {
// Note:
// 1) cloning a *local folder* with `--filter=blob:none`, that *itself* was cloned with `--filter=blob:none`
// leads to *extremely* slow checkouts for older commits later. It takes hours instead of milliseconds, for a commit
// that is just several thousands of commits old :( .
//
// 2) Cloning it *without* the `--filter=blob:none`, leads to `error: unable to read sha1 file of`, later,
// when checking out the older commits, depending on the local git client version (tested with git version 2.41.0).
//
// 3) => instead of cloning, it is much faster, and *bug free*, to just rsync the local repo directly,
// at the expense of a little more space usage, which will make the new tree in local_worktree_path,
// exactly 1:1 the same, as the one in remote_git_url, just independent from it .
scripting.run('rsync -a "${remote_git_url}/" "${local_worktree_path}/"')
return
}
scripting.run('git clone --quiet "${remote_git_url}" "${local_worktree_path}" ')
}
}

Expand Down
6 changes: 5 additions & 1 deletion cmd/tools/oldv.v
Expand Up @@ -83,7 +83,11 @@ fn sync_cache() {
repofolder := os.join_path(cache_oldv_folder, reponame)
if !os.exists(repofolder) {
scripting.verbose_trace(@FN, 'cloning to ${repofolder}')
scripting.exec('git clone --filter=blob:none --quiet https://github.com/vlang/${reponame} ${repofolder}') or {
mut repo_options := ''
if reponame == 'vc' {
repo_options = '--filter=blob:none'
}
scripting.exec('git clone ${repo_options} --quiet https://github.com/vlang/${reponame} ${repofolder}') or {
scripting.verbose_trace(@FN, '## error during clone: ${err}')
exit(1)
}
Expand Down

0 comments on commit a93ef6e

Please sign in to comment.