mirror of
https://gerrit.googlesource.com/git-repo
synced 2024-12-21 07:16:21 +00:00
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>
This commit is contained in:
parent
8db78c7d4d
commit
8501d4602a
43
project.py
43
project.py
@ -794,19 +794,22 @@ class Project(object):
|
|||||||
"""
|
"""
|
||||||
return bool(self.UncommitedFiles(get_all=False))
|
return bool(self.UncommitedFiles(get_all=False))
|
||||||
|
|
||||||
def PrintWorkTreeStatus(self, output_redir=None, quiet=False):
|
def PrintWorkTreeStatus(self, output_redir=None, quiet=False, local=False):
|
||||||
"""Prints the status of the repository to stdout.
|
"""Prints the status of the repository to stdout.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
output_redir: If specified, redirect the output to this object.
|
output_redir: If specified, redirect the output to this object.
|
||||||
quiet: If True then only print the project name. Do not print
|
quiet: If True then only print the project name. Do not print
|
||||||
the modified files, branch name, etc.
|
the modified files, branch name, etc.
|
||||||
|
local: a boolean, if True, the path is relative to the local
|
||||||
|
(sub)manifest. If false, the path is relative to the
|
||||||
|
outermost manifest.
|
||||||
"""
|
"""
|
||||||
if not platform_utils.isdir(self.worktree):
|
if not platform_utils.isdir(self.worktree):
|
||||||
if output_redir is None:
|
if output_redir is None:
|
||||||
output_redir = sys.stdout
|
output_redir = sys.stdout
|
||||||
print(file=output_redir)
|
print(file=output_redir)
|
||||||
print('project %s/' % self.relpath, file=output_redir)
|
print('project %s/' % self.RelPath(local), file=output_redir)
|
||||||
print(' missing (run "repo sync")', file=output_redir)
|
print(' missing (run "repo sync")', file=output_redir)
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -824,7 +827,7 @@ class Project(object):
|
|||||||
out = StatusColoring(self.config)
|
out = StatusColoring(self.config)
|
||||||
if output_redir is not None:
|
if output_redir is not None:
|
||||||
out.redirect(output_redir)
|
out.redirect(output_redir)
|
||||||
out.project('project %-40s', self.relpath + '/ ')
|
out.project('project %-40s', self.RelPath(local) + '/ ')
|
||||||
|
|
||||||
if quiet:
|
if quiet:
|
||||||
out.nl()
|
out.nl()
|
||||||
@ -885,7 +888,8 @@ class Project(object):
|
|||||||
|
|
||||||
return 'DIRTY'
|
return 'DIRTY'
|
||||||
|
|
||||||
def PrintWorkTreeDiff(self, absolute_paths=False, output_redir=None):
|
def PrintWorkTreeDiff(self, absolute_paths=False, output_redir=None,
|
||||||
|
local=False):
|
||||||
"""Prints the status of the repository to stdout.
|
"""Prints the status of the repository to stdout.
|
||||||
"""
|
"""
|
||||||
out = DiffColoring(self.config)
|
out = DiffColoring(self.config)
|
||||||
@ -896,8 +900,8 @@ class Project(object):
|
|||||||
cmd.append('--color')
|
cmd.append('--color')
|
||||||
cmd.append(HEAD)
|
cmd.append(HEAD)
|
||||||
if absolute_paths:
|
if absolute_paths:
|
||||||
cmd.append('--src-prefix=a/%s/' % self.relpath)
|
cmd.append('--src-prefix=a/%s/' % self.RelPath(local))
|
||||||
cmd.append('--dst-prefix=b/%s/' % self.relpath)
|
cmd.append('--dst-prefix=b/%s/' % self.RelPath(local))
|
||||||
cmd.append('--')
|
cmd.append('--')
|
||||||
try:
|
try:
|
||||||
p = GitCommand(self,
|
p = GitCommand(self,
|
||||||
@ -907,14 +911,14 @@ class Project(object):
|
|||||||
p.Wait()
|
p.Wait()
|
||||||
except GitError as e:
|
except GitError as e:
|
||||||
out.nl()
|
out.nl()
|
||||||
out.project('project %s/' % self.relpath)
|
out.project('project %s/' % self.RelPath(local))
|
||||||
out.nl()
|
out.nl()
|
||||||
out.fail('%s', str(e))
|
out.fail('%s', str(e))
|
||||||
out.nl()
|
out.nl()
|
||||||
return False
|
return False
|
||||||
if p.stdout:
|
if p.stdout:
|
||||||
out.nl()
|
out.nl()
|
||||||
out.project('project %s/' % self.relpath)
|
out.project('project %s/' % self.RelPath(local))
|
||||||
out.nl()
|
out.nl()
|
||||||
out.write('%s', p.stdout)
|
out.write('%s', p.stdout)
|
||||||
return p.Wait() == 0
|
return p.Wait() == 0
|
||||||
@ -1553,14 +1557,14 @@ class Project(object):
|
|||||||
if self.IsDirty():
|
if self.IsDirty():
|
||||||
if force:
|
if force:
|
||||||
print('warning: %s: Removing dirty project: uncommitted changes lost.' %
|
print('warning: %s: Removing dirty project: uncommitted changes lost.' %
|
||||||
(self.relpath,), file=sys.stderr)
|
(self.RelPath(local=False),), file=sys.stderr)
|
||||||
else:
|
else:
|
||||||
print('error: %s: Cannot remove project: uncommitted changes are '
|
print('error: %s: Cannot remove project: uncommitted changes are '
|
||||||
'present.\n' % (self.relpath,), file=sys.stderr)
|
'present.\n' % (self.RelPath(local=False),), file=sys.stderr)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if not quiet:
|
if not quiet:
|
||||||
print('%s: Deleting obsolete checkout.' % (self.relpath,))
|
print('%s: Deleting obsolete checkout.' % (self.RelPath(local=False),))
|
||||||
|
|
||||||
# Unlock and delink from the main worktree. We don't use git's worktree
|
# Unlock and delink from the main worktree. We don't use git's worktree
|
||||||
# remove because it will recursively delete projects -- we handle that
|
# remove because it will recursively delete projects -- we handle that
|
||||||
@ -1599,7 +1603,8 @@ class Project(object):
|
|||||||
if e.errno != errno.ENOENT:
|
if e.errno != errno.ENOENT:
|
||||||
print('error: %s: %s' % (self.gitdir, e), file=sys.stderr)
|
print('error: %s: %s' % (self.gitdir, e), file=sys.stderr)
|
||||||
print('error: %s: Failed to delete obsolete checkout; remove manually, '
|
print('error: %s: Failed to delete obsolete checkout; remove manually, '
|
||||||
'then run `repo sync -l`.' % (self.relpath,), file=sys.stderr)
|
'then run `repo sync -l`.' % (self.RelPath(local=False),),
|
||||||
|
file=sys.stderr)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# Delete everything under the worktree, except for directories that contain
|
# Delete everything under the worktree, except for directories that contain
|
||||||
@ -1635,7 +1640,7 @@ class Project(object):
|
|||||||
print('error: %s: Failed to remove: %s' % (d, e), file=sys.stderr)
|
print('error: %s: Failed to remove: %s' % (d, e), file=sys.stderr)
|
||||||
failed = True
|
failed = True
|
||||||
if failed:
|
if failed:
|
||||||
print('error: %s: Failed to delete obsolete checkout.' % (self.relpath,),
|
print('error: %s: Failed to delete obsolete checkout.' % (self.RelPath(local=False),),
|
||||||
file=sys.stderr)
|
file=sys.stderr)
|
||||||
print(' Remove manually, then run `repo sync -l`.', file=sys.stderr)
|
print(' Remove manually, then run `repo sync -l`.', file=sys.stderr)
|
||||||
return False
|
return False
|
||||||
@ -2050,7 +2055,7 @@ class Project(object):
|
|||||||
def _FetchArchive(self, tarpath, cwd=None):
|
def _FetchArchive(self, tarpath, cwd=None):
|
||||||
cmd = ['archive', '-v', '-o', tarpath]
|
cmd = ['archive', '-v', '-o', tarpath]
|
||||||
cmd.append('--remote=%s' % self.remote.url)
|
cmd.append('--remote=%s' % self.remote.url)
|
||||||
cmd.append('--prefix=%s/' % self.relpath)
|
cmd.append('--prefix=%s/' % self.RelPath(local=False))
|
||||||
cmd.append(self.revisionExpr)
|
cmd.append(self.revisionExpr)
|
||||||
|
|
||||||
command = GitCommand(self, cmd, cwd=cwd,
|
command = GitCommand(self, cmd, cwd=cwd,
|
||||||
@ -2634,7 +2639,7 @@ class Project(object):
|
|||||||
if not filecmp.cmp(stock_hook, dst, shallow=False):
|
if not filecmp.cmp(stock_hook, dst, shallow=False):
|
||||||
if not quiet:
|
if not quiet:
|
||||||
_warn("%s: Not replacing locally modified %s hook",
|
_warn("%s: Not replacing locally modified %s hook",
|
||||||
self.relpath, name)
|
self.RelPath(local=False), name)
|
||||||
continue
|
continue
|
||||||
try:
|
try:
|
||||||
platform_utils.symlink(
|
platform_utils.symlink(
|
||||||
@ -2729,7 +2734,7 @@ class Project(object):
|
|||||||
'work tree. If you\'re comfortable with the '
|
'work tree. If you\'re comfortable with the '
|
||||||
'possibility of losing the work tree\'s git metadata,'
|
'possibility of losing the work tree\'s git metadata,'
|
||||||
' use `repo sync --force-sync {0}` to '
|
' use `repo sync --force-sync {0}` to '
|
||||||
'proceed.'.format(self.relpath))
|
'proceed.'.format(self.RelPath(local=False)))
|
||||||
|
|
||||||
def _ReferenceGitDir(self, gitdir, dotgit, copy_all):
|
def _ReferenceGitDir(self, gitdir, dotgit, copy_all):
|
||||||
"""Update |dotgit| to reference |gitdir|, using symlinks where possible.
|
"""Update |dotgit| to reference |gitdir|, using symlinks where possible.
|
||||||
@ -3209,7 +3214,7 @@ class _InfoMessage(object):
|
|||||||
self.text = text
|
self.text = text
|
||||||
|
|
||||||
def Print(self, syncbuf):
|
def Print(self, syncbuf):
|
||||||
syncbuf.out.info('%s/: %s', self.project.relpath, self.text)
|
syncbuf.out.info('%s/: %s', self.project.RelPath(local=False), self.text)
|
||||||
syncbuf.out.nl()
|
syncbuf.out.nl()
|
||||||
|
|
||||||
|
|
||||||
@ -3221,7 +3226,7 @@ class _Failure(object):
|
|||||||
|
|
||||||
def Print(self, syncbuf):
|
def Print(self, syncbuf):
|
||||||
syncbuf.out.fail('error: %s/: %s',
|
syncbuf.out.fail('error: %s/: %s',
|
||||||
self.project.relpath,
|
self.project.RelPath(local=False),
|
||||||
str(self.why))
|
str(self.why))
|
||||||
syncbuf.out.nl()
|
syncbuf.out.nl()
|
||||||
|
|
||||||
@ -3234,7 +3239,7 @@ class _Later(object):
|
|||||||
|
|
||||||
def Run(self, syncbuf):
|
def Run(self, syncbuf):
|
||||||
out = syncbuf.out
|
out = syncbuf.out
|
||||||
out.project('project %s/', self.project.relpath)
|
out.project('project %s/', self.project.RelPath(local=False))
|
||||||
out.nl()
|
out.nl()
|
||||||
try:
|
try:
|
||||||
self.action()
|
self.action()
|
||||||
|
@ -35,18 +35,21 @@ to the Unix 'patch' command.
|
|||||||
dest='absolute', action='store_true',
|
dest='absolute', action='store_true',
|
||||||
help='paths are relative to the repository root')
|
help='paths are relative to the repository root')
|
||||||
|
|
||||||
def _ExecuteOne(self, absolute, project):
|
def _ExecuteOne(self, absolute, local, project):
|
||||||
"""Obtains the diff for a specific project.
|
"""Obtains the diff for a specific project.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
absolute: Paths are relative to the root.
|
absolute: Paths are relative to the root.
|
||||||
|
local: a boolean, if True, the path is relative to the local
|
||||||
|
(sub)manifest. If false, the path is relative to the
|
||||||
|
outermost manifest.
|
||||||
project: Project to get status of.
|
project: Project to get status of.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
The status of the project.
|
The status of the project.
|
||||||
"""
|
"""
|
||||||
buf = io.StringIO()
|
buf = io.StringIO()
|
||||||
ret = project.PrintWorkTreeDiff(absolute, output_redir=buf)
|
ret = project.PrintWorkTreeDiff(absolute, output_redir=buf, local=local)
|
||||||
return (ret, buf.getvalue())
|
return (ret, buf.getvalue())
|
||||||
|
|
||||||
def Execute(self, opt, args):
|
def Execute(self, opt, args):
|
||||||
@ -63,7 +66,7 @@ to the Unix 'patch' command.
|
|||||||
|
|
||||||
return self.ExecuteInParallel(
|
return self.ExecuteInParallel(
|
||||||
opt.jobs,
|
opt.jobs,
|
||||||
functools.partial(self._ExecuteOne, opt.absolute),
|
functools.partial(self._ExecuteOne, opt.absolute, opt.this_manifest_only),
|
||||||
all_projects,
|
all_projects,
|
||||||
callback=_ProcessResults,
|
callback=_ProcessResults,
|
||||||
ordered=True)
|
ordered=True)
|
||||||
|
@ -83,7 +83,7 @@ the following meanings:
|
|||||||
dest='orphans', action='store_true',
|
dest='orphans', action='store_true',
|
||||||
help="include objects in working directory outside of repo projects")
|
help="include objects in working directory outside of repo projects")
|
||||||
|
|
||||||
def _StatusHelper(self, quiet, project):
|
def _StatusHelper(self, quiet, local, project):
|
||||||
"""Obtains the status for a specific project.
|
"""Obtains the status for a specific project.
|
||||||
|
|
||||||
Obtains the status for a project, redirecting the output to
|
Obtains the status for a project, redirecting the output to
|
||||||
@ -91,13 +91,17 @@ the following meanings:
|
|||||||
|
|
||||||
Args:
|
Args:
|
||||||
quiet: Where to output the status.
|
quiet: Where to output the status.
|
||||||
|
local: a boolean, if True, the path is relative to the local
|
||||||
|
(sub)manifest. If false, the path is relative to the
|
||||||
|
outermost manifest.
|
||||||
project: Project to get status of.
|
project: Project to get status of.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
The status of the project.
|
The status of the project.
|
||||||
"""
|
"""
|
||||||
buf = io.StringIO()
|
buf = io.StringIO()
|
||||||
ret = project.PrintWorkTreeStatus(quiet=quiet, output_redir=buf)
|
ret = project.PrintWorkTreeStatus(quiet=quiet, output_redir=buf,
|
||||||
|
local=local)
|
||||||
return (ret, buf.getvalue())
|
return (ret, buf.getvalue())
|
||||||
|
|
||||||
def _FindOrphans(self, dirs, proj_dirs, proj_dirs_parents, outstring):
|
def _FindOrphans(self, dirs, proj_dirs, proj_dirs_parents, outstring):
|
||||||
@ -130,7 +134,7 @@ the following meanings:
|
|||||||
|
|
||||||
counter = self.ExecuteInParallel(
|
counter = self.ExecuteInParallel(
|
||||||
opt.jobs,
|
opt.jobs,
|
||||||
functools.partial(self._StatusHelper, opt.quiet),
|
functools.partial(self._StatusHelper, opt.quiet, opt.this_manifest_only),
|
||||||
all_projects,
|
all_projects,
|
||||||
callback=_ProcessResults,
|
callback=_ProcessResults,
|
||||||
ordered=True)
|
ordered=True)
|
||||||
|
Loading…
Reference in New Issue
Block a user