110
110
# mbed sdk builds url
111
111
regex_build_url = r'^(https?://([\w\-\.]*mbed\.(co\.uk|org|com))/(users|teams)/([\w\-]{1,32})/(repos|code)/([\w\-]+))/builds/?([\w\-]{6,40}|tip)?/?$'
112
112
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
+
113
118
# base url for all mbed related repos (used as sort of index)
114
119
mbed_base_url = 'https://github.com/ARMmbed'
115
120
# default mbed OS url
@@ -369,6 +374,9 @@ def getrev():
369
374
def getbranch ():
370
375
return "default"
371
376
377
+ def gettags (rev = None ):
378
+ return []
379
+
372
380
373
381
# pylint: disable=no-self-argument, no-method-argument, no-member, no-self-use, unused-argument
374
382
@scm ('hg' )
@@ -512,6 +520,9 @@ def getrev():
512
520
def getbranch ():
513
521
return pquery ([hg_cmd , 'branch' ]).strip () or ""
514
522
523
+ def gettags (rev = None ):
524
+ return []
525
+
515
526
def remoteid (url , rev = None ):
516
527
return pquery ([hg_cmd , 'id' , '--id' , url ] + (['-r' , rev ] if rev else [])).strip () or ""
517
528
@@ -657,7 +668,7 @@ def checkout(rev, clean=False):
657
668
return
658
669
info ("Checkout \" %s\" in %s" % (rev , os .path .basename (os .getcwd ())))
659
670
branch = None
660
- refs = Git .getrefs (rev )
671
+ refs = Git .getbranches (rev )
661
672
for ref in refs : # re-associate with a local or remote branch (rev is the same)
662
673
m = re .match (r'^(.*?)\/(.*?)$' , ref )
663
674
if m and m .group (2 ) != "HEAD" : # matches origin/<branch> and isn't HEAD ref
@@ -774,17 +785,42 @@ def getbranch(rev='HEAD'):
774
785
branch = "master"
775
786
return branch if branch != "HEAD" else ""
776
787
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 ):
779
797
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 )
783
801
if m and (not rev or m .group (1 ).startswith (rev )):
784
802
if re .match (r'refs\/(heads|remotes)\/' , m .group (2 )): # exclude tags
785
803
result .append (m .group (1 ) if ret_rev else re .sub (r'refs\/(heads|remotes)\/' , '' , m .group (2 )))
786
804
return result
787
805
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
+
788
824
# Finds branches a rev belongs to
789
825
def revbranches (rev ):
790
826
branches = []
@@ -2123,8 +2159,10 @@ def sync(recursive=True, keep_refs=False, top=True):
2123
2159
"View the dependency tree of the current program or library." ))
2124
2160
def list_ (detailed = False , prefix = '' , p_path = None , ignore = False ):
2125
2161
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 ''
2126
2164
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' ))
2128
2166
2129
2167
for i , lib in enumerate (sorted (repo .libs , key = lambda l : l .path )):
2130
2168
if prefix :
@@ -2138,6 +2176,37 @@ def list_(detailed=False, prefix='', p_path=None, ignore=False):
2138
2176
list_ (detailed , nprefix , repo .path , ignore = ignore )
2139
2177
2140
2178
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
+
2141
2210
# Command status for cross-SCM status of repositories
2142
2211
@subcommand ('status' ,
2143
2212
dict (name = ['-I' , '--ignore' ], action = 'store_true' , help = 'Ignore errors related to missing libraries.' ),
0 commit comments