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 <vapier@google.com>
Commit-Queue: Victor Pushkarev <corvinus.v@gmail.com>
Tested-by: Victor Pushkarev <corvinus.v@gmail.com>
Reviewed-by: Gavin Mak <gavinmak@google.com>
This commit is contained in:
Victor Pushkarev
2026-09-16 04:51:54 -07:00
committed by gerrit-scoped@luci-project-accounts.iam.gserviceaccount.com
parent a468ea7752
commit 4b3ada1781
5 changed files with 48 additions and 11 deletions
+16 -6
View File
@@ -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",
+2 -2
View File
@@ -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)
+2 -2
View File
@@ -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)
+3 -1
View File
@@ -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"
),
)
+25
View File
@@ -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