Skip to content

Commit 5e04ff2

Browse files
author
Jakub Ruzicka
committed
pkgenv: display color coded hashes for branches
Commit hashes are now displayed and colored for branches: * Remote patches branch: green if it exists, red if missing * Local patches branch: green if it exists and matches remote hash, yellow otherwise * Upstream branch: green if it exists, yellow if missing This way, you can easily tell the state of branches just by looking at color. All green is good, yellow deserves attention (something missing or local patches branch divergence), red means broken. Change-Id: Ia2be74573dee6db35d211d7c05009fda939984d9
1 parent 9e39355 commit 5e04ff2

File tree

2 files changed

+31
-6
lines changed

2 files changed

+31
-6
lines changed

rdopkg/actions/distgit/actions.py

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,33 @@ def _putv(title, val):
7474

7575
upstream_branch = guess.upstream_branch()
7676
if not git.ref_exists('refs/remotes/%s' % upstream_branch):
77-
upstream_version = 'upstream remote/branch not found'
77+
upstream_version = log.term.yellow('upstream remote/branch not found')
7878
else:
7979
upstream_version = guess.upstream_version(branch=upstream_branch)
8080
if not upstream_version:
81-
upstream_version = 'no version tag found'
81+
upstream_version = log.term.yellow('no version tag found')
82+
83+
remote_hash = git.get_latest_commit_hash(patches_branch)
84+
local_hash = git.get_latest_commit_hash(local_patches_branch)
85+
upstream_hash = git.get_latest_commit_hash(upstream_branch)
86+
if remote_hash:
87+
remote_str = ("{t.green}{hash}{t.normal}"
88+
.format(hash=remote_hash[:6], t=log.term))
89+
else:
90+
remote_str = log.term.red("not found")
91+
if local_hash:
92+
color = 'yellow'
93+
if local_hash == remote_hash:
94+
color = 'green'
95+
local_str = (("{t.%s}{hash}{t.normal}" % color)
96+
.format(hash=local_hash[:6], t=log.term))
97+
else:
98+
local_str = log.term.yellow("not found")
99+
if upstream_hash:
100+
upstream_str = ("{t.green}{hash}{t.normal}"
101+
.format(hash=upstream_hash[:6], t=log.term))
102+
else:
103+
upstream_str = log.term.yellow("not found")
82104

83105
if patches_style == 'review':
84106
if not gerrit_patches_chain:
@@ -98,9 +120,12 @@ def _putv(title, val):
98120
print
99121
_putv('Patches style: ', patches_style)
100122
_putv('Dist-git branch: ', branch)
101-
_putv('Local patches branch: ', local_patches_branch)
102-
_putv('Remote patches branch: ', patches_branch)
103-
_putv('Remote upstream branch:', upstream_branch or 'not found')
123+
_putv('Local patches branch: ',
124+
'%s : %s' % (local_patches_branch, local_str))
125+
_putv('Remote patches branch: ',
126+
'%s : %s' % (patches_branch, remote_str))
127+
_putv('Remote upstream branch:',
128+
'%s : %s' % (upstream_branch, upstream_str))
104129
if patches_style == 'review':
105130
_putv('Patches chain: ', gerrit_review_url)
106131
print

rdopkg/utils/cmd.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ def get_latest_commit_hash(self, ref=None):
277277
cmd = ['log', '-n', '1', '--format=%H']
278278
if ref:
279279
cmd.append(ref)
280-
out = self(*cmd, log_cmd=False)
280+
out = self(*cmd, log_cmd=False, log_fail=False, fatal=False)
281281
return out
282282

283283
def get_latest_tag(self, branch=None):

0 commit comments

Comments
 (0)