OLD | NEW |
---|---|
1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2014 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 import base64 | 5 import base64 |
6 import logging | 6 import logging |
7 import os | |
8 import xml.dom.minidom as minidom | 7 import xml.dom.minidom as minidom |
9 from xml.parsers.expat import ExpatError | 8 from xml.parsers.expat import ExpatError |
10 | 9 |
11 import crash_utils | 10 import crash_utils |
12 from repository_parser_interface import ParserInterface | 11 from repository_parser_interface import ParserInterface |
13 | 12 |
14 | 13 |
15 class GitParser(ParserInterface): | 14 class GitParser(ParserInterface): |
16 """Parser for Git repository in googlesource. | 15 """Parser for Git repository in googlesource. |
17 | 16 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
86 | 85 |
87 # Set url of this CL. | 86 # Set url of this CL. |
88 revision_url_part = self.url_parts_map['revision_url'] % githash | 87 revision_url_part = self.url_parts_map['revision_url'] % githash |
89 revision['url'] = base_url + revision_url_part | 88 revision['url'] = base_url + revision_url_part |
90 | 89 |
91 # Go through changed files, they are in li. | 90 # Go through changed files, they are in li. |
92 lis = ul.getElementsByTagName('li') | 91 lis = ul.getElementsByTagName('li') |
93 for li in lis: | 92 for li in lis: |
94 # Retrieve path and action of the changed file | 93 # Retrieve path and action of the changed file |
95 file_path = li.getElementsByTagName('a')[0].firstChild.nodeValue | 94 file_path = li.getElementsByTagName('a')[0].firstChild.nodeValue |
96 file_action = li.getElementsByTagName('span')[0].getAttribute('class') | 95 file_change_type = li.getElementsByTagName('span')[ |
96 0].getAttribute('class') | |
97 | 97 |
98 # Normalize file action so that it is same as SVN parser. | 98 # Normalize file action so that it is same as SVN parser. |
99 if file_action == 'add': | 99 if file_change_type == 'add': |
Martin Barbella
2014/08/22 02:24:14
Define a map to handle this and use it in both pla
jeun
2014/08/22 22:58:43
Done.
| |
100 file_action = 'A' | 100 file_change_type = 'A' |
101 elif file_action == 'delete': | 101 elif file_change_type == 'delete': |
102 file_action = 'D' | 102 file_change_type = 'D' |
103 elif file_action == 'modify': | 103 elif file_change_type == 'modify': |
104 file_action = 'M' | 104 file_change_type = 'M' |
105 | 105 |
106 # Add the changed file to the map. | 106 # Add the changed file to the map. |
107 changed_file = os.path.basename(file_path) | 107 if file_path not in file_to_revision_map: |
108 if changed_file not in file_to_revision_map: | 108 file_to_revision_map[file_path] = [] |
109 file_to_revision_map[changed_file] = [] | 109 file_to_revision_map[file_path].append((githash, file_change_type)) |
110 file_to_revision_map[changed_file].append((githash, file_action, | |
111 file_path)) | |
112 | 110 |
113 # Add this revision object to the map. | 111 # Add this revision object to the map. |
114 revision_map[githash] = revision | 112 revision_map[githash] = revision |
115 | 113 |
116 # Parse one revision for the start range, because googlesource does not | 114 # Parse one revision for the start range, because googlesource does not |
117 # include the start of the range. | 115 # include the start of the range. |
118 self.ParseRevision(revision_url, range_start, revision_map, | 116 self.ParseRevision(revision_url, range_start, revision_map, |
119 file_to_revision_map) | 117 file_to_revision_map) |
120 | 118 |
121 return (revision_map, file_to_revision_map) | 119 return (revision_map, file_to_revision_map) |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
179 githash = json_revision['commit'] | 177 githash = json_revision['commit'] |
180 | 178 |
181 # Set author, message and URL of this CL. | 179 # Set author, message and URL of this CL. |
182 revision['author'] = json_revision['author']['name'] | 180 revision['author'] = json_revision['author']['name'] |
183 revision['message'] = json_revision['message'] | 181 revision['message'] = json_revision['message'] |
184 revision['url'] = url | 182 revision['url'] = url |
185 | 183 |
186 # Iterate through the changed files. | 184 # Iterate through the changed files. |
187 for diff in json_revision['tree_diff']: | 185 for diff in json_revision['tree_diff']: |
188 file_path = diff['new_path'] | 186 file_path = diff['new_path'] |
189 file_action = diff['type'] | 187 file_change_type = diff['type'] |
190 | 188 |
191 # Normalize file action so that it fits with svn_repository_parser. | 189 # Normalize file action so that it fits with svn_repository_parser. |
192 if file_action == 'add': | 190 if file_change_type == 'add': |
193 file_action = 'A' | 191 file_change_type = 'A' |
194 elif file_action == 'delete': | 192 elif file_change_type == 'delete': |
195 file_action = 'D' | 193 file_change_type = 'D' |
196 elif file_action == 'modify': | 194 elif file_change_type == 'modify': |
197 file_action = 'M' | 195 file_change_type = 'M' |
198 | 196 |
199 # Add the file to the map. | 197 # Add the file to the map. |
200 changed_file = os.path.basename(file_path) | 198 if file_path not in file_to_revision_map: |
201 if changed_file not in file_to_revision_map: | 199 file_to_revision_map[file_path] = [] |
202 file_to_revision_map[changed_file] = [] | 200 file_to_revision_map[file_path].append((githash, file_change_type)) |
203 file_to_revision_map[changed_file].append( | |
204 (githash, file_action, file_path)) | |
205 | 201 |
206 # Add this CL to the map. | 202 # Add this CL to the map. |
207 revision_map[githash] = revision | 203 revision_map[githash] = revision |
208 | 204 |
209 return | 205 return |
210 | 206 |
211 def ParseLineDiff(self, path, component, file_action, githash): | 207 def ParseLineDiff(self, path, component, file_change_type, githash): |
212 changed_line_numbers = [] | 208 changed_line_numbers = [] |
213 changed_line_contents = [] | 209 changed_line_contents = [] |
214 base_url = self.component_to_url_map[component]['repository'] | 210 base_url = self.component_to_url_map[component]['repository'] |
215 backup_url = (base_url + self.url_parts_map['revision_url']) % githash | 211 backup_url = (base_url + self.url_parts_map['revision_url']) % githash |
216 | 212 |
217 # If the file is added (not modified), treat it as if it is not changed. | 213 # If the file is added (not modified), treat it as if it is not changed. |
218 if file_action == 'A': | 214 if file_change_type == 'A': |
219 return (backup_url, changed_line_numbers, changed_line_contents) | 215 return (backup_url, changed_line_numbers, changed_line_contents) |
220 | 216 |
221 # Retrieves the diff data from URL, and if it fails, return emptry lines. | 217 # Retrieves the diff data from URL, and if it fails, return emptry lines. |
222 url = (base_url + self.url_parts_map['diff_url']) % (githash, path) | 218 url = (base_url + self.url_parts_map['diff_url']) % (githash, path) |
223 data = crash_utils.GetDataFromURL(url + '?format=text') | 219 data = crash_utils.GetDataFromURL(url + '?format=text') |
224 if not data: | 220 if not data: |
225 logging.error('Failed to get diff from %s.', url) | 221 logging.error('Failed to get diff from %s.', url) |
226 return (backup_url, changed_line_numbers, changed_line_contents) | 222 return (backup_url, changed_line_numbers, changed_line_contents) |
227 | 223 |
228 # Decode the returned object to line diff info | 224 # Decode the returned object to line diff info |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
282 # region. | 278 # region. |
283 if start <= line and line <= start + count - 1: | 279 if start <= line and line <= start + count - 1: |
284 # If we are in the right region, get the information from the line. | 280 # If we are in the right region, get the information from the line. |
285 revision = blame_line['commit'] | 281 revision = blame_line['commit'] |
286 author = blame_line['author']['name'] | 282 author = blame_line['author']['name'] |
287 revision_url_parts = self.url_parts_map['revision_url'] % revision | 283 revision_url_parts = self.url_parts_map['revision_url'] % revision |
288 revision_url = base_url + revision_url_parts | 284 revision_url = base_url + revision_url_parts |
289 # TODO(jeun): Add a way to get content from JSON object. | 285 # TODO(jeun): Add a way to get content from JSON object. |
290 content = None | 286 content = None |
291 | 287 |
292 return (content, revision, author, revision_url) | 288 (revision_info, _) = self.ParseChangelog(component, revision, revision) |
289 message = revision_info[revision]['message'] | |
290 return (content, revision, author, revision_url, message) | |
293 | 291 |
294 # Return none if the region does not exist. | 292 # Return none if the region does not exist. |
295 return None | 293 return None |
OLD | NEW |