From 230dcb479d8200ca2b0704e8f60ae6f4e3852aed Mon Sep 17 00:00:00 2001 From: Turiiya <34311583+ttytm@users.noreply.github.com> Date: Sat, 4 Nov 2023 09:16:43 +0100 Subject: [PATCH] tools: improve VCS handling in vpm part2 (#19754) --- cmd/tools/vpm/common.v | 11 +++-------- cmd/tools/vpm/install.v | 4 ++-- cmd/tools/vpm/update.v | 6 ++---- cmd/tools/vpm/vpm.v | 35 ++++++++++++++++++++++------------- 4 files changed, 29 insertions(+), 27 deletions(-) diff --git a/cmd/tools/vpm/common.v b/cmd/tools/vpm/common.v index bd6aa39acec238..1f1c9c75a6f540 100644 --- a/cmd/tools/vpm/common.v +++ b/cmd/tools/vpm/common.v @@ -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}') @@ -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.') } } diff --git a/cmd/tools/vpm/install.v b/cmd/tools/vpm/install.v index 397929ae97a988..76b77e7c7b09a4 100644 --- a/cmd/tools/vpm/install.v +++ b/cmd/tools/vpm/install.v @@ -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) diff --git a/cmd/tools/vpm/update.v b/cmd/tools/vpm/update.v index 223a11ed052506..455cc733d87dc3 100644 --- a/cmd/tools/vpm/update.v +++ b/cmd/tools/vpm/update.v @@ -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 { @@ -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 { diff --git a/cmd/tools/vpm/vpm.v b/cmd/tools/vpm/vpm.v index 704ac445508b49..2a4a1ec01ea58f 100644 --- a/cmd/tools/vpm/vpm.v +++ b/cmd/tools/vpm/vpm.v @@ -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 ( @@ -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'] + } } } )