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>
diff --git a/command.py b/command.py
index 3086e13..6aa0ca8 100644
--- a/command.py
+++ b/command.py
@@ -17,7 +17,7 @@
 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 @@
             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 @@
         )
 
         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 f4566dc..08882b8 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 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 754c029..2767ac3 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 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 c51ecf3..460ebab 100644
--- a/subcmds/sync.py
+++ b/subcmds/sync.py
@@ -534,6 +534,8 @@
             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 @@
             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 39d9f03..208ff60 100644
--- a/tests/test_subcmds_sync.py
+++ b/tests/test_subcmds_sync.py
@@ -215,6 +215,31 @@
             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