|
114 | 114 | # mbed sdk builds url
|
115 | 115 | regex_build_url = r'^(https?://([\w\-\.]*mbed\.(co\.uk|org|com))/(users|teams)/([\w\-]{1,32})/(repos|code)/([\w\-]+))/builds/?([\w\-]{6,40}|tip)?/?$'
|
116 | 116 |
|
| 117 | +# match official release tags |
| 118 | +regex_rels_official = r'^(release|rel|mbed-os|[rv]+)?[.-]?\d+(\.\d+)*$' |
| 119 | +# match rc/beta/alpha release tags |
| 120 | +regex_rels_all = r'^(release|rel|mbed-os|[rv]+)?[.-]?\d+(\.\d+)*([a-z0-9.-]+)?$' |
| 121 | + |
117 | 122 | # base url for all mbed related repos (used as sort of index)
|
118 | 123 | mbed_base_url = 'https://github.com/ARMmbed'
|
119 | 124 | # default mbed OS url
|
@@ -373,6 +378,9 @@ def getrev():
|
373 | 378 | def getbranch():
|
374 | 379 | return "default"
|
375 | 380 |
|
| 381 | + def gettags(rev=None): |
| 382 | + return [] |
| 383 | + |
376 | 384 |
|
377 | 385 | # pylint: disable=no-self-argument, no-method-argument, no-member, no-self-use, unused-argument
|
378 | 386 | @scm('hg')
|
@@ -516,6 +524,15 @@ def getrev():
|
516 | 524 | def getbranch():
|
517 | 525 | return pquery([hg_cmd, 'branch']).strip() or ""
|
518 | 526 |
|
| 527 | + def gettags(rev=None): |
| 528 | + tags = [] |
| 529 | + refs = pquery([hg_cmd, 'tags']).strip().splitlines() or [] |
| 530 | + for ref in refs: |
| 531 | + m = re.match(r'^(.+?)\s+(\d+)\:([a-f0-9]+)$', ref) |
| 532 | + if m and (not rev or m.group(1).startswith(rev)): |
| 533 | + tags.append(m.group(1) if rev else [m.group(3), m.group(1)]) |
| 534 | + return tags |
| 535 | + |
519 | 536 | def remoteid(url, rev=None):
|
520 | 537 | return pquery([hg_cmd, 'id', '--id', url] + (['-r', rev] if rev else [])).strip() or ""
|
521 | 538 |
|
@@ -661,7 +678,7 @@ def checkout(rev, clean=False):
|
661 | 678 | return
|
662 | 679 | info("Checkout \"%s\" in %s" % (rev, os.path.basename(os.getcwd())))
|
663 | 680 | branch = None
|
664 |
| - refs = Git.getrefs(rev) |
| 681 | + refs = Git.getbranches(rev) |
665 | 682 | for ref in refs: # re-associate with a local or remote branch (rev is the same)
|
666 | 683 | m = re.match(r'^(.*?)\/(.*?)$', ref)
|
667 | 684 | if m and m.group(2) != "HEAD": # matches origin/<branch> and isn't HEAD ref
|
@@ -778,17 +795,39 @@ def getbranch(rev='HEAD'):
|
778 | 795 | branch = "master"
|
779 | 796 | return branch if branch != "HEAD" else ""
|
780 | 797 |
|
781 |
| - # Finds refs (local or remote branches). Will match rev if specified |
782 |
| - def getrefs(rev=None, ret_rev=False): |
| 798 | + # Get all refs |
| 799 | + def getrefs(): |
| 800 | + try: |
| 801 | + return pquery([git_cmd, 'show-ref', '--dereference']).strip().splitlines() |
| 802 | + except ProcessException: |
| 803 | + return [] |
| 804 | + |
| 805 | + # Finds branches (local or remote). Will match rev if specified |
| 806 | + def getbranches(rev=None, ret_rev=False): |
783 | 807 | result = []
|
784 |
| - lines = pquery([git_cmd, 'show-ref']).strip().splitlines() |
785 |
| - for line in lines: |
786 |
| - m = re.match(r'^(.+)\s+(.+)$', line) |
| 808 | + refs = Git.getrefs() |
| 809 | + for ref in refs: |
| 810 | + m = re.match(r'^(.+)\s+refs\/(heads|remotes)\/(.+)$', ref) |
787 | 811 | if m and (not rev or m.group(1).startswith(rev)):
|
788 |
| - if re.match(r'refs\/(heads|remotes)\/', m.group(2)): # exclude tags |
789 |
| - result.append(m.group(1) if ret_rev else re.sub(r'refs\/(heads|remotes)\/', '', m.group(2))) |
| 812 | + result.append(m.group(1) if ret_rev else m.group(3)) |
790 | 813 | return result
|
791 | 814 |
|
| 815 | + # Finds tags. Will match rev if specified |
| 816 | + def gettags(rev=None): |
| 817 | + tags = [] |
| 818 | + refs = Git.getrefs() |
| 819 | + for ref in refs: |
| 820 | + m = re.match(r'^(.+)\s+refs\/tags\/(.+)$', ref) |
| 821 | + if m and (not rev or m.group(1).startswith(rev)): |
| 822 | + t = m.group(2) |
| 823 | + if re.match(r'^(.+)\^\{\}$', t): # detect tag "pointer" |
| 824 | + t = re.sub(r'\^\{\}$', '', t) # remove "pointer" chars, e.g. some-tag^{} |
| 825 | + for tag in tags: |
| 826 | + if tag[1] == t: |
| 827 | + tags.remove(tag) |
| 828 | + tags.append(t if rev else [m.group(1), t]) |
| 829 | + return tags |
| 830 | + |
792 | 831 | # Finds branches a rev belongs to
|
793 | 832 | def revbranches(rev):
|
794 | 833 | branches = []
|
@@ -2061,7 +2100,7 @@ def update(rev=None, clean=False, clean_files=False, clean_deps=False, ignore=Fa
|
2061 | 2100 |
|
2062 | 2101 | # Synch command
|
2063 | 2102 | @subcommand('sync',
|
2064 |
| - help='Synchronize library references', |
| 2103 | + help='Synchronize library references\n\n', |
2065 | 2104 | description=(
|
2066 | 2105 | "Synchronizes all library and dependency references (.lib files) in the\n"
|
2067 | 2106 | "current program or library.\n"
|
@@ -2129,21 +2168,63 @@ def sync(recursive=True, keep_refs=False, top=True):
|
2129 | 2168 | "View the dependency tree of the current program or library."))
|
2130 | 2169 | def list_(detailed=False, prefix='', p_path=None, ignore=False):
|
2131 | 2170 | repo = Repo.fromrepo()
|
| 2171 | + revtags = repo.scm.gettags(repo.rev) if repo.rev else [] |
| 2172 | + revstr = ('#' + repo.rev[:12] + (', tags: ' + ', '.join(revtags[0:2]) if len(revtags) else '')) if repo.rev else '' |
2132 | 2173 |
|
2133 |
| - 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')) |
| 2174 | + 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 revstr) or 'no revision')) |
2134 | 2175 |
|
2135 | 2176 | for i, lib in enumerate(sorted(repo.libs, key=lambda l: l.path)):
|
2136 |
| - if prefix: |
2137 |
| - nprefix = prefix[:-3] + ('| ' if prefix[-3] == '|' else ' ') |
2138 |
| - else: |
2139 |
| - nprefix = '' |
| 2177 | + nprefix = (prefix[:-3] + ('| ' if prefix[-3] == '|' else ' ')) if prefix else '' |
2140 | 2178 | nprefix += '|- ' if i < len(repo.libs)-1 else '`- '
|
2141 | 2179 |
|
2142 | 2180 | if lib.check_repo(ignore):
|
2143 | 2181 | with cd(lib.path):
|
2144 | 2182 | list_(detailed, nprefix, repo.path, ignore=ignore)
|
2145 | 2183 |
|
2146 | 2184 |
|
| 2185 | +# Command release for cross-SCM release tags of repositories |
| 2186 | +@subcommand('releases', |
| 2187 | + dict(name=['-a', '--all'], dest='detailed', action='store_true', help='Show revision hashes'), |
| 2188 | + dict(name=['-u', '--unstable'], dest='unstable', action='store_true', help='Show unstable releases well, e.g. release candidates, alphas, betas, etc'), |
| 2189 | + dict(name=['-r', '--recursive'], action='store_true', help='Show release tags for all libraries and sub-libraries as well'), |
| 2190 | + help='Show release tags', |
| 2191 | + description=( |
| 2192 | + "Show release tags for the current program or library.")) |
| 2193 | +def releases_(detailed=False, unstable=False, recursive=False, prefix='', p_path=None): |
| 2194 | + repo = Repo.fromrepo() |
| 2195 | + tags = repo.scm.gettags() |
| 2196 | + revtags = repo.scm.gettags(repo.rev) if repo.rev else [] # associated tags with current commit |
| 2197 | + revstr = ('#' + repo.rev[:12] + (', tags: ' + ', '.join(revtags[0:2]) if len(revtags) else '')) if repo.rev else '' |
| 2198 | + regex_rels = regex_rels_all if unstable else regex_rels_official |
| 2199 | + |
| 2200 | + # Generate list of tags |
| 2201 | + rels = [] |
| 2202 | + for tag in tags: |
| 2203 | + if re.match(regex_rels, tag[1]): |
| 2204 | + rels.append(tag[1] + " %s%s" % ('#' + tag[0] if detailed else "", " <- current" if tag[1] in revtags else "")) |
| 2205 | + |
| 2206 | + # Print header |
| 2207 | + 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 revstr) or 'no revision')) |
| 2208 | + |
| 2209 | + # Print list of tags |
| 2210 | + rprefix = (prefix[:-3] + ('| ' if prefix[-3] == '|' else ' ')) if recursive and prefix else '' |
| 2211 | + rprefix += '| ' if recursive and len(repo.libs) > 1 else ' ' |
| 2212 | + if len(rels): |
| 2213 | + for rel in rels: |
| 2214 | + print rprefix + '* ' + rel |
| 2215 | + else: |
| 2216 | + print rprefix + 'No release tags detected' |
| 2217 | + |
| 2218 | + if recursive: |
| 2219 | + for i, lib in enumerate(sorted(repo.libs, key=lambda l: l.path)): |
| 2220 | + nprefix = (prefix[:-3] + ('| ' if prefix[-3] == '|' else ' ')) if prefix else '' |
| 2221 | + nprefix += '|- ' if i < len(repo.libs)-1 else '`- ' |
| 2222 | + |
| 2223 | + if lib.check_repo(): |
| 2224 | + with cd(lib.path): |
| 2225 | + releases_(detailed, unstable, recursive, nprefix, repo.path) |
| 2226 | + |
| 2227 | + |
2147 | 2228 | # Command status for cross-SCM status of repositories
|
2148 | 2229 | @subcommand('status',
|
2149 | 2230 | dict(name=['-I', '--ignore'], action='store_true', help='Ignore errors related to missing libraries.'),
|
|
0 commit comments