mirror of
https://gerrit.googlesource.com/git-repo
synced 2024-12-21 07:16:21 +00:00
superproject: Log branch and remote url with every log message.
Saved superproject's remote URL in _remote_url data and used it in the _Fecth function. Tested: $ ./run_tests $ flake8 git_superproject.py $ repo_dev init --use-superproject -u https://android.googlesource.com/platform/manifest $ repo_dev sync Verified the all log messages have the following format. repo superproject branch: <branch> url: <url> warning: <message> Bug: [google internal] b/200072098 Change-Id: Iac6af7c99225479fd50bc6909396b22e0ce5f76b Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/318177 Reviewed-by: Xin Li <delphij@google.com> Tested-by: Raman Tenneti <rtenneti@google.com>
This commit is contained in:
parent
6448a4f2af
commit
d8e8ae8990
@ -98,8 +98,11 @@ class Superproject(object):
|
|||||||
_SUPERPROJECT_MANIFEST_NAME)
|
_SUPERPROJECT_MANIFEST_NAME)
|
||||||
git_name = ''
|
git_name = ''
|
||||||
if self._manifest.superproject:
|
if self._manifest.superproject:
|
||||||
remote_name = self._manifest.superproject['remote'].name
|
remote = self._manifest.superproject['remote']
|
||||||
git_name = hashlib.md5(remote_name.encode('utf8')).hexdigest() + '-'
|
git_name = hashlib.md5(remote.name.encode('utf8')).hexdigest() + '-'
|
||||||
|
self._remote_url = remote.url
|
||||||
|
else:
|
||||||
|
self._remote_url = None
|
||||||
self._work_git_name = git_name + _SUPERPROJECT_GIT_NAME
|
self._work_git_name = git_name + _SUPERPROJECT_GIT_NAME
|
||||||
self._work_git = os.path.join(self._superproject_path, self._work_git_name)
|
self._work_git = os.path.join(self._superproject_path, self._work_git_name)
|
||||||
|
|
||||||
@ -130,13 +133,17 @@ class Superproject(object):
|
|||||||
print(message, file=sys.stderr)
|
print(message, file=sys.stderr)
|
||||||
self._git_event_log.ErrorEvent(message, f'{message}')
|
self._git_event_log.ErrorEvent(message, f'{message}')
|
||||||
|
|
||||||
|
def _LogMessagePrefix(self):
|
||||||
|
"""Returns the prefix string to be logged in each log message"""
|
||||||
|
return f'repo superproject branch: {self._branch} url: {self._remote_url}'
|
||||||
|
|
||||||
def _LogError(self, message):
|
def _LogError(self, message):
|
||||||
"""Logs error message to stderr and _git_event_log."""
|
"""Logs error message to stderr and _git_event_log."""
|
||||||
self._LogMessage(f'repo superproject error: {message}')
|
self._LogMessage(f'{self._LogMessagePrefix()} error: {message}')
|
||||||
|
|
||||||
def _LogWarning(self, message):
|
def _LogWarning(self, message):
|
||||||
"""Logs warning message to stderr and _git_event_log."""
|
"""Logs warning message to stderr and _git_event_log."""
|
||||||
self._LogMessage(f'repo superproject warning: {message}')
|
self._LogMessage(f'{self._LogMessagePrefix()} warning: {message}')
|
||||||
|
|
||||||
def _Init(self):
|
def _Init(self):
|
||||||
"""Sets up a local Git repository to get a copy of a superproject.
|
"""Sets up a local Git repository to get a copy of a superproject.
|
||||||
@ -162,11 +169,8 @@ class Superproject(object):
|
|||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def _Fetch(self, url):
|
def _Fetch(self):
|
||||||
"""Fetches a local copy of a superproject for the manifest based on url.
|
"""Fetches a local copy of a superproject for the manifest based on |_remote_url|.
|
||||||
|
|
||||||
Args:
|
|
||||||
url: superproject's url.
|
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
True if fetch is successful, or False.
|
True if fetch is successful, or False.
|
||||||
@ -177,7 +181,8 @@ class Superproject(object):
|
|||||||
if not git_require((2, 28, 0)):
|
if not git_require((2, 28, 0)):
|
||||||
self._LogWarning('superproject requires a git version 2.28 or later')
|
self._LogWarning('superproject requires a git version 2.28 or later')
|
||||||
return False
|
return False
|
||||||
cmd = ['fetch', url, '--depth', '1', '--force', '--no-tags', '--filter', 'blob:none']
|
cmd = ['fetch', self._remote_url, '--depth', '1', '--force', '--no-tags',
|
||||||
|
'--filter', 'blob:none']
|
||||||
if self._branch:
|
if self._branch:
|
||||||
cmd += [self._branch + ':' + self._branch]
|
cmd += [self._branch + ':' + self._branch]
|
||||||
p = GitCommand(None,
|
p = GitCommand(None,
|
||||||
@ -234,15 +239,14 @@ class Superproject(object):
|
|||||||
print('NOTICE: --use-superproject is in beta; report any issues to the '
|
print('NOTICE: --use-superproject is in beta; report any issues to the '
|
||||||
'address described in `repo version`', file=sys.stderr)
|
'address described in `repo version`', file=sys.stderr)
|
||||||
should_exit = True
|
should_exit = True
|
||||||
url = self._manifest.superproject['remote'].url
|
if not self._remote_url:
|
||||||
if not url:
|
|
||||||
self._LogWarning(f'superproject URL is not defined in manifest: '
|
self._LogWarning(f'superproject URL is not defined in manifest: '
|
||||||
f'{self._manifest.manifestFile}')
|
f'{self._manifest.manifestFile}')
|
||||||
return SyncResult(False, should_exit)
|
return SyncResult(False, should_exit)
|
||||||
|
|
||||||
if not self._Init():
|
if not self._Init():
|
||||||
return SyncResult(False, should_exit)
|
return SyncResult(False, should_exit)
|
||||||
if not self._Fetch(url):
|
if not self._Fetch():
|
||||||
return SyncResult(False, should_exit)
|
return SyncResult(False, should_exit)
|
||||||
if not self._quiet:
|
if not self._quiet:
|
||||||
print('%s: Initial setup for superproject completed.' % self._work_git)
|
print('%s: Initial setup for superproject completed.' % self._work_git)
|
||||||
@ -260,7 +264,7 @@ class Superproject(object):
|
|||||||
|
|
||||||
data = self._LsTree()
|
data = self._LsTree()
|
||||||
if not data:
|
if not data:
|
||||||
self._LogWarning(f'warning: git ls-tree failed to return data for manifest: '
|
self._LogWarning(f'git ls-tree failed to return data for manifest: '
|
||||||
f'{self._manifest.manifestFile}')
|
f'{self._manifest.manifestFile}')
|
||||||
return CommitIdsResult(None, True)
|
return CommitIdsResult(None, True)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user