commit: 0e1699ad6b3f8eec56fbd6dd6255ed1145e89dd5
Author: Manuel Rüger <mrueg <AT> gentoo <DOT> org>
AuthorDate: Fri Jun 16 14:48:34 2017 +0000
Commit: Manuel Rüger <mrueg <AT> gentoo <DOT> org>
CommitDate: Tue Jul 4 21:42:45 2017 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=0e1699ad
emerge: Add head commit per repo to --info
This adds the following to emerge --info output for git and rsync based
repositories:
Head commit of repository gentoo: 0518b330edac963f54f98df33391b8e7b9eaee4c
Reviewed-By: Zac Medico <zmedico <AT> gentoo.org>
pym/_emerge/actions.py | 10 ++++++++++
pym/portage/sync/modules/git/__init__.py | 3 ++-
pym/portage/sync/modules/git/git.py | 12 ++++++++++++
pym/portage/sync/modules/rsync/__init__.py | 3 ++-
pym/portage/sync/modules/rsync/rsync.py | 12 ++++++++++++
pym/portage/sync/syncbase.py | 5 ++++-
6 files changed, 42 insertions(+), 3 deletions(-)
diff --git a/pym/_emerge/actions.py b/pym/_emerge/actions.py
index c8a62fb01..3c6c265f7 100644
--- a/pym/_emerge/actions.py
+++ b/pym/_emerge/actions.py
@@ -1644,8 +1644,18 @@ def action_info(settings, trees, myopts, myfiles):
for repo in repos:
last_sync = portage.grabfile(os.path.join(repo.location,
"metadata", "timestamp.chk"))
+ head_commit = None
if last_sync:
append("Timestamp of repository %s: %s" % (repo.name,
last_sync[0]))
+ if repo.sync_type:
+ sync =
portage.sync.module_controller.get_class(repo.sync_type)()
+ options = { 'repo': repo }
+ try:
+ head_commit =
sync.retrieve_head(options=options)
+ except NotImplementedError:
+ head_commit = (1, False)
+ if head_commit and head_commit[0] == os.EX_OK:
+ append("Head commit of repository %s: %s" % (repo.name,
head_commit[1]))
# Searching contents for the /bin/sh provider is somewhat
# slow. Therefore, use the basename of the symlink target
diff --git a/pym/portage/sync/modules/git/__init__.py
b/pym/portage/sync/modules/git/__init__.py
index e7206e12d..2f1d35226 100644
--- a/pym/portage/sync/modules/git/__init__.py
+++ b/pym/portage/sync/modules/git/__init__.py
@@ -43,12 +43,13 @@ module_spec = {
'sourcefile': "git",
'class': "GitSync",
'description': doc,
- 'functions': ['sync', 'new', 'exists'],
+ 'functions': ['sync', 'new', 'exists', 'retrieve_head'],
'func_desc': {
'sync': 'Performs a git pull on the repository',
'new': 'Creates the new repository at the
specified location',
'exists': 'Returns a boolean of whether the
specified dir ' +
'exists and is a valid Git repository',
+ 'retrieve_head': 'Returns the head commit hash',
},
'validate_config': CheckGitConfig,
'module_specific_options': (
diff --git a/pym/portage/sync/modules/git/git.py
b/pym/portage/sync/modules/git/git.py
index bea79c7e7..8df9ca612 100644
--- a/pym/portage/sync/modules/git/git.py
+++ b/pym/portage/sync/modules/git/git.py
@@ -130,3 +130,15 @@ class GitSync(NewBase):
cwd=portage._unicode_encode(self.repo.location))
return (os.EX_OK, current_rev != previous_rev)
+
+ def retrieve_head(self, **kwargs):
+ '''Get information about the head commit'''
+ if kwargs:
+ self._kwargs(kwargs)
+ rev_cmd = [self.bin_command, "rev-list", "--max-count=1",
"HEAD"]
+ try:
+ ret = (os.EX_OK, subprocess.check_output(rev_cmd,
+
cwd=portage._unicode_encode(self.repo.location)))
+ except CalledProcessError:
+ ret = (1, False)
+ return ret
diff --git a/pym/portage/sync/modules/rsync/__init__.py
b/pym/portage/sync/modules/rsync/__init__.py
index 7ebb5476c..c2fdc4188 100644
--- a/pym/portage/sync/modules/rsync/__init__.py
+++ b/pym/portage/sync/modules/rsync/__init__.py
@@ -17,11 +17,12 @@ module_spec = {
'sourcefile': "rsync",
'class': "RsyncSync",
'description': doc,
- 'functions': ['sync', 'new', 'exists'],
+ 'functions': ['sync', 'new', 'exists', 'retrieve_head'],
'func_desc': {
'sync': 'Performs rsync transfers on the
repository',
'new': 'Creates the new repository at the
specified location',
'exists': 'Returns a boolean if the specified
directory exists',
+ 'retrieve_head': 'Returns the head commit based
on metadata/timestamp.commit',
},
'validate_config': CheckSyncConfig,
'module_specific_options': (
diff --git a/pym/portage/sync/modules/rsync/rsync.py
b/pym/portage/sync/modules/rsync/rsync.py
index cf958356a..45a70e7dd 100644
--- a/pym/portage/sync/modules/rsync/rsync.py
+++ b/pym/portage/sync/modules/rsync/rsync.py
@@ -303,6 +303,18 @@ class RsyncSync(NewBase):
return (1, False)
return self.update()
+ def retrieve_head(self, **kwargs):
+ '''Get information about the head commit'''
+ if kwargs:
+ self._kwargs(kwargs)
+ last_sync = portage.grabfile(os.path.join(self.repo.location,
"metadata", "timestamp.commit"))
+ ret = (1, False)
+ if last_sync:
+ try:
+ ret = (os.EX_OK, last_sync[0].split()[0])
+ except IndexError:
+ pass
+ return ret
def _set_rsync_defaults(self):
portage.writemsg("PORTAGE_RSYNC_OPTS empty or unset, using
hardcoded defaults\n")
diff --git a/pym/portage/sync/syncbase.py b/pym/portage/sync/syncbase.py
index 6aaa9c437..05e4d69d4 100644
--- a/pym/portage/sync/syncbase.py
+++ b/pym/portage/sync/syncbase.py
@@ -129,8 +129,11 @@ class NewBase(SyncBase):
'''Do the initial download and install of the repository'''
raise NotImplementedError
-
def update(self):
'''Update existing repository
'''
raise NotImplementedError
+
+ def retrieve_head(self, **kwargs):
+ '''Get information about the head commit'''
+ raise NotImplementedError