style: use import command everywhere

Align with Google style guides and `import command` as a module
rather than import symbols out of it.

The help subcmd needed a minor rewrite as it had a "command"
variable already.

Change-Id: I9b465c85246670d63827df0744b00e59033e87b2
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/656243
Commit-Queue: Mike Frysinger <vapier@google.com>
Tested-by: Mike Frysinger <vapier@google.com>
Reviewed-by: Brian Gan <brgan@google.com>
This commit is contained in:
Mike Frysinger authored and gerrit-scoped@luci-project-accounts.iam.gserviceaccount.com committed 2026-11-10 12:59:38 -08:00
1 parent b2e30cef91
commit 4bb901eab0
29 files changed
+88 -121

No files matched your search

-20
View File
@@ -10,32 +10,12 @@ per-file-ignores =
git_status.py: IMR241,
main.py: IMR241,
manifest_xml.py: IMR241,
subcmds/abandon.py: IMR241,
subcmds/branches.py: IMR241,
subcmds/checkout.py: IMR241,
subcmds/cherry_pick.py: IMR241,
subcmds/diffmanifests.py: IMR241,
subcmds/diff.py: IMR241,
subcmds/download.py: IMR241,
subcmds/forall.py: IMR241,
subcmds/gc.py: IMR241,
subcmds/grep.py: IMR241,
subcmds/help.py: IMR241,
subcmds/info.py: IMR241,
subcmds/init.py: IMR241,
subcmds/list.py: IMR241,
subcmds/manifest.py: IMR241,
subcmds/overview.py: IMR241,
subcmds/prune.py: IMR241,
subcmds/rebase.py: IMR241,
subcmds/selfupdate.py: IMR241,
subcmds/smartsync.py: IMR241,
subcmds/stage.py: IMR241,
subcmds/start.py: IMR241,
subcmds/status.py: IMR241,
subcmds/sync.py: IMR241,
subcmds/upload.py: IMR241,
subcmds/version.py: IMR241,
subcmds/wipe.py: IMR241,
tests/e2e/test_failures.py: IMR241,
tests/e2e/test_groups.py: IMR241,
+8 -4
View File
@@ -42,8 +42,7 @@ except ImportError:
kerberos = None
import color
from command import InteractiveCommand
from command import MirrorSafeCommand
import command
import editor
import error
import event_log
@@ -415,7 +414,10 @@ class _Repo:
editor.Editor.globalConfig = cmd.client.globalConfig
if not isinstance(cmd, MirrorSafeCommand) and cmd.manifest.IsMirror:
if (
not isinstance(cmd, command.MirrorSafeCommand)
and cmd.manifest.IsMirror
):
logger.error("fatal: '%s' requires a working directory", name)
return 1
@@ -432,7 +434,9 @@ class _Repo:
cmd.CommonValidateOptions(copts, cargs)
git_trace2_event_log.verbose = copts.verbose
if gopts.pager is not False and not isinstance(cmd, InteractiveCommand):
if gopts.pager is not False and not isinstance(
cmd, command.InteractiveCommand
):
config = cmd.client.globalConfig
if gopts.pager:
use_pager = True
+3 -4
View File
@@ -16,8 +16,7 @@ import collections
import functools
import itertools
from command import Command
from command import DEFAULT_LOCAL_JOBS
import command
import error
import git_command
import progress
@@ -31,7 +30,7 @@ class AbandonError(error.RepoExitError):
"""Exit error when abandon command fails."""
class Abandon(Command):
class Abandon(command.Command):
COMMON = True
helpSummary = "Permanently abandon a development branch"
helpUsage = """
@@ -42,7 +41,7 @@ deleting it (and all its history) from your local repository.
It is equivalent to "git branch -D <branchname>".
"""
PARALLEL_JOBS = DEFAULT_LOCAL_JOBS
PARALLEL_JOBS = command.DEFAULT_LOCAL_JOBS
def _Options(self, p):
p.add_option(
+3 -4
View File
@@ -16,8 +16,7 @@ import itertools
import sys
import color
from command import Command
from command import DEFAULT_LOCAL_JOBS
import command
class BranchColoring(color.Coloring):
@@ -62,7 +61,7 @@ class BranchInfo:
return self.published_equal == len(self.projects)
class Branches(Command):
class Branches(command.Command):
COMMON = True
helpSummary = "View current topic branches"
helpUsage = """
@@ -96,7 +95,7 @@ the branch appears in, or does not appear in. If no project list
is shown, then the branch appears in all projects.
"""
PARALLEL_JOBS = DEFAULT_LOCAL_JOBS
PARALLEL_JOBS = command.DEFAULT_LOCAL_JOBS
@classmethod
def _ExpandProjectToBranches(cls, project_idx):
+3 -4
View File
@@ -15,8 +15,7 @@
import functools
from typing import NamedTuple
from command import Command
from command import DEFAULT_LOCAL_JOBS
import command
import error
import progress
import repo_logging
@@ -40,7 +39,7 @@ class MissingBranchError(error.RepoExitError):
"""Exception thrown when no project has specified branch."""
class Checkout(Command):
class Checkout(command.Command):
COMMON = True
helpSummary = "Checkout a branch for development"
helpUsage = """
@@ -54,7 +53,7 @@ The command is equivalent to:
repo forall [<project>...] -c git checkout <branchname>
"""
PARALLEL_JOBS = DEFAULT_LOCAL_JOBS
PARALLEL_JOBS = command.DEFAULT_LOCAL_JOBS
def ValidateOptions(self, opt, args):
if not args:
+2 -2
View File
@@ -16,7 +16,7 @@ import re
import sys
from typing import Tuple
from command import Command
import command
import error
import git_command
import repo_logging
@@ -26,7 +26,7 @@ CHANGE_ID_RE = re.compile(r"^\s*Change-Id: I([0-9a-f]{40})\s*$")
logger = repo_logging.RepoLogger(__file__)
class CherryPick(Command):
class CherryPick(command.Command):
COMMON = True
helpSummary = "Cherry-pick a change."
helpUsage = """
+3 -4
View File
@@ -15,11 +15,10 @@
import functools
import io
from command import DEFAULT_LOCAL_JOBS
from command import PagedCommand
import command
class Diff(PagedCommand):
class Diff(command.PagedCommand):
COMMON = True
helpSummary = "Show changes between commit and working tree"
helpUsage = """
@@ -29,7 +28,7 @@ The -u option causes '%prog' to generate diff output with file paths
relative to the repository root, so the output can be applied
to the Unix 'patch' command.
"""
PARALLEL_JOBS = DEFAULT_LOCAL_JOBS
PARALLEL_JOBS = command.DEFAULT_LOCAL_JOBS
def _Options(self, p):
p.add_option(
+2 -2
View File
@@ -13,7 +13,7 @@
# limitations under the License.
import color
from command import PagedCommand
import command
import manifest_xml
@@ -22,7 +22,7 @@ class _Coloring(color.Coloring):
super().__init__(config, "status")
class Diffmanifests(PagedCommand):
class Diffmanifests(command.PagedCommand):
"""A command to see logs in projects represented by manifests
This is used to see deeper differences between manifests. Where a simple
+2 -2
View File
@@ -15,7 +15,7 @@
import re
import sys
from command import Command
import command
import error
import repo_logging
@@ -28,7 +28,7 @@ class DownloadCommandError(error.RepoExitError):
"""Error raised when download command fails."""
class Download(Command):
class Download(command.Command):
COMMON = True
helpSummary = "Download and checkout a change"
helpUsage = """
+3 -5
View File
@@ -22,9 +22,7 @@ import subprocess
import sys
import color
from command import Command
from command import DEFAULT_LOCAL_JOBS
from command import MirrorSafeCommand
import command
import repo_logging
@@ -43,7 +41,7 @@ class ForallColoring(color.Coloring):
self.project = self.printer("project", attr="bold")
class Forall(Command, MirrorSafeCommand):
class Forall(command.Command, command.MirrorSafeCommand):
COMMON = False
helpSummary = "Run a shell command in each project"
helpUsage = """
@@ -136,7 +134,7 @@ terminal and are not redirected.
If -e is used, when a command exits unsuccessfully, '%prog' will abort
without iterating through the remaining projects.
"""
PARALLEL_JOBS = DEFAULT_LOCAL_JOBS
PARALLEL_JOBS = command.DEFAULT_LOCAL_JOBS
@staticmethod
def _cmd_option(option, _opt_str, _value, parser):
+2 -2
View File
@@ -15,14 +15,14 @@
import os
from typing import List, Set
from command import Command
import command
import git_command
import platform_utils
import progress
from project import Project
class Gc(Command):
class Gc(command.Command):
COMMON = True
helpSummary = "Cleaning up internal repo and Git state."
helpUsage = """
+3 -4
View File
@@ -17,8 +17,7 @@ import sys
from typing import NamedTuple
import color
from command import DEFAULT_LOCAL_JOBS
from command import PagedCommand
import command
import error
import git_command
import repo_logging
@@ -50,7 +49,7 @@ class GrepCommandError(error.SilentRepoExitError):
aggregate errors exit silently."""
class Grep(PagedCommand):
class Grep(command.PagedCommand):
COMMON = True
helpSummary = "Print lines matching a pattern"
helpUsage = """
@@ -84,7 +83,7 @@ contain a line that matches both expressions:
repo grep --all-match -e NODE -e Unexpected
"""
PARALLEL_JOBS = DEFAULT_LOCAL_JOBS
PARALLEL_JOBS = command.DEFAULT_LOCAL_JOBS
@staticmethod
def _carry_option(_option, opt_str, value, parser):
+13 -13
View File
@@ -15,10 +15,10 @@
import re
import sys
import textwrap
from typing import Sequence
import color
from command import MirrorSafeCommand
from command import PagedCommand
import command
import error
import subcmds
import wrapper
@@ -28,7 +28,7 @@ class InvalidHelpCommand(error.RepoExitError):
"""Invalid command passed into help."""
class Help(PagedCommand, MirrorSafeCommand):
class Help(command.PagedCommand, command.MirrorSafeCommand):
COMMON = False
helpSummary = "Display detailed help on a command"
helpUsage = """
@@ -38,17 +38,17 @@ class Help(PagedCommand, MirrorSafeCommand):
Displays detailed usage information about a command.
"""
def _PrintCommands(self, commandNames):
"""Helper to display |commandNames| summaries."""
def _PrintCommands(self, names: Sequence[str]) -> None:
"""Helper to display |names| summaries."""
maxlen = 0
for name in commandNames:
for name in names:
maxlen = max(maxlen, len(name))
fmt = " %%-%ds %%s" % maxlen
for name in commandNames:
command = subcmds.all_commands[name]()
for name in names:
cmd = subcmds.all_commands[name]()
try:
summary = command.helpSummary.strip()
summary = cmd.helpSummary.strip()
except AttributeError:
summary = ""
print(fmt % (name, summary))
@@ -59,8 +59,8 @@ Displays detailed usage information about a command.
def PrintAllCommandsBody(self):
print("The complete list of recognized repo commands is:")
commandNames = sorted(subcmds.all_commands)
self._PrintCommands(commandNames)
names = sorted(subcmds.all_commands)
self._PrintCommands(names)
print(
"See 'repo help <command>' for more information on a "
"specific command."
@@ -74,10 +74,10 @@ Displays detailed usage information about a command.
def PrintCommonCommandsBody(self):
print("The most commonly used repo commands are:")
commandNames = sorted(
names = sorted(
name for name, cmd in subcmds.all_commands.items() if cmd.COMMON
)
self._PrintCommands(commandNames)
self._PrintCommands(names)
print(
"See 'repo help <command>' for more information on a specific "
+3 -4
View File
@@ -21,8 +21,7 @@ import sys
from typing import Any, Dict, List, NamedTuple, Optional, Tuple
import color
from command import DEFAULT_LOCAL_JOBS
from command import PagedCommand
import command
import git_refs
@@ -51,9 +50,9 @@ class _Coloring(color.Coloring):
super().__init__(config, "status")
class Info(PagedCommand):
class Info(command.PagedCommand):
COMMON = True
PARALLEL_JOBS = DEFAULT_LOCAL_JOBS
PARALLEL_JOBS = command.DEFAULT_LOCAL_JOBS
helpSummary = (
"Get info on the manifest branch, current branch or unmerged branches"
)
+2 -3
View File
@@ -16,8 +16,7 @@ import os
import sys
import color
from command import InteractiveCommand
from command import MirrorSafeCommand
import command
import error
import git_command
import repo_logging
@@ -29,7 +28,7 @@ logger = repo_logging.RepoLogger(__file__)
_REPO_ALLOW_SHALLOW = os.environ.get("REPO_ALLOW_SHALLOW")
class Init(InteractiveCommand, MirrorSafeCommand):
class Init(command.InteractiveCommand, command.MirrorSafeCommand):
COMMON = True
RESPECT_SMART_SYNC_OVERRIDE = False
MULTI_MANIFEST_SUPPORT = True
+2 -3
View File
@@ -14,11 +14,10 @@
import os
from command import Command
from command import MirrorSafeCommand
import command
class List(Command, MirrorSafeCommand):
class List(command.Command, command.MirrorSafeCommand):
COMMON = True
helpSummary = "List projects and their associated directories"
helpUsage = """
+2 -2
View File
@@ -18,7 +18,7 @@ import optparse
import os
import sys
from command import PagedCommand
import command
import repo_logging
@@ -35,7 +35,7 @@ class OutputFormat(enum.Enum):
JSON = enum.auto()
class Manifest(PagedCommand):
class Manifest(command.PagedCommand):
COMMON = False
helpSummary = "Manifest inspection utility"
helpUsage = """
+2 -2
View File
@@ -15,10 +15,10 @@
import optparse
import color
from command import PagedCommand
import command
class Overview(PagedCommand):
class Overview(command.PagedCommand):
COMMON = True
helpSummary = "Display overview of unmerged project branches"
helpUsage = """
+3 -4
View File
@@ -15,17 +15,16 @@
import itertools
import color
from command import DEFAULT_LOCAL_JOBS
from command import PagedCommand
import command
class Prune(PagedCommand):
class Prune(command.PagedCommand):
COMMON = True
helpSummary = "Prune (delete) already merged topics"
helpUsage = """
%prog [<project>...]
"""
PARALLEL_JOBS = DEFAULT_LOCAL_JOBS
PARALLEL_JOBS = command.DEFAULT_LOCAL_JOBS
@classmethod
def _ExecuteOne(cls, project_idx):
+2 -2
View File
@@ -15,7 +15,7 @@
import sys
import color
from command import Command
import command
import error
import git_command
from project import Project
@@ -43,7 +43,7 @@ def _ResolveOntoManifest(project: Project) -> str:
return project.revisionExpr
class Rebase(Command):
class Rebase(command.Command):
COMMON = True
helpSummary = "Rebase local branches on upstream branch"
helpUsage = """
+2 -3
View File
@@ -14,8 +14,7 @@
import optparse
from command import Command
from command import MirrorSafeCommand
import command
import error
import repo_logging
from subcmds.sync import _PostRepoFetch
@@ -29,7 +28,7 @@ class SelfupdateError(error.RepoExitError):
"""Exit error for failed selfupdate command."""
class Selfupdate(Command, MirrorSafeCommand):
class Selfupdate(command.Command, command.MirrorSafeCommand):
COMMON = False
helpSummary = "Update repo to the latest version"
helpUsage = """
+2 -2
View File
@@ -15,7 +15,7 @@
import sys
import color
from command import InteractiveCommand
import command
import git_command
import repo_logging
@@ -31,7 +31,7 @@ class _ProjectList(color.Coloring):
self.help = self.printer("help", fg="red", attr="bold")
class Stage(InteractiveCommand):
class Stage(command.InteractiveCommand):
COMMON = True
helpSummary = "Stage file(s) for commit"
helpUsage = """
+3 -4
View File
@@ -15,8 +15,7 @@
import functools
from typing import NamedTuple
from command import Command
from command import DEFAULT_LOCAL_JOBS
import command
import error
import git_command
import git_config
@@ -36,7 +35,7 @@ class StartError(error.RepoExitError):
"""Exit error for failed start command."""
class Start(Command):
class Start(command.Command):
COMMON = True
helpSummary = "Start a new branch for development"
helpUsage = """
@@ -46,7 +45,7 @@ class Start(Command):
'%prog' begins a new branch of development, starting from the
revision specified in the manifest.
"""
PARALLEL_JOBS = DEFAULT_LOCAL_JOBS
PARALLEL_JOBS = command.DEFAULT_LOCAL_JOBS
def _Options(self, p):
p.add_option(
+3 -4
View File
@@ -18,12 +18,11 @@ import io
import os
import color
from command import DEFAULT_LOCAL_JOBS
from command import PagedCommand
import command
import platform_utils
class Status(PagedCommand):
class Status(command.PagedCommand):
COMMON = True
helpSummary = "Show the working tree status"
helpUsage = """
@@ -82,7 +81,7 @@ the following meanings:
d: deleted ( in index, not in work tree )
"""
PARALLEL_JOBS = DEFAULT_LOCAL_JOBS
PARALLEL_JOBS = command.DEFAULT_LOCAL_JOBS
def _Options(self, p):
p.add_option(
+7 -8
View File
@@ -53,10 +53,7 @@ except ImportError:
return (256, 256)
from command import Command
from command import DEFAULT_LOCAL_JOBS
from command import MirrorSafeCommand
from command import WORKER_BATCH_SIZE
import command
import error
import event_log
import git_command
@@ -294,7 +291,7 @@ def _WithoutProjects(
def _chunksize(projects: int, jobs: int) -> int:
"""Calculate chunk size for the given number of projects and jobs."""
return min(max(1, projects // jobs), WORKER_BATCH_SIZE)
return min(max(1, projects // jobs), command.WORKER_BATCH_SIZE)
class _FetchOneResult(NamedTuple):
@@ -447,7 +444,7 @@ class TeeStringIO(io.StringIO):
return ret
class Sync(Command, MirrorSafeCommand):
class Sync(command.Command, command.MirrorSafeCommand):
COMMON = True
RESPECT_SMART_SYNC_OVERRIDE = False
MULTI_MANIFEST_SUPPORT = True
@@ -592,7 +589,9 @@ later is required to fix a server side protocol bug.
"--jobs or 1). Ignored unless --no-interleaved is set",
)
jobs_checkout_default = self._GetHelpForCpuJobCount(DEFAULT_LOCAL_JOBS)
jobs_checkout_default = self._GetHelpForCpuJobCount(
command.DEFAULT_LOCAL_JOBS
)
p.add_option(
"--jobs-checkout",
default=None,
@@ -2389,7 +2388,7 @@ later is required to fix a server side protocol bug.
if not opt.jobs_network:
opt.jobs_network = 1
if not opt.jobs_checkout:
opt.jobs_checkout = DEFAULT_LOCAL_JOBS
opt.jobs_checkout = command.DEFAULT_LOCAL_JOBS
opt.jobs = os.cpu_count()
# Try to stay under user rlimit settings.
+3 -4
View File
@@ -19,8 +19,7 @@ import re
import sys
from typing import List
from command import DEFAULT_LOCAL_JOBS
from command import InteractiveCommand
import command
import editor
import error
import git_refs
@@ -104,7 +103,7 @@ def _SplitEmails(values):
return result
class Upload(InteractiveCommand):
class Upload(command.InteractiveCommand):
COMMON = True
helpSummary = "Upload changes for code review"
helpUsage = """
@@ -211,7 +210,7 @@ threshold to a different value.
Gerrit Code Review: https://www.gerritcodereview.com/
"""
PARALLEL_JOBS = DEFAULT_LOCAL_JOBS
PARALLEL_JOBS = command.DEFAULT_LOCAL_JOBS
def _Options(self, p):
p.add_option(
+2 -3
View File
@@ -16,14 +16,13 @@ import platform
import sys
from typing import Any, Tuple
from command import Command
from command import MirrorSafeCommand
import command
import git_command
import git_refs
import wrapper
class Version(Command, MirrorSafeCommand):
class Version(command.Command, command.MirrorSafeCommand):
wrapper_version = None
wrapper_path = None
+2 -2
View File
@@ -16,7 +16,7 @@ import os
import sys
from typing import List
from command import Command
import command
import error
import platform_utils
from project import DeleteWorktreeError
@@ -26,7 +26,7 @@ class Error(error.RepoExitError):
"""Exit error when wipe command fails."""
class Wipe(Command):
class Wipe(command.Command):
"""Delete projects from the worktree and .repo"""
COMMON = True
+1 -1
View File
@@ -360,7 +360,7 @@ def test_jobs_checkout_help_default(
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(
with mock.patch.object(command, "DEFAULT_LOCAL_JOBS", 7), mock.patch.object(
command,
"GENERATE_MANPAGES",
generate_manpages,