diff options
author | LaMont Jones <lamontjones@google.com> | 2022-06-22 19:21:15 +0000 |
---|---|---|
committer | LaMont Jones <lamontjones@google.com> | 2022-07-14 16:00:18 +0000 |
commit | 8501d4602a4c85f1e22c7a51ad191af8166efecd (patch) | |
tree | e8c5bf46c22f029412b35fc48c04daed73cde633 | |
parent | 8db78c7d4db84ff9e191457bbf4b1254da321c7e (diff) | |
download | git-repo-8501d4602a4c85f1e22c7a51ad191af8166efecd.tar.gz |
status, diff: display correct path for multi-manifest
Display the project path relative to the outermost manifest by default,
and relative to the sub manifest only when --this-manifest-only is
specified.
For project-related diagnostic messages, use the outermost manifest for
messages.
Change-Id: I4537d7dd412a2c182e77d6720e95c1b0ef70eb0e
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/340754
Reviewed-by: Mike Frysinger <vapier@google.com>
Tested-by: LaMont Jones <lamontjones@google.com>
-rw-r--r-- | project.py | 43 | ||||
-rw-r--r-- | subcmds/diff.py | 9 | ||||
-rw-r--r-- | subcmds/status.py | 10 |
3 files changed, 37 insertions, 25 deletions
@@ -794,19 +794,22 @@ class Project(object): | |||
794 | """ | 794 | """ |
795 | return bool(self.UncommitedFiles(get_all=False)) | 795 | return bool(self.UncommitedFiles(get_all=False)) |
796 | 796 | ||
797 | def PrintWorkTreeStatus(self, output_redir=None, quiet=False): | 797 | def PrintWorkTreeStatus(self, output_redir=None, quiet=False, local=False): |
798 | """Prints the status of the repository to stdout. | 798 | """Prints the status of the repository to stdout. |
799 | 799 | ||
800 | Args: | 800 | Args: |
801 | output_redir: If specified, redirect the output to this object. | 801 | output_redir: If specified, redirect the output to this object. |
802 | quiet: If True then only print the project name. Do not print | 802 | quiet: If True then only print the project name. Do not print |
803 | the modified files, branch name, etc. | 803 | the modified files, branch name, etc. |
804 | local: a boolean, if True, the path is relative to the local | ||
805 | (sub)manifest. If false, the path is relative to the | ||
806 | outermost manifest. | ||
804 | """ | 807 | """ |
805 | if not platform_utils.isdir(self.worktree): | 808 | if not platform_utils.isdir(self.worktree): |
806 | if output_redir is None: | 809 | if output_redir is None: |
807 | output_redir = sys.stdout | 810 | output_redir = sys.stdout |
808 | print(file=output_redir) | 811 | print(file=output_redir) |
809 | print('project %s/' % self.relpath, file=output_redir) | 812 | print('project %s/' % self.RelPath(local), file=output_redir) |
810 | print(' missing (run "repo sync")', file=output_redir) | 813 | print(' missing (run "repo sync")', file=output_redir) |
811 | return | 814 | return |
812 | 815 | ||
@@ -824,7 +827,7 @@ class Project(object): | |||
824 | out = StatusColoring(self.config) | 827 | out = StatusColoring(self.config) |
825 | if output_redir is not None: | 828 | if output_redir is not None: |
826 | out.redirect(output_redir) | 829 | out.redirect(output_redir) |
827 | out.project('project %-40s', self.relpath + '/ ') | 830 | out.project('project %-40s', self.RelPath(local) + '/ ') |
828 | 831 | ||
829 | if quiet: | 832 | if quiet: |
830 | out.nl() | 833 | out.nl() |
@@ -885,7 +888,8 @@ class Project(object): | |||
885 | 888 | ||
886 | return 'DIRTY' | 889 | return 'DIRTY' |
887 | 890 | ||
888 | def PrintWorkTreeDiff(self, absolute_paths=False, output_redir=None): | 891 | def PrintWorkTreeDiff(self, absolute_paths=False, output_redir=None, |
892 | local=False): | ||
889 | """Prints the status of the repository to stdout. | 893 | """Prints the status of the repository to stdout. |
890 | """ | 894 | """ |
891 | out = DiffColoring(self.config) | 895 | out = DiffColoring(self.config) |
@@ -896,8 +900,8 @@ class Project(object): | |||
896 | cmd.append('--color') | 900 | cmd.append('--color') |
897 | cmd.append(HEAD) | 901 | cmd.append(HEAD) |
898 | if absolute_paths: | 902 | if absolute_paths: |
899 | cmd.append('--src-prefix=a/%s/' % self.relpath) | 903 | cmd.append('--src-prefix=a/%s/' % self.RelPath(local)) |
900 | cmd.append('--dst-prefix=b/%s/' % self.relpath) | 904 | cmd.append('--dst-prefix=b/%s/' % self.RelPath(local)) |
901 | cmd.append('--') | 905 | cmd.append('--') |
902 | try: | 906 | try: |
903 | p = GitCommand(self, | 907 | p = GitCommand(self, |
@@ -907,14 +911,14 @@ class Project(object): | |||
907 | p.Wait() | 911 | p.Wait() |
908 | except GitError as e: | 912 | except GitError as e: |
909 | out.nl() | 913 | out.nl() |
910 | out.project('project %s/' % self.relpath) | 914 | out.project('project %s/' % self.RelPath(local)) |
911 | out.nl() | 915 | out.nl() |
912 | out.fail('%s', str(e)) | 916 | out.fail('%s', str(e)) |
913 | out.nl() | 917 | out.nl() |
914 | return False | 918 | return False |
915 | if p.stdout: | 919 | if p.stdout: |
916 | out.nl() | 920 | out.nl() |
917 | out.project('project %s/' % self.relpath) | 921 | out.project('project %s/' % self.RelPath(local)) |
918 | out.nl() | 922 | out.nl() |
919 | out.write('%s', p.stdout) | 923 | out.write('%s', p.stdout) |
920 | return p.Wait() == 0 | 924 | return p.Wait() == 0 |
@@ -1553,14 +1557,14 @@ class Project(object): | |||
1553 | if self.IsDirty(): | 1557 | if self.IsDirty(): |
1554 | if force: | 1558 | if force: |
1555 | print('warning: %s: Removing dirty project: uncommitted changes lost.' % | 1559 | print('warning: %s: Removing dirty project: uncommitted changes lost.' % |
1556 | (self.relpath,), file=sys.stderr) | 1560 | (self.RelPath(local=False),), file=sys.stderr) |
1557 | else: | 1561 | else: |
1558 | print('error: %s: Cannot remove project: uncommitted changes are ' | 1562 | print('error: %s: Cannot remove project: uncommitted changes are ' |
1559 | 'present.\n' % (self.relpath,), file=sys.stderr) | 1563 | 'present.\n' % (self.RelPath(local=False),), file=sys.stderr) |
1560 | return False | 1564 | return False |
1561 | 1565 | ||
1562 | if not quiet: | 1566 | if not quiet: |
1563 | print('%s: Deleting obsolete checkout.' % (self.relpath,)) | 1567 | print('%s: Deleting obsolete checkout.' % (self.RelPath(local=False),)) |
1564 | 1568 | ||
1565 | # Unlock and delink from the main worktree. We don't use git's worktree | 1569 | # Unlock and delink from the main worktree. We don't use git's worktree |
1566 | # remove because it will recursively delete projects -- we handle that | 1570 | # remove because it will recursively delete projects -- we handle that |
@@ -1599,7 +1603,8 @@ class Project(object): | |||
1599 | if e.errno != errno.ENOENT: | 1603 | if e.errno != errno.ENOENT: |
1600 | print('error: %s: %s' % (self.gitdir, e), file=sys.stderr) | 1604 | print('error: %s: %s' % (self.gitdir, e), file=sys.stderr) |
1601 | print('error: %s: Failed to delete obsolete checkout; remove manually, ' | 1605 | print('error: %s: Failed to delete obsolete checkout; remove manually, ' |
1602 | 'then run `repo sync -l`.' % (self.relpath,), file=sys.stderr) | 1606 | 'then run `repo sync -l`.' % (self.RelPath(local=False),), |
1607 | file=sys.stderr) | ||
1603 | return False | 1608 | return False |
1604 | 1609 | ||
1605 | # Delete everything under the worktree, except for directories that contain | 1610 | # Delete everything under the worktree, except for directories that contain |
@@ -1635,7 +1640,7 @@ class Project(object): | |||
1635 | print('error: %s: Failed to remove: %s' % (d, e), file=sys.stderr) | 1640 | print('error: %s: Failed to remove: %s' % (d, e), file=sys.stderr) |
1636 | failed = True | 1641 | failed = True |
1637 | if failed: | 1642 | if failed: |
1638 | print('error: %s: Failed to delete obsolete checkout.' % (self.relpath,), | 1643 | print('error: %s: Failed to delete obsolete checkout.' % (self.RelPath(local=False),), |
1639 | file=sys.stderr) | 1644 | file=sys.stderr) |
1640 | print(' Remove manually, then run `repo sync -l`.', file=sys.stderr) | 1645 | print(' Remove manually, then run `repo sync -l`.', file=sys.stderr) |
1641 | return False | 1646 | return False |
@@ -2050,7 +2055,7 @@ class Project(object): | |||
2050 | def _FetchArchive(self, tarpath, cwd=None): | 2055 | def _FetchArchive(self, tarpath, cwd=None): |
2051 | cmd = ['archive', '-v', '-o', tarpath] | 2056 | cmd = ['archive', '-v', '-o', tarpath] |
2052 | cmd.append('--remote=%s' % self.remote.url) | 2057 | cmd.append('--remote=%s' % self.remote.url) |
2053 | cmd.append('--prefix=%s/' % self.relpath) | 2058 | cmd.append('--prefix=%s/' % self.RelPath(local=False)) |
2054 | cmd.append(self.revisionExpr) | 2059 | cmd.append(self.revisionExpr) |
2055 | 2060 | ||
2056 | command = GitCommand(self, cmd, cwd=cwd, | 2061 | command = GitCommand(self, cmd, cwd=cwd, |
@@ -2634,7 +2639,7 @@ class Project(object): | |||
2634 | if not filecmp.cmp(stock_hook, dst, shallow=False): | 2639 | if not filecmp.cmp(stock_hook, dst, shallow=False): |
2635 | if not quiet: | 2640 | if not quiet: |
2636 | _warn("%s: Not replacing locally modified %s hook", | 2641 | _warn("%s: Not replacing locally modified %s hook", |
2637 | self.relpath, name) | 2642 | self.RelPath(local=False), name) |
2638 | continue | 2643 | continue |
2639 | try: | 2644 | try: |
2640 | platform_utils.symlink( | 2645 | platform_utils.symlink( |
@@ -2729,7 +2734,7 @@ class Project(object): | |||
2729 | 'work tree. If you\'re comfortable with the ' | 2734 | 'work tree. If you\'re comfortable with the ' |
2730 | 'possibility of losing the work tree\'s git metadata,' | 2735 | 'possibility of losing the work tree\'s git metadata,' |
2731 | ' use `repo sync --force-sync {0}` to ' | 2736 | ' use `repo sync --force-sync {0}` to ' |
2732 | 'proceed.'.format(self.relpath)) | 2737 | 'proceed.'.format(self.RelPath(local=False))) |
2733 | 2738 | ||
2734 | def _ReferenceGitDir(self, gitdir, dotgit, copy_all): | 2739 | def _ReferenceGitDir(self, gitdir, dotgit, copy_all): |
2735 | """Update |dotgit| to reference |gitdir|, using symlinks where possible. | 2740 | """Update |dotgit| to reference |gitdir|, using symlinks where possible. |
@@ -3209,7 +3214,7 @@ class _InfoMessage(object): | |||
3209 | self.text = text | 3214 | self.text = text |
3210 | 3215 | ||
3211 | def Print(self, syncbuf): | 3216 | def Print(self, syncbuf): |
3212 | syncbuf.out.info('%s/: %s', self.project.relpath, self.text) | 3217 | syncbuf.out.info('%s/: %s', self.project.RelPath(local=False), self.text) |
3213 | syncbuf.out.nl() | 3218 | syncbuf.out.nl() |
3214 | 3219 | ||
3215 | 3220 | ||
@@ -3221,7 +3226,7 @@ class _Failure(object): | |||
3221 | 3226 | ||
3222 | def Print(self, syncbuf): | 3227 | def Print(self, syncbuf): |
3223 | syncbuf.out.fail('error: %s/: %s', | 3228 | syncbuf.out.fail('error: %s/: %s', |
3224 | self.project.relpath, | 3229 | self.project.RelPath(local=False), |
3225 | str(self.why)) | 3230 | str(self.why)) |
3226 | syncbuf.out.nl() | 3231 | syncbuf.out.nl() |
3227 | 3232 | ||
@@ -3234,7 +3239,7 @@ class _Later(object): | |||
3234 | 3239 | ||
3235 | def Run(self, syncbuf): | 3240 | def Run(self, syncbuf): |
3236 | out = syncbuf.out | 3241 | out = syncbuf.out |
3237 | out.project('project %s/', self.project.relpath) | 3242 | out.project('project %s/', self.project.RelPath(local=False)) |
3238 | out.nl() | 3243 | out.nl() |
3239 | try: | 3244 | try: |
3240 | self.action() | 3245 | self.action() |
diff --git a/subcmds/diff.py b/subcmds/diff.py index a1f4ba88..a606ee9a 100644 --- a/subcmds/diff.py +++ b/subcmds/diff.py | |||
@@ -35,18 +35,21 @@ to the Unix 'patch' command. | |||
35 | dest='absolute', action='store_true', | 35 | dest='absolute', action='store_true', |
36 | help='paths are relative to the repository root') | 36 | help='paths are relative to the repository root') |
37 | 37 | ||
38 | def _ExecuteOne(self, absolute, project): | 38 | def _ExecuteOne(self, absolute, local, project): |
39 | """Obtains the diff for a specific project. | 39 | """Obtains the diff for a specific project. |
40 | 40 | ||
41 | Args: | 41 | Args: |
42 | absolute: Paths are relative to the root. | 42 | absolute: Paths are relative to the root. |
43 | local: a boolean, if True, the path is relative to the local | ||
44 | (sub)manifest. If false, the path is relative to the | ||
45 | outermost manifest. | ||
43 | project: Project to get status of. | 46 | project: Project to get status of. |
44 | 47 | ||
45 | Returns: | 48 | Returns: |
46 | The status of the project. | 49 | The status of the project. |
47 | """ | 50 | """ |
48 | buf = io.StringIO() | 51 | buf = io.StringIO() |
49 | ret = project.PrintWorkTreeDiff(absolute, output_redir=buf) | 52 | ret = project.PrintWorkTreeDiff(absolute, output_redir=buf, local=local) |
50 | return (ret, buf.getvalue()) | 53 | return (ret, buf.getvalue()) |
51 | 54 | ||
52 | def Execute(self, opt, args): | 55 | def Execute(self, opt, args): |
@@ -63,7 +66,7 @@ to the Unix 'patch' command. | |||
63 | 66 | ||
64 | return self.ExecuteInParallel( | 67 | return self.ExecuteInParallel( |
65 | opt.jobs, | 68 | opt.jobs, |
66 | functools.partial(self._ExecuteOne, opt.absolute), | 69 | functools.partial(self._ExecuteOne, opt.absolute, opt.this_manifest_only), |
67 | all_projects, | 70 | all_projects, |
68 | callback=_ProcessResults, | 71 | callback=_ProcessResults, |
69 | ordered=True) | 72 | ordered=True) |
diff --git a/subcmds/status.py b/subcmds/status.py index 0aa4200f..572c72f7 100644 --- a/subcmds/status.py +++ b/subcmds/status.py | |||
@@ -83,7 +83,7 @@ the following meanings: | |||
83 | dest='orphans', action='store_true', | 83 | dest='orphans', action='store_true', |
84 | help="include objects in working directory outside of repo projects") | 84 | help="include objects in working directory outside of repo projects") |
85 | 85 | ||
86 | def _StatusHelper(self, quiet, project): | 86 | def _StatusHelper(self, quiet, local, project): |
87 | """Obtains the status for a specific project. | 87 | """Obtains the status for a specific project. |
88 | 88 | ||
89 | Obtains the status for a project, redirecting the output to | 89 | Obtains the status for a project, redirecting the output to |
@@ -91,13 +91,17 @@ the following meanings: | |||
91 | 91 | ||
92 | Args: | 92 | Args: |
93 | quiet: Where to output the status. | 93 | quiet: Where to output the status. |
94 | local: a boolean, if True, the path is relative to the local | ||
95 | (sub)manifest. If false, the path is relative to the | ||
96 | outermost manifest. | ||
94 | project: Project to get status of. | 97 | project: Project to get status of. |
95 | 98 | ||
96 | Returns: | 99 | Returns: |
97 | The status of the project. | 100 | The status of the project. |
98 | """ | 101 | """ |
99 | buf = io.StringIO() | 102 | buf = io.StringIO() |
100 | ret = project.PrintWorkTreeStatus(quiet=quiet, output_redir=buf) | 103 | ret = project.PrintWorkTreeStatus(quiet=quiet, output_redir=buf, |
104 | local=local) | ||
101 | return (ret, buf.getvalue()) | 105 | return (ret, buf.getvalue()) |
102 | 106 | ||
103 | def _FindOrphans(self, dirs, proj_dirs, proj_dirs_parents, outstring): | 107 | def _FindOrphans(self, dirs, proj_dirs, proj_dirs_parents, outstring): |
@@ -130,7 +134,7 @@ the following meanings: | |||
130 | 134 | ||
131 | counter = self.ExecuteInParallel( | 135 | counter = self.ExecuteInParallel( |
132 | opt.jobs, | 136 | opt.jobs, |
133 | functools.partial(self._StatusHelper, opt.quiet), | 137 | functools.partial(self._StatusHelper, opt.quiet, opt.this_manifest_only), |
134 | all_projects, | 138 | all_projects, |
135 | callback=_ProcessResults, | 139 | callback=_ProcessResults, |
136 | ordered=True) | 140 | ordered=True) |