summaryrefslogtreecommitdiffstats
path: root/meta/lib/oeqa/utils/gitarchive.py
diff options
context:
space:
mode:
Diffstat (limited to 'meta/lib/oeqa/utils/gitarchive.py')
-rw-r--r--meta/lib/oeqa/utils/gitarchive.py56
1 files changed, 51 insertions, 5 deletions
diff --git a/meta/lib/oeqa/utils/gitarchive.py b/meta/lib/oeqa/utils/gitarchive.py
index 6e8040eb5c..10cb267dfa 100644
--- a/meta/lib/oeqa/utils/gitarchive.py
+++ b/meta/lib/oeqa/utils/gitarchive.py
@@ -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
103def 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
104def expand_tag_strings(repo, name_pattern, msg_subj_pattern, msg_body_pattern, 139def 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
@@ -116,7 +151,7 @@ def expand_tag_strings(repo, name_pattern, msg_subj_pattern, msg_body_pattern,
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,
@@ -181,7 +217,7 @@ def get_test_runs(log, repo, tag_name, **kwargs):
181 217
182 # Get a list of all matching tags 218 # Get a list of all matching tags
183 tag_pattern = tag_name.format(**str_fields) 219 tag_pattern = tag_name.format(**str_fields)
184 tags = repo.run_cmd(['tag', '-l', tag_pattern]).splitlines() 220 tags = get_tags(repo, log, pattern=tag_pattern)
185 log.debug("Found %d tags matching pattern '%s'", len(tags), tag_pattern) 221 log.debug("Found %d tags matching pattern '%s'", len(tags), tag_pattern)
186 222
187 # Parse undefined fields from tag names 223 # Parse undefined fields from tag names
@@ -199,6 +235,8 @@ def get_test_runs(log, repo, tag_name, **kwargs):
199 revs = [] 235 revs = []
200 for tag in tags: 236 for tag in tags:
201 m = tag_re.match(tag) 237 m = tag_re.match(tag)
238 if not m:
239 continue
202 groups = m.groupdict() 240 groups = m.groupdict()
203 revs.append([groups[f] for f in undef_fields] + [tag]) 241 revs.append([groups[f] for f in undef_fields] + [tag])
204 242
@@ -219,7 +257,15 @@ def get_test_revs(log, repo, tag_name, **kwargs):
219 if not commit in revs: 257 if not commit in revs:
220 revs[commit] = TestedRev(commit, commit_num, [tag]) 258 revs[commit] = TestedRev(commit, commit_num, [tag])
221 else: 259 else:
222 assert commit_num == revs[commit].commit_number, "Commit numbers do not match" 260 if commit_num != revs[commit].commit_number:
261 # Historically we have incorrect commit counts of '1' in the repo so fix these up
262 if int(revs[commit].commit_number) < 5:
263 tags = revs[commit].tags
264 revs[commit] = TestedRev(commit, commit_num, [tags])
265 elif int(commit_num) < 5:
266 pass
267 else:
268 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) 269 revs[commit].tags.append(tag)
224 270
225 # Return in sorted table 271 # Return in sorted table