From 4b3ada1781c7dc855858582a2b8f47fb0fc7f412 Mon Sep 17 00:00:00 2001 From: Victor Pushkarev Date: Thu, 3 Sep 2026 15:31:49 +0300 Subject: [PATCH] sync: keep generated jobs-checkout help host-independent The default shown for `--jobs-checkout` comes from `DEFAULT_LOCAL_JOBS`, which depends on the host CPU count. As a result, regenerating the sync and smartsync manpages on a different machine can change their output even though repo's behavior has not changed. Use shared CPU-based help formatting for `--jobs` and `--jobs-checkout`. Interactive help still shows the actual default, while generated manpages describe it without including a host-specific value. Runtime job selection is unchanged. Add coverage for both help modes and regenerate the affected manpages. Change-Id: Ia60e6fcc17b6f4618c52a76217c128eddead8848 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/625381 Reviewed-by: Mike Frysinger Commit-Queue: Victor Pushkarev Tested-by: Victor Pushkarev Reviewed-by: Gavin Mak --- command.py | 22 ++++++++++++++++------ man/repo-smartsync.1 | 4 ++-- man/repo-sync.1 | 4 ++-- subcmds/sync.py | 4 +++- tests/test_subcmds_sync.py | 25 +++++++++++++++++++++++++ 5 files changed, 48 insertions(+), 11 deletions(-) diff --git a/command.py b/command.py index 3086e13a2..6aa0ca86b 100644 --- a/command.py +++ b/command.py @@ -17,7 +17,7 @@ import multiprocessing import optparse import os import re -from typing import List, TYPE_CHECKING +from typing import List, Optional, TYPE_CHECKING from error import InvalidProjectGroupsError from error import NoSuchProjectError @@ -152,6 +152,20 @@ class Command: self._Options(self._optparse) return self._optparse + @staticmethod + def _GetHelpForCpuJobCount( + default_jobs: Optional[int] = None, + ) -> str: + """Return CPU-based job help, with an explicit default when needed. + + Specify default_jobs when additional logic computes effective default. + """ + if GENERATE_MANPAGES: + return "based on number of CPU cores" + + default = "%default" if default_jobs is None else str(default_jobs) + return f"{default}; based on number of CPU cores" + def _CommonOptions(self, p, opt_v=True): """Initialize the option parser with common options. @@ -176,11 +190,7 @@ class Command: ) if self.PARALLEL_JOBS is not None: - default = "based on number of CPU cores" - if not GENERATE_MANPAGES: - # Only include active cpu count if we aren't generating man - # pages. - default = f"%default; {default}" + default = self._GetHelpForCpuJobCount() p.add_option( "-j", "--jobs", diff --git a/man/repo-smartsync.1 b/man/repo-smartsync.1 index f4566dc01..08882b8ce 100644 --- a/man/repo-smartsync.1 +++ b/man/repo-smartsync.1 @@ -1,5 +1,5 @@ .\" DO NOT MODIFY THIS FILE! It was generated by help2man. -.TH REPO "1" "July 2026" "repo smartsync" "Repo Manual" +.TH REPO "1" "September 2026" "repo smartsync" "Repo Manual" .SH NAME repo \- repo smartsync - manual page for repo smartsync .SH SYNOPSIS @@ -21,7 +21,7 @@ number of jobs to run in parallel (default: based on number of CPU cores) number of network jobs to run in parallel (defaults to \fB\-\-jobs\fR or 1). Ignored unless \fB\-\-no\-interleaved\fR is set .TP \fB\-\-jobs\-checkout\fR=\fI\,JOBS\/\fR -number of local checkout jobs to run in parallel (defaults to \fB\-\-jobs\fR or 8). Ignored unless \fB\-\-no\-interleaved\fR is set +number of local checkout jobs to run in parallel (defaults to \fB\-\-jobs\fR or based on number of CPU cores). Ignored unless \fB\-\-no\-interleaved\fR is set .TP \fB\-f\fR, \fB\-\-force\-broken\fR obsolete option (to be deleted in the future) diff --git a/man/repo-sync.1 b/man/repo-sync.1 index 754c02927..2767ac3d8 100644 --- a/man/repo-sync.1 +++ b/man/repo-sync.1 @@ -1,5 +1,5 @@ .\" DO NOT MODIFY THIS FILE! It was generated by help2man. -.TH REPO "1" "July 2026" "repo sync" "Repo Manual" +.TH REPO "1" "September 2026" "repo sync" "Repo Manual" .SH NAME repo \- repo sync - manual page for repo sync .SH SYNOPSIS @@ -21,7 +21,7 @@ number of jobs to run in parallel (default: based on number of CPU cores) number of network jobs to run in parallel (defaults to \fB\-\-jobs\fR or 1). Ignored unless \fB\-\-no\-interleaved\fR is set .TP \fB\-\-jobs\-checkout\fR=\fI\,JOBS\/\fR -number of local checkout jobs to run in parallel (defaults to \fB\-\-jobs\fR or 8). Ignored unless \fB\-\-no\-interleaved\fR is set +number of local checkout jobs to run in parallel (defaults to \fB\-\-jobs\fR or based on number of CPU cores). Ignored unless \fB\-\-no\-interleaved\fR is set .TP \fB\-f\fR, \fB\-\-force\-broken\fR obsolete option (to be deleted in the future) diff --git a/subcmds/sync.py b/subcmds/sync.py index c51ecf385..460ebabd1 100644 --- a/subcmds/sync.py +++ b/subcmds/sync.py @@ -534,6 +534,8 @@ later is required to fix a server side protocol bug. help="number of network jobs to run in parallel (defaults to " "--jobs or 1). Ignored unless --no-interleaved is set", ) + + jobs_checkout_default = self._GetHelpForCpuJobCount(DEFAULT_LOCAL_JOBS) p.add_option( "--jobs-checkout", default=None, @@ -541,7 +543,7 @@ later is required to fix a server side protocol bug. metavar="JOBS", help=( "number of local checkout jobs to run in parallel (defaults " - f"to --jobs or {DEFAULT_LOCAL_JOBS}). Ignored unless " + f"to --jobs or {jobs_checkout_default}). Ignored unless " "--no-interleaved is set" ), ) diff --git a/tests/test_subcmds_sync.py b/tests/test_subcmds_sync.py index 39d9f03b1..208ff60b2 100644 --- a/tests/test_subcmds_sync.py +++ b/tests/test_subcmds_sync.py @@ -215,6 +215,31 @@ def test_sync_update_projects_revision_id_respects_groups(tmp_path: Path): assert kwargs.get("groups") == "group1" +@pytest.mark.parametrize( + "generate_manpages, expected_default", + [ + (False, "7; based on number of CPU cores"), + (True, "based on number of CPU cores"), + ], + ids=("interactive", "manpages"), +) +def test_jobs_checkout_help_default( + generate_manpages: bool, + expected_default: str, +) -> None: + """Test checkout-jobs default help in interactive and manpage modes.""" + with mock.patch.object(sync, "DEFAULT_LOCAL_JOBS", 7), mock.patch.object( + command, + "GENERATE_MANPAGES", + generate_manpages, + ): + help_text = " ".join(sync.Sync().OptionParser.format_help().split()) + + assert f"defaults to --jobs or {expected_default}" in help_text + if generate_manpages: + assert "defaults to --jobs or 7" not in help_text + + # Used to patch os.cpu_count() for reliable results. OS_CPU_COUNT = 24