Mercurial > hg
comparison mercurial/util.py @ 37801:5cab6f5016fa stable
version: make parser more robust for rc variants and ill-formed strings
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Fri, 20 Apr 2018 20:38:29 +0900 |
parents | 5b8a260769a2 |
children | 8fb9985382be |
comparison
equal
deleted
inserted
replaced
37800:6cf5f5b4eb57 | 37801:5cab6f5016fa |
---|---|
1035 (3, 9) | 1035 (3, 9) |
1036 >>> versiontuple(v, 3) | 1036 >>> versiontuple(v, 3) |
1037 (3, 9, None) | 1037 (3, 9, None) |
1038 >>> versiontuple(v, 4) | 1038 >>> versiontuple(v, 4) |
1039 (3, 9, None, 'rc+2-02a8fea4289b') | 1039 (3, 9, None, 'rc+2-02a8fea4289b') |
1040 | |
1041 >>> versiontuple(b'4.6rc0') | |
1042 (4, 6, None, 'rc0') | |
1043 >>> versiontuple(b'4.6rc0+12-425d55e54f98') | |
1044 (4, 6, None, 'rc0+12-425d55e54f98') | |
1045 >>> versiontuple(b'.1.2.3') | |
1046 (None, None, None, '.1.2.3') | |
1047 >>> versiontuple(b'12.34..5') | |
1048 (12, 34, None, '..5') | |
1049 >>> versiontuple(b'1.2.3.4.5.6') | |
1050 (1, 2, 3, '.4.5.6') | |
1040 """ | 1051 """ |
1041 if not v: | 1052 if not v: |
1042 v = version() | 1053 v = version() |
1043 parts = remod.split('[\+-]', v, 1) | 1054 m = remod.match(br'(\d+(?:\.\d+){,2})[\+-]?(.*)', v) |
1044 if len(parts) == 1: | 1055 if not m: |
1045 vparts, extra = parts[0], None | 1056 vparts, extra = '', v |
1057 elif m.group(2): | |
1058 vparts, extra = m.groups() | |
1046 else: | 1059 else: |
1047 vparts, extra = parts | 1060 vparts, extra = m.group(1), None |
1048 | 1061 |
1049 vints = [] | 1062 vints = [] |
1050 for i in vparts.split('.'): | 1063 for i in vparts.split('.'): |
1051 try: | 1064 try: |
1052 vints.append(int(i)) | 1065 vints.append(int(i)) |