Skip to content

Commit

Permalink
tools: improve VCS handling in vpm part2 (#19754)
Browse files Browse the repository at this point in the history
  • Loading branch information
ttytm committed Nov 4, 2023
1 parent f1ba664 commit 230dcb4
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 27 deletions.
11 changes: 3 additions & 8 deletions cmd/tools/vpm/common.v
Expand Up @@ -38,9 +38,8 @@ fn get_mod_date_info(mut pp pool.PoolProcessor, idx int, wid int) &ModDateInfo {
vcs := vcs_used_in_dir(final_module_path) or { return result }
is_hg := vcs.cmd == 'hg'
mut outputs := []string{}
for step in vcs.outdated_steps {
path_flag := if is_hg { '-R' } else { '-C' }
cmd := '${vcs.cmd} ${path_flag} "${final_module_path}" ${step}'
for step in vcs.args.outdated {
cmd := '${vcs.cmd} ${vcs.args.path} "${final_module_path}" ${step}'
res := os.execute('${cmd}')
if res.exit_code < 0 {
verbose_println('Error command: ${cmd}')
Expand Down Expand Up @@ -229,11 +228,7 @@ fn ensure_vmodules_dir_exist() {
}

fn ensure_vcs_is_installed(vcs &VCS) ! {
cmd := '${vcs.cmd} --version'
verbose_println(' command: ${cmd}')
res := os.execute(cmd)
if res.exit_code != 0 {
verbose_println(' command output: ${res.output}')
os.find_abs_path_of_executable(vcs.cmd) or {
return error('VPM needs `${vcs}` to be installed.')
}
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/tools/vpm/install.v
Expand Up @@ -79,13 +79,13 @@ fn vpm_install(requested_modules []string, opts []string) {
vpm_install_from_vpm(vpm_modules)
}
if external_modules.len > 0 {
vcs := if '--hg' in opts { supported_vcs['hd'] } else { supported_vcs['git'] }
vcs := if '--hg' in opts { supported_vcs['hg'] } else { supported_vcs['git'] }
vpm_install_from_vcs(external_modules, vcs)
}
}

fn install_module(vcs &VCS, name string, url string, final_module_path string) ! {
cmd := '${vcs.cmd} ${vcs.install_arg} "${url}" "${final_module_path}"'
cmd := '${vcs.cmd} ${vcs.args.install} "${url}" "${final_module_path}"'
verbose_println(' command: ${cmd}')
println('Installing module "${name}" from "${url}" to "${final_module_path}" ...')
res := os.execute(cmd)
Expand Down
6 changes: 2 additions & 4 deletions cmd/tools/vpm/update.v
Expand Up @@ -24,8 +24,7 @@ fn update_module(mut pp pool.PoolProcessor, idx int, wid int) &ModUpdateInfo {
eprintln(err)
return result
}
path_flag := if vcs.cmd == 'hg' { '-R' } else { '-C' }
cmd := '${vcs.cmd} ${path_flag} "${result.final_path}" ${vcs.update_arg}'
cmd := '${vcs.cmd} ${vcs.args.path} "${result.final_path}" ${vcs.args.update}'
verbose_println(' command: ${cmd}')
res := os.execute('${cmd}')
if res.exit_code != 0 {
Expand Down Expand Up @@ -76,8 +75,7 @@ fn vpm_update_verbose(module_names []string) {
eprintln(err)
continue
}
path_flag := if vcs.cmd == 'hg' { '-R' } else { '-C' }
cmd := '${vcs.cmd} ${path_flag} "${final_module_path}" ${vcs.update_arg}'
cmd := '${vcs.cmd} ${vcs.args.path} "${final_module_path}" ${vcs.args.update}'
verbose_println(' command: ${cmd}')
res := os.execute('${cmd}')
if res.exit_code != 0 {
Expand Down
35 changes: 22 additions & 13 deletions cmd/tools/vpm/vpm.v
Expand Up @@ -18,11 +18,14 @@ mut:
}

struct VCS {
cmd string
dir string
update_arg string
install_arg string
outdated_steps []string
dir string
cmd string
args struct {
install string
path string // the flag used to specify a path. E.g., used to explictly work on a path during multithreaded updating.
update string
outdated []string
}
}

const (
Expand All @@ -35,18 +38,24 @@ const (
excluded_dirs = ['cache', 'vlib']
supported_vcs = {
'git': VCS{
cmd: 'git'
dir: '.git'
update_arg: 'pull --recurse-submodules' // pulling with `--depth=1` leads to conflicts, when the upstream is more than 1 commit newer
install_arg: 'clone --depth=1 --recursive --shallow-submodules'
outdated_steps: ['fetch', 'rev-parse @', 'rev-parse @{u}']
cmd: 'git'
args: struct {
install: 'clone --depth=1 --recursive --shallow-submodules'
update: 'pull --recurse-submodules' // pulling with `--depth=1` leads to conflicts, when the upstream is more than 1 commit newer
path: '-C'
outdated: ['fetch', 'rev-parse @', 'rev-parse @{u}']
}
}
'hg': VCS{
cmd: 'hg'
dir: '.hg'
update_arg: 'pull --update'
install_arg: 'clone'
outdated_steps: ['incoming']
cmd: 'hg'
args: struct {
install: 'clone'
update: 'pull --update'
path: '-R'
outdated: ['incoming']
}
}
}
)
Expand Down

0 comments on commit 230dcb4

Please sign in to comment.