Skip to content

Commit 0565c25

Browse files
committed
New command mbed releases - Show release tags for the current program or library.
This enables listing of tags matched against common release naming patterns, e.g. v1.2, r1.3.5, mbed-os-5.1.2, etc The command supports the following switches -a|-all - Show all, including release candidates, alpha, betas -r|--recursive - Show releases for all libraries and sub-libraries as well Also `mbed ls` uses some of the routines from `mbed releases` and now shows associated tags/releases
1 parent 63c9daa commit 0565c25

File tree

1 file changed

+76
-7
lines changed

1 file changed

+76
-7
lines changed

mbed/mbed.py

Lines changed: 76 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,11 @@
110110
# mbed sdk builds url
111111
regex_build_url = r'^(https?://([\w\-\.]*mbed\.(co\.uk|org|com))/(users|teams)/([\w\-]{1,32})/(repos|code)/([\w\-]+))/builds/?([\w\-]{6,40}|tip)?/?$'
112112

113+
# match official release tags
114+
regex_rels_official = r'^((mbed-os-\d+.\d+.\d+)|([rv]?\.?\d+(\.\d+)*))$'
115+
# match rc/beta/alpha release tags
116+
regex_rels_all = r'^(mbed-os-\d+.\d+.\d+|[rv]?\.?\d+(\.\d+)?)(\-?[a-z0-9]+)?$'
117+
113118
# base url for all mbed related repos (used as sort of index)
114119
mbed_base_url = 'https://github.com/ARMmbed'
115120
# default mbed OS url
@@ -369,6 +374,9 @@ def getrev():
369374
def getbranch():
370375
return "default"
371376

377+
def gettags(rev=None):
378+
return []
379+
372380

373381
# pylint: disable=no-self-argument, no-method-argument, no-member, no-self-use, unused-argument
374382
@scm('hg')
@@ -512,6 +520,9 @@ def getrev():
512520
def getbranch():
513521
return pquery([hg_cmd, 'branch']).strip() or ""
514522

523+
def gettags(rev=None):
524+
return []
525+
515526
def remoteid(url, rev=None):
516527
return pquery([hg_cmd, 'id', '--id', url] + (['-r', rev] if rev else [])).strip() or ""
517528

@@ -657,7 +668,7 @@ def checkout(rev, clean=False):
657668
return
658669
info("Checkout \"%s\" in %s" % (rev, os.path.basename(os.getcwd())))
659670
branch = None
660-
refs = Git.getrefs(rev)
671+
refs = Git.getbranches(rev)
661672
for ref in refs: # re-associate with a local or remote branch (rev is the same)
662673
m = re.match(r'^(.*?)\/(.*?)$', ref)
663674
if m and m.group(2) != "HEAD": # matches origin/<branch> and isn't HEAD ref
@@ -774,17 +785,42 @@ def getbranch(rev='HEAD'):
774785
branch = "master"
775786
return branch if branch != "HEAD" else ""
776787

777-
# Finds refs (local or remote branches). Will match rev if specified
778-
def getrefs(rev=None, ret_rev=False):
788+
# Get all refs
789+
def getrefs():
790+
try:
791+
return pquery([git_cmd, 'show-ref', '--dereference']).strip().splitlines()
792+
except ProcessException:
793+
return []
794+
795+
# Finds branches (local or remote). Will match rev if specified
796+
def getbranches(rev=None, ret_rev=False):
779797
result = []
780-
lines = pquery([git_cmd, 'show-ref']).strip().splitlines()
781-
for line in lines:
782-
m = re.match(r'^(.+)\s+(.+)$', line)
798+
refs = Git.getrefs()
799+
for ref in refs:
800+
m = re.match(r'^(.+)\s+(.+)$', ref)
783801
if m and (not rev or m.group(1).startswith(rev)):
784802
if re.match(r'refs\/(heads|remotes)\/', m.group(2)): # exclude tags
785803
result.append(m.group(1) if ret_rev else re.sub(r'refs\/(heads|remotes)\/', '', m.group(2)))
786804
return result
787805

