Gentoo Archives: gentoo-portage-dev

From: "Manuel RĂ¼ger" <mrueg@g.o>
To: gentoo-portage-dev@l.g.o
Subject: [gentoo-portage-dev] [PATCH] emerge: Add head commit per repo to --info
Date: Fri, 30 Jun 2017 09:46:39
Message-Id: 00a28bdf-72af-12c8-4ee4-0fbda06cb891@gentoo.org
1 This adds the following to emerge --info output for git and rsync based
2 repositories:
3
4 Head commit of repository gentoo: 0518b330edac963f54f98df33391b8e7b9eaee4c
5 ---
6 pym/_emerge/actions.py | 10 ++++++++++
7 pym/portage/sync/modules/git/__init__.py | 3 ++-
8 pym/portage/sync/modules/git/git.py | 12 ++++++++++++
9 pym/portage/sync/modules/rsync/__init__.py | 3 ++-
10 pym/portage/sync/modules/rsync/rsync.py | 12 ++++++++++++
11 pym/portage/sync/syncbase.py | 5 ++++-
12 6 files changed, 42 insertions(+), 3 deletions(-)
13
14 diff --git a/pym/_emerge/actions.py b/pym/_emerge/actions.py
15 index c8a62fb01..3c6c265f7 100644
16 --- a/pym/_emerge/actions.py
17 +++ b/pym/_emerge/actions.py
18 @@ -1644,8 +1644,18 @@ def action_info(settings, trees, myopts, myfiles):
19
20 for repo in repos:
21 last_sync = portage.grabfile(os.path.join(repo.location, "metadata",
22 "timestamp.chk"))
23 + head_commit = None
24 if last_sync:
25 append("Timestamp of repository %s: %s" % (repo.name, last_sync[0]))
26 + if repo.sync_type:
27 + sync = portage.sync.module_controller.get_class(repo.sync_type)()
28 + options = { 'repo': repo }
29 + try:
30 + head_commit = sync.retrieve_head(options=options)
31 + except NotImplementedError:
32 + head_commit = (1, False)
33 + if head_commit and head_commit[0] == os.EX_OK:
34 + append("Head commit of repository %s: %s" % (repo.name, head_commit[1]))
35
36 # Searching contents for the /bin/sh provider is somewhat
37 # slow. Therefore, use the basename of the symlink target
38 diff --git a/pym/portage/sync/modules/git/__init__.py
39 b/pym/portage/sync/modules/git/__init__.py
40 index e7206e12d..2f1d35226 100644
41 --- a/pym/portage/sync/modules/git/__init__.py
42 +++ b/pym/portage/sync/modules/git/__init__.py
43 @@ -43,12 +43,13 @@ def _check_depth(self, attr):
44 'sourcefile': "git",
45 'class': "GitSync",
46 'description': doc,
47 - 'functions': ['sync', 'new', 'exists'],
48 + 'functions': ['sync', 'new', 'exists', 'retrieve_head'],
49 'func_desc': {
50 'sync': 'Performs a git pull on the repository',
51 'new': 'Creates the new repository at the specified location',
52 'exists': 'Returns a boolean of whether the specified dir ' +
53 'exists and is a valid Git repository',
54 + 'retrieve_head': 'Returns the head commit hash',
55 },
56 'validate_config': CheckGitConfig,
57 'module_specific_options': (
58 diff --git a/pym/portage/sync/modules/git/git.py
59 b/pym/portage/sync/modules/git/git.py
60 index bea79c7e7..8df9ca612 100644
61 --- a/pym/portage/sync/modules/git/git.py
62 +++ b/pym/portage/sync/modules/git/git.py
63 @@ -130,3 +130,15 @@ def update(self):
64 cwd=portage._unicode_encode(self.repo.location))
65
66 return (os.EX_OK, current_rev != previous_rev)
67 +
68 + def retrieve_head(self, **kwargs):
69 + '''Get information about the head commit'''
70 + if kwargs:
71 + self._kwargs(kwargs)
72 + rev_cmd = [self.bin_command, "rev-list", "--max-count=1", "HEAD"]
73 + try:
74 + ret = (os.EX_OK, subprocess.check_output(rev_cmd,
75 + cwd=portage._unicode_encode(self.repo.location)))
76 + except CalledProcessError:
77 + ret = (1, False)
78 + return ret
79 diff --git a/pym/portage/sync/modules/rsync/__init__.py
80 b/pym/portage/sync/modules/rsync/__init__.py
81 index 7ebb5476c..c2fdc4188 100644
82 --- a/pym/portage/sync/modules/rsync/__init__.py
83 +++ b/pym/portage/sync/modules/rsync/__init__.py
84 @@ -17,11 +17,12 @@
85 'sourcefile': "rsync",
86 'class': "RsyncSync",
87 'description': doc,
88 - 'functions': ['sync', 'new', 'exists'],
89 + 'functions': ['sync', 'new', 'exists', 'retrieve_head'],
90 'func_desc': {
91 'sync': 'Performs rsync transfers on the repository',
92 'new': 'Creates the new repository at the specified location',
93 'exists': 'Returns a boolean if the specified directory exists',
94 + 'retrieve_head': 'Returns the head commit based on
95 metadata/timestamp.commit',
96 },
97 'validate_config': CheckSyncConfig,
98 'module_specific_options': (
99 diff --git a/pym/portage/sync/modules/rsync/rsync.py
100 b/pym/portage/sync/modules/rsync/rsync.py
101 index cf958356a..45a70e7dd 100644
102 --- a/pym/portage/sync/modules/rsync/rsync.py
103 +++ b/pym/portage/sync/modules/rsync/rsync.py
104 @@ -303,6 +303,18 @@ def new(self, **kwargs):
105 return (1, False)
106 return self.update()
107
108 + def retrieve_head(self, **kwargs):
109 + '''Get information about the head commit'''
110 + if kwargs:
111 + self._kwargs(kwargs)
112 + last_sync = portage.grabfile(os.path.join(self.repo.location,
113 "metadata", "timestamp.commit"))
114 + ret = (1, False)
115 + if last_sync:
116 + try:
117 + ret = (os.EX_OK, last_sync[0].split()[0])
118 + except IndexError:
119 + pass
120 + return ret
121
122 def _set_rsync_defaults(self):
123 portage.writemsg("PORTAGE_RSYNC_OPTS empty or unset, using hardcoded
124 defaults\n")
125 diff --git a/pym/portage/sync/syncbase.py b/pym/portage/sync/syncbase.py
126 index 6aaa9c437..05e4d69d4 100644
127 --- a/pym/portage/sync/syncbase.py
128 +++ b/pym/portage/sync/syncbase.py
129 @@ -129,8 +129,11 @@ def new(self, **kwargs):
130 '''Do the initial download and install of the repository'''
131 raise NotImplementedError
132
133 -
134 def update(self):
135 '''Update existing repository
136 '''
137 raise NotImplementedError
138 +
139 + def retrieve_head(self, **kwargs):
140 + '''Get information about the head commit'''
141 + raise NotImplementedError

Replies