diff options
| -rw-r--r-- | subcmds/abandon.py | 17 | ||||
| -rw-r--r-- | subcmds/checkout.py | 12 | ||||
| -rw-r--r-- | subcmds/cherry_pick.py | 22 | ||||
| -rw-r--r-- | subcmds/download.py | 49 | ||||
| -rw-r--r-- | subcmds/forall.py | 10 | ||||
| -rw-r--r-- | subcmds/grep.py | 8 | ||||
| -rw-r--r-- | subcmds/init.py | 18 | ||||
| -rw-r--r-- | subcmds/manifest.py | 16 | ||||
| -rw-r--r-- | subcmds/rebase.py | 32 | ||||
| -rw-r--r-- | subcmds/selfupdate.py | 7 | ||||
| -rw-r--r-- | subcmds/stage.py | 6 | ||||
| -rw-r--r-- | subcmds/upload.py | 39 |
12 files changed, 121 insertions, 115 deletions
diff --git a/subcmds/abandon.py b/subcmds/abandon.py index 996c3d2c..f6c0c66c 100644 --- a/subcmds/abandon.py +++ b/subcmds/abandon.py | |||
| @@ -15,7 +15,6 @@ | |||
| 15 | import collections | 15 | import collections |
| 16 | import functools | 16 | import functools |
| 17 | import itertools | 17 | import itertools |
| 18 | import sys | ||
| 19 | 18 | ||
| 20 | from command import Command | 19 | from command import Command |
| 21 | from command import DEFAULT_LOCAL_JOBS | 20 | from command import DEFAULT_LOCAL_JOBS |
| @@ -23,6 +22,10 @@ from error import RepoError | |||
| 23 | from error import RepoExitError | 22 | from error import RepoExitError |
| 24 | from git_command import git | 23 | from git_command import git |
| 25 | from progress import Progress | 24 | from progress import Progress |
| 25 | from repo_logging import RepoLogger | ||
| 26 | |||
| 27 | |||
| 28 | logger = RepoLogger(__file__) | ||
| 26 | 29 | ||
| 27 | 30 | ||
| 28 | class AbandonError(RepoExitError): | 31 | class AbandonError(RepoExitError): |
| @@ -126,18 +129,12 @@ It is equivalent to "git branch -D <branchname>". | |||
| 126 | if err: | 129 | if err: |
| 127 | for br in err.keys(): | 130 | for br in err.keys(): |
| 128 | err_msg = "error: cannot abandon %s" % br | 131 | err_msg = "error: cannot abandon %s" % br |
| 129 | print(err_msg, file=sys.stderr) | 132 | logger.error(err_msg) |
| 130 | for proj in err[br]: | 133 | for proj in err[br]: |
| 131 | print( | 134 | logger.error(" " * len(err_msg) + " | %s", _RelPath(proj)) |
| 132 | " " * len(err_msg) + " | %s" % _RelPath(proj), | ||
| 133 | file=sys.stderr, | ||
| 134 | ) | ||
| 135 | raise AbandonError(aggregate_errors=aggregate_errors) | 135 | raise AbandonError(aggregate_errors=aggregate_errors) |
| 136 | elif not success: | 136 | elif not success: |
| 137 | print( | 137 | logger.error("error: no project has local branch(es) : %s", nb) |
| 138 | "error: no project has local branch(es) : %s" % nb, | ||
| 139 | file=sys.stderr, | ||
| 140 | ) | ||
| 141 | raise AbandonError(aggregate_errors=aggregate_errors) | 138 | raise AbandonError(aggregate_errors=aggregate_errors) |
| 142 | else: | 139 | else: |
| 143 | # Everything below here is displaying status. | 140 | # Everything below here is displaying status. |
diff --git a/subcmds/checkout.py b/subcmds/checkout.py index 67f1838c..ea48263e 100644 --- a/subcmds/checkout.py +++ b/subcmds/checkout.py | |||
| @@ -13,7 +13,6 @@ | |||
| 13 | # limitations under the License. | 13 | # limitations under the License. |
| 14 | 14 | ||
| 15 | import functools | 15 | import functools |
| 16 | import sys | ||
| 17 | from typing import NamedTuple | 16 | from typing import NamedTuple |
| 18 | 17 | ||
| 19 | from command import Command | 18 | from command import Command |
| @@ -22,6 +21,10 @@ from error import GitError | |||
| 22 | from error import RepoExitError | 21 | from error import RepoExitError |
| 23 | from progress import Progress | 22 | from progress import Progress |
| 24 | from project import Project | 23 | from project import Project |
| 24 | from repo_logging import RepoLogger | ||
| 25 | |||
| 26 | |||
| 27 | logger = RepoLogger(__file__) | ||
| 25 | 28 | ||
| 26 | 29 | ||
| 27 | class CheckoutBranchResult(NamedTuple): | 30 | class CheckoutBranchResult(NamedTuple): |
| @@ -99,12 +102,9 @@ The command is equivalent to: | |||
| 99 | 102 | ||
| 100 | if err_projects: | 103 | if err_projects: |
| 101 | for p in err_projects: | 104 | for p in err_projects: |
| 102 | print( | 105 | logger.error("error: %s/: cannot checkout %s", p.relpath, nb) |
| 103 | "error: %s/: cannot checkout %s" % (p.relpath, nb), | ||
| 104 | file=sys.stderr, | ||
| 105 | ) | ||
| 106 | raise CheckoutCommandError(aggregate_errors=err) | 106 | raise CheckoutCommandError(aggregate_errors=err) |
| 107 | elif not success: | 107 | elif not success: |
| 108 | msg = f"error: no project has branch {nb}" | 108 | msg = f"error: no project has branch {nb}" |
| 109 | print(msg, file=sys.stderr) | 109 | logger.error(msg) |
| 110 | raise MissingBranchError(msg) | 110 | raise MissingBranchError(msg) |
diff --git a/subcmds/cherry_pick.py b/subcmds/cherry_pick.py index 980720eb..f9ae3e32 100644 --- a/subcmds/cherry_pick.py +++ b/subcmds/cherry_pick.py | |||
| @@ -18,9 +18,11 @@ import sys | |||
| 18 | from command import Command | 18 | from command import Command |
| 19 | from error import GitError | 19 | from error import GitError |
| 20 | from git_command import GitCommand | 20 | from git_command import GitCommand |
| 21 | from repo_logging import RepoLogger | ||
| 21 | 22 | ||
| 22 | 23 | ||
| 23 | CHANGE_ID_RE = re.compile(r"^\s*Change-Id: I([0-9a-f]{40})\s*$") | 24 | CHANGE_ID_RE = re.compile(r"^\s*Change-Id: I([0-9a-f]{40})\s*$") |
| 25 | logger = RepoLogger(__file__) | ||
| 24 | 26 | ||
| 25 | 27 | ||
| 26 | class CherryPick(Command): | 28 | class CherryPick(Command): |
| @@ -52,7 +54,7 @@ change id will be added. | |||
| 52 | try: | 54 | try: |
| 53 | p.Wait() | 55 | p.Wait() |
| 54 | except GitError: | 56 | except GitError: |
| 55 | print(p.stderr, file=sys.stderr) | 57 | logger.error(p.stderr) |
| 56 | raise | 58 | raise |
| 57 | 59 | ||
| 58 | sha1 = p.stdout.strip() | 60 | sha1 = p.stdout.strip() |
| @@ -67,9 +69,7 @@ change id will be added. | |||
| 67 | try: | 69 | try: |
| 68 | p.Wait() | 70 | p.Wait() |
| 69 | except GitError: | 71 | except GitError: |
| 70 | print( | 72 | logger.error("error: Failed to retrieve old commit message") |
| 71 | "error: Failed to retrieve old commit message", file=sys.stderr | ||
| 72 | ) | ||
| 73 | raise | 73 | raise |
| 74 | 74 | ||
| 75 | old_msg = self._StripHeader(p.stdout) | 75 | old_msg = self._StripHeader(p.stdout) |
| @@ -85,14 +85,13 @@ change id will be added. | |||
| 85 | try: | 85 | try: |
| 86 | p.Wait() | 86 | p.Wait() |
| 87 | except GitError as e: | 87 | except GitError as e: |
| 88 | print(str(e)) | 88 | logger.error(e) |
| 89 | print( | 89 | logger.warn( |
| 90 | "NOTE: When committing (please see above) and editing the " | 90 | "NOTE: When committing (please see above) and editing the " |
| 91 | "commit message, please remove the old Change-Id-line and " | 91 | "commit message, please remove the old Change-Id-line and " |
| 92 | "add:" | 92 | "add:\n%s", |
| 93 | self._GetReference(sha1), | ||
| 93 | ) | 94 | ) |
| 94 | print(self._GetReference(sha1), file=sys.stderr) | ||
| 95 | print(file=sys.stderr) | ||
| 96 | raise | 95 | raise |
| 97 | 96 | ||
| 98 | if p.stdout: | 97 | if p.stdout: |
| @@ -115,10 +114,7 @@ change id will be added. | |||
| 115 | try: | 114 | try: |
| 116 | p.Wait() | 115 | p.Wait() |
| 117 | except GitError: | 116 | except GitError: |
| 118 | print( | 117 | logger.error("error: Failed to update commit message") |
| 119 | "error: Failed to update commit message", | ||
| 120 | file=sys.stderr, | ||
| 121 | ) | ||
| 122 | raise | 118 | raise |
| 123 | 119 | ||
| 124 | def _IsChangeId(self, line): | 120 | def _IsChangeId(self, line): |
diff --git a/subcmds/download.py b/subcmds/download.py index e33698e1..4396c9e7 100644 --- a/subcmds/download.py +++ b/subcmds/download.py | |||
| @@ -19,9 +19,11 @@ from command import Command | |||
| 19 | from error import GitError | 19 | from error import GitError |
| 20 | from error import NoSuchProjectError | 20 | from error import NoSuchProjectError |
| 21 | from error import RepoExitError | 21 | from error import RepoExitError |
| 22 | from repo_logging import RepoLogger | ||
| 22 | 23 | ||
| 23 | 24 | ||
| 24 | CHANGE_RE = re.compile(r"^([1-9][0-9]*)(?:[/\.-]([1-9][0-9]*))?$") | 25 | CHANGE_RE = re.compile(r"^([1-9][0-9]*)(?:[/\.-]([1-9][0-9]*))?$") |
| 26 | logger = RepoLogger(__file__) | ||
| 25 | 27 | ||
| 26 | 28 | ||
| 27 | class DownloadCommandError(RepoExitError): | 29 | class DownloadCommandError(RepoExitError): |
| @@ -109,21 +111,16 @@ If no project is specified try to use current directory as a project. | |||
| 109 | except NoSuchProjectError: | 111 | except NoSuchProjectError: |
| 110 | project = None | 112 | project = None |
| 111 | if project not in projects: | 113 | if project not in projects: |
| 112 | print( | 114 | logger.error( |
| 113 | "error: %s matches too many projects; please " | 115 | "error: %s matches too many projects; please " |
| 114 | "re-run inside the project checkout." % (a,), | 116 | "re-run inside the project checkout.", |
| 115 | file=sys.stderr, | 117 | a, |
| 116 | ) | 118 | ) |
| 117 | for project in projects: | 119 | for project in projects: |
| 118 | print( | 120 | logger.error( |
| 119 | " %s/ @ %s" | 121 | " %s/ @ %s", |
| 120 | % ( | 122 | project.RelPath(local=opt.this_manifest_only), |
| 121 | project.RelPath( | 123 | project.revisionExpr, |
| 122 | local=opt.this_manifest_only | ||
| 123 | ), | ||
| 124 | project.revisionExpr, | ||
| 125 | ), | ||
| 126 | file=sys.stderr, | ||
| 127 | ) | 124 | ) |
| 128 | raise NoSuchProjectError() | 125 | raise NoSuchProjectError() |
| 129 | else: | 126 | else: |
| @@ -156,18 +153,21 @@ If no project is specified try to use current directory as a project. | |||
| 156 | dl = project.DownloadPatchSet(change_id, ps_id) | 153 | dl = project.DownloadPatchSet(change_id, ps_id) |
| 157 | 154 | ||
| 158 | if not opt.revert and not dl.commits: | 155 | if not opt.revert and not dl.commits: |
| 159 | print( | 156 | logger.error( |
| 160 | "[%s] change %d/%d has already been merged" | 157 | "[%s] change %d/%d has already been merged", |
| 161 | % (project.name, change_id, ps_id), | 158 | project.name, |
| 162 | file=sys.stderr, | 159 | change_id, |
| 160 | ps_id, | ||
| 163 | ) | 161 | ) |
| 164 | continue | 162 | continue |
| 165 | 163 | ||
| 166 | if len(dl.commits) > 1: | 164 | if len(dl.commits) > 1: |
| 167 | print( | 165 | logger.error( |
| 168 | "[%s] %d/%d depends on %d unmerged changes:" | 166 | "[%s] %d/%d depends on %d unmerged changes:", |
| 169 | % (project.name, change_id, ps_id, len(dl.commits)), | 167 | project.name, |
| 170 | file=sys.stderr, | 168 | change_id, |
| 169 | ps_id, | ||
| 170 | len(dl.commits), | ||
| 171 | ) | 171 | ) |
| 172 | for c in dl.commits: | 172 | for c in dl.commits: |
| 173 | print(" %s" % (c), file=sys.stderr) | 173 | print(" %s" % (c), file=sys.stderr) |
| @@ -204,9 +204,10 @@ If no project is specified try to use current directory as a project. | |||
| 204 | project._Checkout(dl.commit) | 204 | project._Checkout(dl.commit) |
| 205 | 205 | ||
| 206 | except GitError: | 206 | except GitError: |
| 207 | print( | 207 | logger.error( |
| 208 | "[%s] Could not complete the %s of %s" | 208 | "[%s] Could not complete the %s of %s", |
| 209 | % (project.name, mode, dl.commit), | 209 | project.name, |
| 210 | file=sys.stderr, | 210 | mode, |
| 211 | dl.commit, | ||
| 211 | ) | 212 | ) |
| 212 | raise | 213 | raise |
diff --git a/subcmds/forall.py b/subcmds/forall.py index 9a02c49f..287f2e04 100644 --- a/subcmds/forall.py +++ b/subcmds/forall.py | |||
| @@ -28,8 +28,10 @@ from command import DEFAULT_LOCAL_JOBS | |||
| 28 | from command import MirrorSafeCommand | 28 | from command import MirrorSafeCommand |
| 29 | from command import WORKER_BATCH_SIZE | 29 | from command import WORKER_BATCH_SIZE |
| 30 | from error import ManifestInvalidRevisionError | 30 | from error import ManifestInvalidRevisionError |
| 31 | from repo_logging import RepoLogger | ||
| 31 | 32 | ||
| 32 | 33 | ||
| 34 | logger = RepoLogger(__file__) | ||
| 33 | _CAN_COLOR = [ | 35 | _CAN_COLOR = [ |
| 34 | "branch", | 36 | "branch", |
| 35 | "diff", | 37 | "diff", |
| @@ -293,10 +295,10 @@ without iterating through the remaining projects. | |||
| 293 | rc = rc or errno.EINTR | 295 | rc = rc or errno.EINTR |
| 294 | except Exception as e: | 296 | except Exception as e: |
| 295 | # Catch any other exceptions raised | 297 | # Catch any other exceptions raised |
| 296 | print( | 298 | logger.error( |
| 297 | "forall: unhandled error, terminating the pool: %s: %s" | 299 | "forall: unhandled error, terminating the pool: %s: %s", |
| 298 | % (type(e).__name__, e), | 300 | type(e).__name__, |
| 299 | file=sys.stderr, | 301 | e, |
| 300 | ) | 302 | ) |
| 301 | rc = rc or getattr(e, "errno", 1) | 303 | rc = rc or getattr(e, "errno", 1) |
| 302 | if rc != 0: | 304 | if rc != 0: |
diff --git a/subcmds/grep.py b/subcmds/grep.py index 19c06d4d..b677b6bd 100644 --- a/subcmds/grep.py +++ b/subcmds/grep.py | |||
| @@ -24,6 +24,10 @@ from error import InvalidArgumentsError | |||
| 24 | from error import SilentRepoExitError | 24 | from error import SilentRepoExitError |
| 25 | from git_command import GitCommand | 25 | from git_command import GitCommand |
| 26 | from project import Project | 26 | from project import Project |
| 27 | from repo_logging import RepoLogger | ||
| 28 | |||
| 29 | |||
| 30 | logger = RepoLogger(__file__) | ||
| 27 | 31 | ||
| 28 | 32 | ||
| 29 | class GrepColoring(Coloring): | 33 | class GrepColoring(Coloring): |
| @@ -371,7 +375,7 @@ contain a line that matches both expressions: | |||
| 371 | if opt.revision: | 375 | if opt.revision: |
| 372 | if "--cached" in cmd_argv: | 376 | if "--cached" in cmd_argv: |
| 373 | msg = "fatal: cannot combine --cached and --revision" | 377 | msg = "fatal: cannot combine --cached and --revision" |
| 374 | print(msg, file=sys.stderr) | 378 | logger.error(msg) |
| 375 | raise InvalidArgumentsError(msg) | 379 | raise InvalidArgumentsError(msg) |
| 376 | have_rev = True | 380 | have_rev = True |
| 377 | cmd_argv.extend(opt.revision) | 381 | cmd_argv.extend(opt.revision) |
| @@ -396,5 +400,5 @@ contain a line that matches both expressions: | |||
| 396 | sys.exit(0) | 400 | sys.exit(0) |
| 397 | elif have_rev and bad_rev: | 401 | elif have_rev and bad_rev: |
| 398 | for r in opt.revision: | 402 | for r in opt.revision: |
| 399 | print("error: can't search revision %s" % r, file=sys.stderr) | 403 | logger.error("error: can't search revision %s", r) |
| 400 | raise GrepCommandError(aggregate_errors=errors) | 404 | raise GrepCommandError(aggregate_errors=errors) |
diff --git a/subcmds/init.py b/subcmds/init.py index 529b212b..9ac42d8e 100644 --- a/subcmds/init.py +++ b/subcmds/init.py | |||
| @@ -23,9 +23,12 @@ from error import UpdateManifestError | |||
| 23 | from git_command import git_require | 23 | from git_command import git_require |
| 24 | from git_command import MIN_GIT_VERSION_HARD | 24 | from git_command import MIN_GIT_VERSION_HARD |
| 25 | from git_command import MIN_GIT_VERSION_SOFT | 25 | from git_command import MIN_GIT_VERSION_SOFT |
| 26 | from repo_logging import RepoLogger | ||
| 26 | from wrapper import Wrapper | 27 | from wrapper import Wrapper |
| 27 | 28 | ||
| 28 | 29 | ||
| 30 | logger = RepoLogger(__file__) | ||
| 31 | |||
| 29 | _REPO_ALLOW_SHALLOW = os.environ.get("REPO_ALLOW_SHALLOW") | 32 | _REPO_ALLOW_SHALLOW = os.environ.get("REPO_ALLOW_SHALLOW") |
| 30 | 33 | ||
| 31 | 34 | ||
| @@ -330,11 +333,11 @@ to update the working directory files. | |||
| 330 | def Execute(self, opt, args): | 333 | def Execute(self, opt, args): |
| 331 | git_require(MIN_GIT_VERSION_HARD, fail=True) | 334 | git_require(MIN_GIT_VERSION_HARD, fail=True) |
| 332 | if not git_require(MIN_GIT_VERSION_SOFT): | 335 | if not git_require(MIN_GIT_VERSION_SOFT): |
| 333 | print( | 336 | logger.warning( |
| 334 | "repo: warning: git-%s+ will soon be required; please upgrade " | 337 | "repo: warning: git-%s+ will soon be required; " |
| 335 | "your version of git to maintain support." | 338 | "please upgrade your version of git to maintain " |
| 336 | % (".".join(str(x) for x in MIN_GIT_VERSION_SOFT),), | 339 | "support.", |
| 337 | file=sys.stderr, | 340 | ".".join(str(x) for x in MIN_GIT_VERSION_SOFT), |
| 338 | ) | 341 | ) |
| 339 | 342 | ||
| 340 | rp = self.manifest.repoProject | 343 | rp = self.manifest.repoProject |
| @@ -357,10 +360,7 @@ to update the working directory files. | |||
| 357 | ) | 360 | ) |
| 358 | except wrapper.CloneFailure as e: | 361 | except wrapper.CloneFailure as e: |
| 359 | err_msg = "fatal: double check your --repo-rev setting." | 362 | err_msg = "fatal: double check your --repo-rev setting." |
| 360 | print( | 363 | logger.error(err_msg) |
| 361 | err_msg, | ||
| 362 | file=sys.stderr, | ||
| 363 | ) | ||
| 364 | self.git_event_log.ErrorEvent(err_msg) | 364 | self.git_event_log.ErrorEvent(err_msg) |
| 365 | raise RepoUnhandledExceptionError(e) | 365 | raise RepoUnhandledExceptionError(e) |
| 366 | 366 | ||
diff --git a/subcmds/manifest.py b/subcmds/manifest.py index f72df348..101240d1 100644 --- a/subcmds/manifest.py +++ b/subcmds/manifest.py | |||
| @@ -17,6 +17,10 @@ import os | |||
| 17 | import sys | 17 | import sys |
| 18 | 18 | ||
| 19 | from command import PagedCommand | 19 | from command import PagedCommand |
| 20 | from repo_logging import RepoLogger | ||
| 21 | |||
| 22 | |||
| 23 | logger = RepoLogger(__file__) | ||
| 20 | 24 | ||
| 21 | 25 | ||
| 22 | class Manifest(PagedCommand): | 26 | class Manifest(PagedCommand): |
| @@ -132,7 +136,7 @@ to indicate the remote ref to push changes to via 'repo upload'. | |||
| 132 | manifest.SetUseLocalManifests(not opt.ignore_local_manifests) | 136 | manifest.SetUseLocalManifests(not opt.ignore_local_manifests) |
| 133 | 137 | ||
| 134 | if opt.json: | 138 | if opt.json: |
| 135 | print("warning: --json is experimental!", file=sys.stderr) | 139 | logger.warn("warning: --json is experimental!") |
| 136 | doc = manifest.ToDict( | 140 | doc = manifest.ToDict( |
| 137 | peg_rev=opt.peg_rev, | 141 | peg_rev=opt.peg_rev, |
| 138 | peg_rev_upstream=opt.peg_rev_upstream, | 142 | peg_rev_upstream=opt.peg_rev_upstream, |
| @@ -159,13 +163,13 @@ to indicate the remote ref to push changes to via 'repo upload'. | |||
| 159 | if output_file != "-": | 163 | if output_file != "-": |
| 160 | fd.close() | 164 | fd.close() |
| 161 | if manifest.path_prefix: | 165 | if manifest.path_prefix: |
| 162 | print( | 166 | logger.warn( |
| 163 | f"Saved {manifest.path_prefix} submanifest to " | 167 | "Saved %s submanifest to %s", |
| 164 | f"{output_file}", | 168 | manifest.path_prefix, |
| 165 | file=sys.stderr, | 169 | output_file, |
| 166 | ) | 170 | ) |
| 167 | else: | 171 | else: |
| 168 | print(f"Saved manifest to {output_file}", file=sys.stderr) | 172 | logger.warn("Saved manifest to %s", output_file) |
| 169 | 173 | ||
| 170 | def ValidateOptions(self, opt, args): | 174 | def ValidateOptions(self, opt, args): |
| 171 | if args: | 175 | if args: |
diff --git a/subcmds/rebase.py b/subcmds/rebase.py index c0e83adf..439557c2 100644 --- a/subcmds/rebase.py +++ b/subcmds/rebase.py | |||
| @@ -17,6 +17,10 @@ import sys | |||
| 17 | from color import Coloring | 17 | from color import Coloring |
| 18 | from command import Command | 18 | from command import Command |
| 19 | from git_command import GitCommand | 19 | from git_command import GitCommand |
| 20 | from repo_logging import RepoLogger | ||
| 21 | |||
| 22 | |||
| 23 | logger = RepoLogger(__file__) | ||
| 20 | 24 | ||
| 21 | 25 | ||
| 22 | class RebaseColoring(Coloring): | 26 | class RebaseColoring(Coloring): |
| @@ -104,17 +108,15 @@ branch but need to incorporate new upstream changes "underneath" them. | |||
| 104 | one_project = len(all_projects) == 1 | 108 | one_project = len(all_projects) == 1 |
| 105 | 109 | ||
| 106 | if opt.interactive and not one_project: | 110 | if opt.interactive and not one_project: |
| 107 | print( | 111 | logger.error( |
| 108 | "error: interactive rebase not supported with multiple " | 112 | "error: interactive rebase not supported with multiple projects" |
| 109 | "projects", | ||
| 110 | file=sys.stderr, | ||
| 111 | ) | 113 | ) |
| 114 | |||
| 112 | if len(args) == 1: | 115 | if len(args) == 1: |
| 113 | print( | 116 | logger.warn( |
| 114 | "note: project %s is mapped to more than one path" | 117 | "note: project %s is mapped to more than one path", args[0] |
| 115 | % (args[0],), | ||
| 116 | file=sys.stderr, | ||
| 117 | ) | 118 | ) |
| 119 | |||
| 118 | return 1 | 120 | return 1 |
| 119 | 121 | ||
| 120 | # Setup the common git rebase args that we use for all projects. | 122 | # Setup the common git rebase args that we use for all projects. |
| @@ -145,10 +147,9 @@ branch but need to incorporate new upstream changes "underneath" them. | |||
| 145 | cb = project.CurrentBranch | 147 | cb = project.CurrentBranch |
| 146 | if not cb: | 148 | if not cb: |
| 147 | if one_project: | 149 | if one_project: |
| 148 | print( | 150 | logger.error( |
| 149 | "error: project %s has a detached HEAD" | 151 | "error: project %s has a detached HEAD", |
| 150 | % _RelPath(project), | 152 | _RelPath(project), |
| 151 | file=sys.stderr, | ||
| 152 | ) | 153 | ) |
| 153 | return 1 | 154 | return 1 |
| 154 | # Ignore branches with detached HEADs. | 155 | # Ignore branches with detached HEADs. |
| @@ -157,10 +158,9 @@ branch but need to incorporate new upstream changes "underneath" them. | |||
| 157 | upbranch = project.GetBranch(cb) | 158 | upbranch = project.GetBranch(cb) |
| 158 | if not upbranch.LocalMerge: | 159 | if not upbranch.LocalMerge: |
| 159 | if one_project: | 160 | if one_project: |
| 160 | print( | 161 | logger.error( |
| 161 | "error: project %s does not track any remote branches" | 162 | "error: project %s does not track any remote branches", |
| 162 | % _RelPath(project), | 163 | _RelPath(project), |
| 163 | file=sys.stderr, | ||
| 164 | ) | 164 | ) |
| 165 | return 1 | 165 | return 1 |
| 166 | # Ignore branches without remotes. | 166 | # Ignore branches without remotes. |
diff --git a/subcmds/selfupdate.py b/subcmds/selfupdate.py index 51d963ee..72683097 100644 --- a/subcmds/selfupdate.py +++ b/subcmds/selfupdate.py | |||
| @@ -13,15 +13,18 @@ | |||
| 13 | # limitations under the License. | 13 | # limitations under the License. |
| 14 | 14 | ||
| 15 | import optparse | 15 | import optparse |
| 16 | import sys | ||
| 17 | 16 | ||
| 18 | from command import Command | 17 | from command import Command |
| 19 | from command import MirrorSafeCommand | 18 | from command import MirrorSafeCommand |
| 20 | from error import RepoExitError | 19 | from error import RepoExitError |
| 20 | from repo_logging import RepoLogger | ||
| 21 | from subcmds.sync import _PostRepoFetch | 21 | from subcmds.sync import _PostRepoFetch |
| 22 | from subcmds.sync import _PostRepoUpgrade | 22 | from subcmds.sync import _PostRepoUpgrade |
| 23 | 23 | ||
| 24 | 24 | ||
| 25 | logger = RepoLogger(__file__) | ||
| 26 | |||
| 27 | |||
| 25 | class SelfupdateError(RepoExitError): | 28 | class SelfupdateError(RepoExitError): |
| 26 | """Exit error for failed selfupdate command.""" | 29 | """Exit error for failed selfupdate command.""" |
| 27 | 30 | ||
| @@ -66,7 +69,7 @@ need to be performed by an end-user. | |||
| 66 | else: | 69 | else: |
| 67 | result = rp.Sync_NetworkHalf() | 70 | result = rp.Sync_NetworkHalf() |
| 68 | if result.error: | 71 | if result.error: |
| 69 | print("error: can't update repo", file=sys.stderr) | 72 | logger.error("error: can't update repo") |
| 70 | raise SelfupdateError(aggregate_errors=[result.error]) | 73 | raise SelfupdateError(aggregate_errors=[result.error]) |
| 71 | 74 | ||
| 72 | rp.bare_git.gc("--auto") | 75 | rp.bare_git.gc("--auto") |
diff --git a/subcmds/stage.py b/subcmds/stage.py index 4d54eb19..92a00ea0 100644 --- a/subcmds/stage.py +++ b/subcmds/stage.py | |||
| @@ -17,6 +17,10 @@ import sys | |||
| 17 | from color import Coloring | 17 | from color import Coloring |
| 18 | from command import InteractiveCommand | 18 | from command import InteractiveCommand |
| 19 | from git_command import GitCommand | 19 | from git_command import GitCommand |
| 20 | from repo_logging import RepoLogger | ||
| 21 | |||
| 22 | |||
| 23 | logger = RepoLogger(__file__) | ||
| 20 | 24 | ||
| 21 | 25 | ||
| 22 | class _ProjectList(Coloring): | 26 | class _ProjectList(Coloring): |
| @@ -62,7 +66,7 @@ The '%prog' command stages files to prepare the next commit. | |||
| 62 | if p.IsDirty() | 66 | if p.IsDirty() |
| 63 | ] | 67 | ] |
| 64 | if not all_projects: | 68 | if not all_projects: |
| 65 | print("no projects have uncommitted modifications", file=sys.stderr) | 69 | logger.error("no projects have uncommitted modifications") |
| 66 | return | 70 | return |
| 67 | 71 | ||
| 68 | out = _ProjectList(self.manifest.manifestProject.config) | 72 | out = _ProjectList(self.manifest.manifestProject.config) |
diff --git a/subcmds/upload.py b/subcmds/upload.py index ec89ad43..618a10e1 100644 --- a/subcmds/upload.py +++ b/subcmds/upload.py | |||
| @@ -29,10 +29,12 @@ from git_command import GitCommand | |||
| 29 | from git_refs import R_HEADS | 29 | from git_refs import R_HEADS |
| 30 | from hooks import RepoHook | 30 | from hooks import RepoHook |
| 31 | from project import ReviewableBranch | 31 | from project import ReviewableBranch |
| 32 | from repo_logging import RepoLogger | ||
| 32 | from subcmds.sync import LocalSyncState | 33 | from subcmds.sync import LocalSyncState |
| 33 | 34 | ||
| 34 | 35 | ||
| 35 | _DEFAULT_UNUSUAL_COMMIT_THRESHOLD = 5 | 36 | _DEFAULT_UNUSUAL_COMMIT_THRESHOLD = 5 |
| 37 | logger = RepoLogger(__file__) | ||
| 36 | 38 | ||
| 37 | 39 | ||
| 38 | class UploadExitError(SilentRepoExitError): | 40 | class UploadExitError(SilentRepoExitError): |
| @@ -70,16 +72,16 @@ def _VerifyPendingCommits(branches: List[ReviewableBranch]) -> bool: | |||
| 70 | # If any branch has many commits, prompt the user. | 72 | # If any branch has many commits, prompt the user. |
| 71 | if many_commits: | 73 | if many_commits: |
| 72 | if len(branches) > 1: | 74 | if len(branches) > 1: |
| 73 | print( | 75 | logger.warn( |
| 74 | "ATTENTION: One or more branches has an unusually high number " | 76 | "ATTENTION: One or more branches has an unusually high number " |
| 75 | "of commits." | 77 | "of commits." |
| 76 | ) | 78 | ) |
| 77 | else: | 79 | else: |
| 78 | print( | 80 | logger.warn( |
| 79 | "ATTENTION: You are uploading an unusually high number of " | 81 | "ATTENTION: You are uploading an unusually high number of " |
| 80 | "commits." | 82 | "commits." |
| 81 | ) | 83 | ) |
| 82 | print( | 84 | logger.warn( |
| 83 | "YOU PROBABLY DO NOT MEAN TO DO THIS. (Did you rebase across " | 85 | "YOU PROBABLY DO NOT MEAN TO DO THIS. (Did you rebase across " |
| 84 | "branches?)" | 86 | "branches?)" |
| 85 | ) | 87 | ) |
| @@ -93,7 +95,7 @@ def _VerifyPendingCommits(branches: List[ReviewableBranch]) -> bool: | |||
| 93 | 95 | ||
| 94 | def _die(fmt, *args): | 96 | def _die(fmt, *args): |
| 95 | msg = fmt % args | 97 | msg = fmt % args |
| 96 | print("error: %s" % msg, file=sys.stderr) | 98 | logger.error("error: %s", msg) |
| 97 | raise UploadExitError(msg) | 99 | raise UploadExitError(msg) |
| 98 | 100 | ||
| 99 | 101 | ||
| @@ -748,16 +750,13 @@ Gerrit Code Review: https://www.gerritcodereview.com/ | |||
| 748 | for result in results: | 750 | for result in results: |
| 749 | project, avail = result | 751 | project, avail = result |
| 750 | if avail is None: | 752 | if avail is None: |
| 751 | print( | 753 | logger.error( |
| 752 | 'repo: error: %s: Unable to upload branch "%s". ' | 754 | 'repo: error: %s: Unable to upload branch "%s". ' |
| 753 | "You might be able to fix the branch by running:\n" | 755 | "You might be able to fix the branch by running:\n" |
| 754 | " git branch --set-upstream-to m/%s" | 756 | " git branch --set-upstream-to m/%s", |
| 755 | % ( | 757 | project.RelPath(local=opt.this_manifest_only), |
| 756 | project.RelPath(local=opt.this_manifest_only), | 758 | project.CurrentBranch, |
| 757 | project.CurrentBranch, | 759 | project.manifest.branch, |
| 758 | project.manifest.branch, | ||
| 759 | ), | ||
| 760 | file=sys.stderr, | ||
| 761 | ) | 760 | ) |
| 762 | elif avail: | 761 | elif avail: |
| 763 | pending.append(result) | 762 | pending.append(result) |
| @@ -772,14 +771,11 @@ Gerrit Code Review: https://www.gerritcodereview.com/ | |||
| 772 | 771 | ||
| 773 | if not pending: | 772 | if not pending: |
| 774 | if opt.branch is None: | 773 | if opt.branch is None: |
| 775 | print( | 774 | logger.error("repo: error: no branches ready for upload") |
| 776 | "repo: error: no branches ready for upload", file=sys.stderr | ||
| 777 | ) | ||
| 778 | else: | 775 | else: |
| 779 | print( | 776 | logger.error( |
| 780 | 'repo: error: no branches named "%s" ready for upload' | 777 | 'repo: error: no branches named "%s" ready for upload', |
| 781 | % (opt.branch,), | 778 | opt.branch, |
| 782 | file=sys.stderr, | ||
| 783 | ) | 779 | ) |
| 784 | return 1 | 780 | return 1 |
| 785 | 781 | ||
| @@ -809,10 +805,9 @@ Gerrit Code Review: https://www.gerritcodereview.com/ | |||
| 809 | project_list=pending_proj_names, worktree_list=pending_worktrees | 805 | project_list=pending_proj_names, worktree_list=pending_worktrees |
| 810 | ): | 806 | ): |
| 811 | if LocalSyncState(manifest).IsPartiallySynced(): | 807 | if LocalSyncState(manifest).IsPartiallySynced(): |
| 812 | print( | 808 | logger.error( |
| 813 | "Partially synced tree detected. Syncing all projects " | 809 | "Partially synced tree detected. Syncing all projects " |
| 814 | "may resolve issues you're seeing.", | 810 | "may resolve issues you're seeing." |
| 815 | file=sys.stderr, | ||
| 816 | ) | 811 | ) |
| 817 | ret = 1 | 812 | ret = 1 |
| 818 | if ret: | 813 | if ret: |