806+
# Finds tags. Will match rev if specified
807+
def gettags(rev=None):
808+
tags = []
809+
refs = Git.getrefs()
810+
for ref in refs:
811+
m = re.match(r'^(.+)\s+(.+)$', ref)
812+
if m and (not rev or m.group(1).startswith(rev)):
813+
if re.match(r'refs\/tags\/', m.group(2)): # only tags
814+
t = re.sub(r'refs\/tags\/', '', m.group(2))
815+
if re.match(r'^(.+)\^\{\}$', t): # detect tag "symlink"
816+
t = re.sub(r'\^\{\}$', '', t) # remove "symlink" chars, e.g. some-tag^{}
817+
for tag in tags:
818+
if tag[1] == t:
819+
tags.remove(tag)
820+
#tags = {key:tag for key, tag in tags.items() if tag != t} # remove duplicate
821+
tags.append(t if rev else [m.group(1), t])
822+
return tags
823+
788824
# Finds branches a rev belongs to
789825
def revbranches(rev):
790826
branches = []
@@ -2123,8 +2159,10 @@ def sync(recursive=True, keep_refs=False, top=True):
21232159
"View the dependency tree of the current program or library."))
21242160
def list_(detailed=False, prefix='', p_path=None, ignore=False):
21252161
repo = Repo.fromrepo()
2162+
revtags = repo.scm.gettags(repo.rev) if repo.rev else []
2163+
rev = ', '.join(revtags[0:3]) if len(revtags) else str(repo.rev)[:12] if repo.rev else ''
21262164

2127-
print "%s (%s)" % (prefix + (relpath(p_path, repo.path) if p_path else repo.name), ((repo.url+('#'+str(repo.rev)[:12] if repo.rev else '') if detailed else str(repo.rev)[:12]) or 'no revision'))
2165+
print "%s (%s)" % (prefix + (relpath(p_path, repo.path) if p_path else repo.name), ((repo.url+('#'+str(repo.rev)[:12] if repo.rev else '') if detailed else rev) or 'no revision'))
21282166

21292167
for i, lib in enumerate(sorted(repo.libs, key=lambda l: l.path)):
21302168
if prefix:
@@ -2138,6 +2176,37 @@ def list_(detailed=False, prefix='', p_path=None, ignore=False):
21382176
list_(detailed, nprefix, repo.path, ignore=ignore)
21392177

21402178

2179+
# Command status for cross-SCM status of repositories
2180+
@subcommand('releases',
2181+
dict(name=['-a', '--all'], dest='all_refs', action='store_true', help='Show all, e.g. release candidates, alpha, betas'),
2182+
dict(name=['-r', '--recursive'], action='store_true', help='Show releases for all libraries and sub-libraries as well'),
2183+
help='Shows release tags\n\n',
2184+
description=(
2185+
"Show release tags for the current program or library."))
2186+
def releases_(all_refs=False, recursive=False):
2187+
repo = Repo.fromrepo()
2188+
tags = repo.scm.gettags()
2189+
revtags = repo.scm.gettags(repo.rev) # associated tags with current commit
2190+
2191+
action("Releases in %s \"%s\"\n" % (repo.pathtype(repo.path), repo.name))
2192+
regex = regex_rels_all if all_refs else regex_rels_official
2193+
rels = []
2194+
for tag in tags:
2195+
if re.match(regex, tag[1]):
2196+
rels.append(tag[1] + " %s%s" % (tag[0] if verbose else "", " <- current" if tag[1] in revtags else ""))
2197+
2198+
if len(rels):
2199+
for rel in rels:
2200+
log(rel+"\n")
2201+
else:
2202+
log("None\n")
2203+
log("\n")
2204+
2205+
if recursive:
2206+
for lib in repo.libs:
2207+
with cd(lib.path):
2208+
releases_(all_refs, recursive)
2209+
21412210
# Command status for cross-SCM status of repositories
21422211
@subcommand('status',
21432212
dict(name=['-I', '--ignore'], action='store_true', help='Ignore errors related to missing libraries.'),

0 commit comments

Comments
 (0)