diff options
Diffstat (limited to 'meta/lib/oeqa/utils/gitarchive.py')
| -rw-r--r-- | meta/lib/oeqa/utils/gitarchive.py | 62 |
1 files changed, 55 insertions, 7 deletions
diff --git a/meta/lib/oeqa/utils/gitarchive.py b/meta/lib/oeqa/utils/gitarchive.py index 6e8040eb5c..7e1d505748 100644 --- a/meta/lib/oeqa/utils/gitarchive.py +++ b/meta/lib/oeqa/utils/gitarchive.py | |||
| @@ -67,7 +67,7 @@ def git_commit_data(repo, data_dir, branch, message, exclude, notes, log): | |||
| 67 | 67 | ||
| 68 | # Remove files that are excluded | 68 | # Remove files that are excluded |
| 69 | if exclude: | 69 | if exclude: |
| 70 | repo.run_cmd(['rm', '--cached'] + [f for f in exclude], env_update) | 70 | repo.run_cmd(['rm', '--cached', '--ignore-unmatch'] + [f for f in exclude], env_update) |
| 71 | 71 | ||
| 72 | tree = repo.run_cmd('write-tree', env_update) | 72 | tree = repo.run_cmd('write-tree', env_update) |
| 73 | 73 | ||
| @@ -100,9 +100,44 @@ def git_commit_data(repo, data_dir, branch, message, exclude, notes, log): | |||
| 100 | if os.path.exists(tmp_index): | 100 | if os.path.exists(tmp_index): |
| 101 | os.unlink(tmp_index) | 101 | os.unlink(tmp_index) |
| 102 | 102 | ||
| 103 | def get_tags(repo, log, pattern=None, url=None): | ||
| 104 | """ Fetch remote tags from current repository | ||
| 105 | |||
| 106 | A pattern can be provided to filter returned tags list | ||
| 107 | An URL can be provided if local repository has no valid remote configured | ||
| 108 | """ | ||
| 109 | |||
| 110 | base_cmd = ['ls-remote', '--refs', '--tags', '-q'] | ||
| 111 | cmd = base_cmd.copy() | ||
| 112 | |||
| 113 | # First try to fetch tags from repository configured remote | ||
| 114 | cmd.append('origin') | ||
| 115 | if pattern: | ||
| 116 | cmd.append("refs/tags/"+pattern) | ||
| 117 | try: | ||
| 118 | tags_refs = repo.run_cmd(cmd) | ||
| 119 | tags = ["".join(d.split()[1].split('/', 2)[2:]) for d in tags_refs.splitlines()] | ||
| 120 | except GitError as e: | ||
| 121 | # If it fails, retry with repository url if one is provided | ||
| 122 | if url: | ||
| 123 | log.info("No remote repository configured, use provided url") | ||
| 124 | cmd = base_cmd.copy() | ||
| 125 | cmd.append(url) | ||
| 126 | if pattern: | ||
| 127 | cmd.append(pattern) | ||
| 128 | tags_refs = repo.run_cmd(cmd) | ||
| 129 | tags = ["".join(d.split()[1].split('/', 2)[2:]) for d in tags_refs.splitlines()] | ||
| 130 | else: | ||
| 131 | log.info("Read local tags only, some remote tags may be missed") | ||
| 132 | cmd = ["tag"] | ||
| 133 | if pattern: | ||
| 134 | cmd += ["-l", pattern] | ||
| 135 | tags = repo.run_cmd(cmd).splitlines() | ||
| 136 | |||
| 137 | return tags | ||
| 103 | 138 | ||
| 104 | def expand_tag_strings(repo, name_pattern, msg_subj_pattern, msg_body_pattern, | 139 | def expand_tag_strings(repo, name_pattern, msg_subj_pattern, msg_body_pattern, |
| 105 | keywords): | 140 | url, log, keywords): |
| 106 | """Generate tag name and message, with support for running id number""" | 141 | """Generate tag name and message, with support for running id number""" |
| 107 | keyws = keywords.copy() | 142 | keyws = keywords.copy() |
| 108 | # Tag number is handled specially: if not defined, we autoincrement it | 143 | # Tag number is handled specially: if not defined, we autoincrement it |
| @@ -111,12 +146,12 @@ def expand_tag_strings(repo, name_pattern, msg_subj_pattern, msg_body_pattern, | |||
| 111 | keyws['tag_number'] = '{tag_number}' | 146 | keyws['tag_number'] = '{tag_number}' |
| 112 | tag_re = format_str(name_pattern, keyws) | 147 | tag_re = format_str(name_pattern, keyws) |
| 113 | # Replace parentheses for proper regex matching | 148 | # Replace parentheses for proper regex matching |
| 114 | tag_re = tag_re.replace('(', '\(').replace(')', '\)') + '$' | 149 | tag_re = tag_re.replace('(', r'\(').replace(')', r'\)') + '$' |
| 115 | # Inject regex group pattern for 'tag_number' | 150 | # Inject regex group pattern for 'tag_number' |
| 116 | tag_re = tag_re.format(tag_number='(?P<tag_number>[0-9]{1,5})') | 151 | tag_re = tag_re.format(tag_number='(?P<tag_number>[0-9]{1,5})') |
| 117 | 152 | ||
| 118 | keyws['tag_number'] = 0 | 153 | keyws['tag_number'] = 0 |
| 119 | for existing_tag in repo.run_cmd('tag').splitlines(): | 154 | for existing_tag in get_tags(repo, log, url=url): |
| 120 | match = re.match(tag_re, existing_tag) | 155 | match = re.match(tag_re, existing_tag) |
| 121 | 156 | ||
| 122 | if match and int(match.group('tag_number')) >= keyws['tag_number']: | 157 | if match and int(match.group('tag_number')) >= keyws['tag_number']: |
| @@ -143,7 +178,8 @@ def gitarchive(data_dir, git_dir, no_create, bare, commit_msg_subject, commit_ms | |||
| 143 | if not no_tag and tagname: | 178 | if not no_tag and tagname: |
| 144 | tag_name, tag_msg = expand_tag_strings(data_repo, tagname, | 179 | tag_name, tag_msg = expand_tag_strings(data_repo, tagname, |
| 145 | tag_msg_subject, | 180 | tag_msg_subject, |
| 146 | tag_msg_body, keywords) | 181 | tag_msg_body, |
| 182 | push, log, keywords) | ||
| 147 | 183 | ||
| 148 | # Commit data | 184 | # Commit data |
| 149 | commit = git_commit_data(data_repo, data_dir, branch_name, | 185 | commit = git_commit_data(data_repo, data_dir, branch_name, |
| @@ -166,6 +202,8 @@ def gitarchive(data_dir, git_dir, no_create, bare, commit_msg_subject, commit_ms | |||
| 166 | log.info("Pushing data to remote") | 202 | log.info("Pushing data to remote") |
| 167 | data_repo.run_cmd(cmd) | 203 | data_repo.run_cmd(cmd) |
| 168 | 204 | ||
| 205 | return tag_name | ||
| 206 | |||
| 169 | # Container class for tester revisions | 207 | # Container class for tester revisions |
| 170 | TestedRev = namedtuple('TestedRev', 'commit commit_number tags') | 208 | TestedRev = namedtuple('TestedRev', 'commit commit_number tags') |
| 171 | 209 | ||
| @@ -181,7 +219,7 @@ def get_test_runs(log, repo, tag_name, **kwargs): | |||
| 181 | 219 | ||
| 182 | # Get a list of all matching tags | 220 | # Get a list of all matching tags |
| 183 | tag_pattern = tag_name.format(**str_fields) | 221 | tag_pattern = tag_name.format(**str_fields) |
| 184 | tags = repo.run_cmd(['tag', '-l', tag_pattern]).splitlines() | 222 | tags = get_tags(repo, log, pattern=tag_pattern) |
| 185 | log.debug("Found %d tags matching pattern '%s'", len(tags), tag_pattern) | 223 | log.debug("Found %d tags matching pattern '%s'", len(tags), tag_pattern) |
| 186 | 224 | ||
| 187 | # Parse undefined fields from tag names | 225 | # Parse undefined fields from tag names |
| @@ -199,6 +237,8 @@ def get_test_runs(log, repo, tag_name, **kwargs): | |||
| 199 | revs = [] | 237 | revs = [] |
| 200 | for tag in tags: | 238 | for tag in tags: |
| 201 | m = tag_re.match(tag) | 239 | m = tag_re.match(tag) |
| 240 | if not m: | ||
| 241 | continue | ||
| 202 | groups = m.groupdict() | 242 | groups = m.groupdict() |
| 203 | revs.append([groups[f] for f in undef_fields] + [tag]) | 243 | revs.append([groups[f] for f in undef_fields] + [tag]) |
| 204 | 244 | ||
| @@ -219,7 +259,15 @@ def get_test_revs(log, repo, tag_name, **kwargs): | |||
| 219 | if not commit in revs: | 259 | if not commit in revs: |
| 220 | revs[commit] = TestedRev(commit, commit_num, [tag]) | 260 | revs[commit] = TestedRev(commit, commit_num, [tag]) |
| 221 | else: | 261 | else: |
| 222 | assert commit_num == revs[commit].commit_number, "Commit numbers do not match" | 262 | if commit_num != revs[commit].commit_number: |
| 263 | # Historically we have incorrect commit counts of '1' in the repo so fix these up | ||
| 264 | if int(revs[commit].commit_number) < 5: | ||
| 265 | tags = revs[commit].tags | ||
| 266 | revs[commit] = TestedRev(commit, commit_num, [tags]) | ||
| 267 | elif int(commit_num) < 5: | ||
| 268 | pass | ||
| 269 | else: | ||
| 270 | sys.exit("Commit numbers for commit %s don't match (%s vs %s)" % (commit, commit_num, revs[commit].commit_number)) | ||
| 223 | revs[commit].tags.append(tag) | 271 | revs[commit].tags.append(tag) |
| 224 | 272 | ||
| 225 | # Return in sorted table | 273 | # Return in sorted table |
