diff options
Diffstat (limited to 'project.py')
-rw-r--r-- | project.py | 69 |
1 files changed, 29 insertions, 40 deletions
@@ -365,19 +365,19 @@ def _SafeExpandPath(base, subpath, skipfinal=False): | |||
365 | for part in components: | 365 | for part in components: |
366 | if part in {".", ".."}: | 366 | if part in {".", ".."}: |
367 | raise ManifestInvalidPathError( | 367 | raise ManifestInvalidPathError( |
368 | '%s: "%s" not allowed in paths' % (subpath, part) | 368 | f'{subpath}: "{part}" not allowed in paths' |
369 | ) | 369 | ) |
370 | 370 | ||
371 | path = os.path.join(path, part) | 371 | path = os.path.join(path, part) |
372 | if platform_utils.islink(path): | 372 | if platform_utils.islink(path): |
373 | raise ManifestInvalidPathError( | 373 | raise ManifestInvalidPathError( |
374 | "%s: traversing symlinks not allow" % (path,) | 374 | f"{path}: traversing symlinks not allow" |
375 | ) | 375 | ) |
376 | 376 | ||
377 | if os.path.exists(path): | 377 | if os.path.exists(path): |
378 | if not os.path.isfile(path) and not platform_utils.isdir(path): | 378 | if not os.path.isfile(path) and not platform_utils.isdir(path): |
379 | raise ManifestInvalidPathError( | 379 | raise ManifestInvalidPathError( |
380 | "%s: only regular files & directories allowed" % (path,) | 380 | f"{path}: only regular files & directories allowed" |
381 | ) | 381 | ) |
382 | 382 | ||
383 | if skipfinal: | 383 | if skipfinal: |
@@ -409,11 +409,11 @@ class _CopyFile: | |||
409 | 409 | ||
410 | if platform_utils.isdir(src): | 410 | if platform_utils.isdir(src): |
411 | raise ManifestInvalidPathError( | 411 | raise ManifestInvalidPathError( |
412 | "%s: copying from directory not supported" % (self.src,) | 412 | f"{self.src}: copying from directory not supported" |
413 | ) | 413 | ) |
414 | if platform_utils.isdir(dest): | 414 | if platform_utils.isdir(dest): |
415 | raise ManifestInvalidPathError( | 415 | raise ManifestInvalidPathError( |
416 | "%s: copying to directory not allowed" % (self.dest,) | 416 | f"{self.dest}: copying to directory not allowed" |
417 | ) | 417 | ) |
418 | 418 | ||
419 | # Copy file if it does not exist or is out of date. | 419 | # Copy file if it does not exist or is out of date. |
@@ -957,15 +957,11 @@ class Project: | |||
957 | f_status = "-" | 957 | f_status = "-" |
958 | 958 | ||
959 | if i and i.src_path: | 959 | if i and i.src_path: |
960 | line = " %s%s\t%s => %s (%s%%)" % ( | 960 | line = ( |
961 | i_status, | 961 | f" {i_status}{f_status}\t{i.src_path} => {p} ({i.level}%)" |
962 | f_status, | ||
963 | i.src_path, | ||
964 | p, | ||
965 | i.level, | ||
966 | ) | 962 | ) |
967 | else: | 963 | else: |
968 | line = " %s%s\t%s" % (i_status, f_status, p) | 964 | line = f" {i_status}{f_status}\t{p}" |
969 | 965 | ||
970 | if i and not f: | 966 | if i and not f: |
971 | out.added("%s", line) | 967 | out.added("%s", line) |
@@ -1157,7 +1153,7 @@ class Project: | |||
1157 | if dest_branch.startswith(R_HEADS): | 1153 | if dest_branch.startswith(R_HEADS): |
1158 | dest_branch = dest_branch[len(R_HEADS) :] | 1154 | dest_branch = dest_branch[len(R_HEADS) :] |
1159 | 1155 | ||
1160 | ref_spec = "%s:refs/for/%s" % (R_HEADS + branch.name, dest_branch) | 1156 | ref_spec = f"{R_HEADS + branch.name}:refs/for/{dest_branch}" |
1161 | opts = [] | 1157 | opts = [] |
1162 | if auto_topic: | 1158 | if auto_topic: |
1163 | opts += ["topic=" + branch.name] | 1159 | opts += ["topic=" + branch.name] |
@@ -1182,7 +1178,7 @@ class Project: | |||
1182 | GitCommand(self, cmd, bare=True, verify_command=True).Wait() | 1178 | GitCommand(self, cmd, bare=True, verify_command=True).Wait() |
1183 | 1179 | ||
1184 | if not dryrun: | 1180 | if not dryrun: |
1185 | msg = "posted to %s for %s" % (branch.remote.review, dest_branch) | 1181 | msg = f"posted to {branch.remote.review} for {dest_branch}" |
1186 | self.bare_git.UpdateRef( | 1182 | self.bare_git.UpdateRef( |
1187 | R_PUB + branch.name, R_HEADS + branch.name, message=msg | 1183 | R_PUB + branch.name, R_HEADS + branch.name, message=msg |
1188 | ) | 1184 | ) |
@@ -1444,7 +1440,7 @@ class Project: | |||
1444 | return self.bare_git.rev_list(self.revisionExpr, "-1")[0] | 1440 | return self.bare_git.rev_list(self.revisionExpr, "-1")[0] |
1445 | except GitError: | 1441 | except GitError: |
1446 | raise ManifestInvalidRevisionError( | 1442 | raise ManifestInvalidRevisionError( |
1447 | "revision %s in %s not found" % (self.revisionExpr, self.name) | 1443 | f"revision {self.revisionExpr} in {self.name} not found" |
1448 | ) | 1444 | ) |
1449 | 1445 | ||
1450 | def GetRevisionId(self, all_refs=None): | 1446 | def GetRevisionId(self, all_refs=None): |
@@ -1461,7 +1457,7 @@ class Project: | |||
1461 | return self.bare_git.rev_parse("--verify", "%s^0" % rev) | 1457 | return self.bare_git.rev_parse("--verify", "%s^0" % rev) |
1462 | except GitError: | 1458 | except GitError: |
1463 | raise ManifestInvalidRevisionError( | 1459 | raise ManifestInvalidRevisionError( |
1464 | "revision %s in %s not found" % (self.revisionExpr, self.name) | 1460 | f"revision {self.revisionExpr} in {self.name} not found" |
1465 | ) | 1461 | ) |
1466 | 1462 | ||
1467 | def SetRevisionId(self, revisionId): | 1463 | def SetRevisionId(self, revisionId): |
@@ -1773,9 +1769,7 @@ class Project: | |||
1773 | raise DeleteDirtyWorktreeError(msg, project=self) | 1769 | raise DeleteDirtyWorktreeError(msg, project=self) |
1774 | 1770 | ||
1775 | if not quiet: | 1771 | if not quiet: |
1776 | print( | 1772 | print(f"{self.RelPath(local=False)}: Deleting obsolete checkout.") |
1777 | "%s: Deleting obsolete checkout." % (self.RelPath(local=False),) | ||
1778 | ) | ||
1779 | 1773 | ||
1780 | # Unlock and delink from the main worktree. We don't use git's worktree | 1774 | # Unlock and delink from the main worktree. We don't use git's worktree |
1781 | # remove because it will recursively delete projects -- we handle that | 1775 | # remove because it will recursively delete projects -- we handle that |
@@ -1968,7 +1962,7 @@ class Project: | |||
1968 | # target branch, but otherwise take no other action. | 1962 | # target branch, but otherwise take no other action. |
1969 | _lwrite( | 1963 | _lwrite( |
1970 | self.work_git.GetDotgitPath(subpath=HEAD), | 1964 | self.work_git.GetDotgitPath(subpath=HEAD), |
1971 | "ref: %s%s\n" % (R_HEADS, name), | 1965 | f"ref: {R_HEADS}{name}\n", |
1972 | ) | 1966 | ) |
1973 | return True | 1967 | return True |
1974 | 1968 | ||
@@ -2277,7 +2271,7 @@ class Project: | |||
2277 | self.config.SetString("core.repositoryFormatVersion", str(version)) | 2271 | self.config.SetString("core.repositoryFormatVersion", str(version)) |
2278 | 2272 | ||
2279 | # Enable the extension! | 2273 | # Enable the extension! |
2280 | self.config.SetString("extensions.%s" % (key,), value) | 2274 | self.config.SetString(f"extensions.{key}", value) |
2281 | 2275 | ||
2282 | def ResolveRemoteHead(self, name=None): | 2276 | def ResolveRemoteHead(self, name=None): |
2283 | """Find out what the default branch (HEAD) points to. | 2277 | """Find out what the default branch (HEAD) points to. |
@@ -2447,7 +2441,7 @@ class Project: | |||
2447 | old_packed_lines = [] | 2441 | old_packed_lines = [] |
2448 | 2442 | ||
2449 | for r in sorted(all_refs): | 2443 | for r in sorted(all_refs): |
2450 | line = "%s %s\n" % (all_refs[r], r) | 2444 | line = f"{all_refs[r]} {r}\n" |
2451 | tmp_packed_lines.append(line) | 2445 | tmp_packed_lines.append(line) |
2452 | if r not in tmp: | 2446 | if r not in tmp: |
2453 | old_packed_lines.append(line) | 2447 | old_packed_lines.append(line) |
@@ -2617,7 +2611,7 @@ class Project: | |||
2617 | # one. | 2611 | # one. |
2618 | if not verbose and gitcmd.stdout: | 2612 | if not verbose and gitcmd.stdout: |
2619 | print( | 2613 | print( |
2620 | "\n%s:\n%s" % (self.name, gitcmd.stdout), | 2614 | f"\n{self.name}:\n{gitcmd.stdout}", |
2621 | end="", | 2615 | end="", |
2622 | file=output_redir, | 2616 | file=output_redir, |
2623 | ) | 2617 | ) |
@@ -2752,7 +2746,7 @@ class Project: | |||
2752 | proc = None | 2746 | proc = None |
2753 | with Trace("Fetching bundle: %s", " ".join(cmd)): | 2747 | with Trace("Fetching bundle: %s", " ".join(cmd)): |
2754 | if verbose: | 2748 | if verbose: |
2755 | print("%s: Downloading bundle: %s" % (self.name, srcUrl)) | 2749 | print(f"{self.name}: Downloading bundle: {srcUrl}") |
2756 | stdout = None if verbose else subprocess.PIPE | 2750 | stdout = None if verbose else subprocess.PIPE |
2757 | stderr = None if verbose else subprocess.STDOUT | 2751 | stderr = None if verbose else subprocess.STDOUT |
2758 | try: | 2752 | try: |
@@ -2810,7 +2804,7 @@ class Project: | |||
2810 | if GitCommand(self, cmd).Wait() != 0: | 2804 | if GitCommand(self, cmd).Wait() != 0: |
2811 | if self._allrefs: | 2805 | if self._allrefs: |
2812 | raise GitError( | 2806 | raise GitError( |
2813 | "%s checkout %s " % (self.name, rev), project=self.name | 2807 | f"{self.name} checkout {rev} ", project=self.name |
2814 | ) | 2808 | ) |
2815 | 2809 | ||
2816 | def _CherryPick(self, rev, ffonly=False, record_origin=False): | 2810 | def _CherryPick(self, rev, ffonly=False, record_origin=False): |
@@ -2824,7 +2818,7 @@ class Project: | |||
2824 | if GitCommand(self, cmd).Wait() != 0: | 2818 | if GitCommand(self, cmd).Wait() != 0: |
2825 | if self._allrefs: | 2819 | if self._allrefs: |
2826 | raise GitError( | 2820 | raise GitError( |
2827 | "%s cherry-pick %s " % (self.name, rev), project=self.name | 2821 | f"{self.name} cherry-pick {rev} ", project=self.name |
2828 | ) | 2822 | ) |
2829 | 2823 | ||
2830 | def _LsRemote(self, refs): | 2824 | def _LsRemote(self, refs): |
@@ -2841,9 +2835,7 @@ class Project: | |||
2841 | cmd.append("--") | 2835 | cmd.append("--") |
2842 | if GitCommand(self, cmd).Wait() != 0: | 2836 | if GitCommand(self, cmd).Wait() != 0: |
2843 | if self._allrefs: | 2837 | if self._allrefs: |
2844 | raise GitError( | 2838 | raise GitError(f"{self.name} revert {rev} ", project=self.name) |
2845 | "%s revert %s " % (self.name, rev), project=self.name | ||
2846 | ) | ||
2847 | 2839 | ||
2848 | def _ResetHard(self, rev, quiet=True): | 2840 | def _ResetHard(self, rev, quiet=True): |
2849 | cmd = ["reset", "--hard"] | 2841 | cmd = ["reset", "--hard"] |
@@ -2852,7 +2844,7 @@ class Project: | |||
2852 | cmd.append(rev) | 2844 | cmd.append(rev) |
2853 | if GitCommand(self, cmd).Wait() != 0: | 2845 | if GitCommand(self, cmd).Wait() != 0: |
2854 | raise GitError( | 2846 | raise GitError( |
2855 | "%s reset --hard %s " % (self.name, rev), project=self.name | 2847 | f"{self.name} reset --hard {rev} ", project=self.name |
2856 | ) | 2848 | ) |
2857 | 2849 | ||
2858 | def _SyncSubmodules(self, quiet=True): | 2850 | def _SyncSubmodules(self, quiet=True): |
@@ -2871,18 +2863,14 @@ class Project: | |||
2871 | cmd.extend(["--onto", onto]) | 2863 | cmd.extend(["--onto", onto]) |
2872 | cmd.append(upstream) | 2864 | cmd.append(upstream) |
2873 | if GitCommand(self, cmd).Wait() != 0: | 2865 | if GitCommand(self, cmd).Wait() != 0: |
2874 | raise GitError( | 2866 | raise GitError(f"{self.name} rebase {upstream} ", project=self.name) |
2875 | "%s rebase %s " % (self.name, upstream), project=self.name | ||
2876 | ) | ||
2877 | 2867 | ||
2878 | def _FastForward(self, head, ffonly=False): | 2868 | def _FastForward(self, head, ffonly=False): |
2879 | cmd = ["merge", "--no-stat", head] | 2869 | cmd = ["merge", "--no-stat", head] |
2880 | if ffonly: | 2870 | if ffonly: |
2881 | cmd.append("--ff-only") | 2871 | cmd.append("--ff-only") |
2882 | if GitCommand(self, cmd).Wait() != 0: | 2872 | if GitCommand(self, cmd).Wait() != 0: |
2883 | raise GitError( | 2873 | raise GitError(f"{self.name} merge {head} ", project=self.name) |
2884 | "%s merge %s " % (self.name, head), project=self.name | ||
2885 | ) | ||
2886 | 2874 | ||
2887 | def _InitGitDir(self, mirror_git=None, force_sync=False, quiet=False): | 2875 | def _InitGitDir(self, mirror_git=None, force_sync=False, quiet=False): |
2888 | init_git_dir = not os.path.exists(self.gitdir) | 2876 | init_git_dir = not os.path.exists(self.gitdir) |
@@ -3171,8 +3159,9 @@ class Project: | |||
3171 | "--force-sync not enabled; cannot overwrite a local " | 3159 | "--force-sync not enabled; cannot overwrite a local " |
3172 | "work tree. If you're comfortable with the " | 3160 | "work tree. If you're comfortable with the " |
3173 | "possibility of losing the work tree's git metadata," | 3161 | "possibility of losing the work tree's git metadata," |
3174 | " use `repo sync --force-sync {0}` to " | 3162 | " use " |
3175 | "proceed.".format(self.RelPath(local=False)), | 3163 | f"`repo sync --force-sync {self.RelPath(local=False)}` " |
3164 | "to proceed.", | ||
3176 | project=self.name, | 3165 | project=self.name, |
3177 | ) | 3166 | ) |
3178 | 3167 | ||
@@ -3686,12 +3675,12 @@ class Project: | |||
3686 | config = kwargs.pop("config", None) | 3675 | config = kwargs.pop("config", None) |
3687 | for k in kwargs: | 3676 | for k in kwargs: |
3688 | raise TypeError( | 3677 | raise TypeError( |
3689 | "%s() got an unexpected keyword argument %r" % (name, k) | 3678 | f"{name}() got an unexpected keyword argument {k!r}" |
3690 | ) | 3679 | ) |
3691 | if config is not None: | 3680 | if config is not None: |
3692 | for k, v in config.items(): | 3681 | for k, v in config.items(): |
3693 | cmdv.append("-c") | 3682 | cmdv.append("-c") |
3694 | cmdv.append("%s=%s" % (k, v)) | 3683 | cmdv.append(f"{k}={v}") |
3695 | cmdv.append(name) | 3684 | cmdv.append(name) |
3696 | cmdv.extend(args) | 3685 | cmdv.extend(args) |
3697 | p = GitCommand( | 3686 | p = GitCommand( |