Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # | 2 # |
| 3 # Copyright 2015 The Chromium Authors. All rights reserved. | 3 # Copyright 2015 The Chromium Authors. All rights reserved. |
| 4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
| 5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
| 6 | 6 |
| 7 """Gets list of revisions between two commits and their commit positions. | 7 """Gets list of revisions between two commits and their commit positions. |
| 8 | 8 |
| 9 Example usage: | 9 Example usage: |
| 10 ./fetch_intervening_revisions.py 343b531d31 7b43807df3 \ | 10 ./fetch_intervening_revisions.py 343b531d31 7b43807df3 \ |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 34 | 34 |
| 35 def fetch_intervening_revisions(start, end, base_url): | 35 def fetch_intervening_revisions(start, end, base_url): |
| 36 """Fetches a list of revision in between two commits. | 36 """Fetches a list of revision in between two commits. |
| 37 | 37 |
| 38 Args: | 38 Args: |
| 39 start (str): A git commit hash in the Chromium src repository. | 39 start (str): A git commit hash in the Chromium src repository. |
| 40 end (str): Another git commit hash, after start. | 40 end (str): Another git commit hash, after start. |
| 41 base_url (str): A repository gitiles URL. | 41 base_url (str): A repository gitiles URL. |
| 42 | 42 |
| 43 Returns: | 43 Returns: |
| 44 A list of pairs (commit hash, commit position), from earliest to latest, | 44 A list of pairs (commit hash, commit position), from earliest to latest, |
|
dtu
2016/08/26 01:16:56
This comment needs to be updated.
RobertoCN
2016/08/26 18:17:36
Done.
| |
| 45 for all commits in between the two given commits, not including either | 45 for all commits in between the two given commits, not including either |
| 46 of the given commits. | 46 of the given commits. |
| 47 | 47 |
| 48 Raises: | 48 Raises: |
| 49 urllib2.URLError: The request to gitiles failed. | 49 urllib2.URLError: The request to gitiles failed. |
| 50 ValueError: The response wasn't valid JSON. | 50 ValueError: The response wasn't valid JSON. |
| 51 KeyError: The JSON didn't contain the expected data. | 51 KeyError: The JSON didn't contain the expected data. |
| 52 """ | 52 """ |
| 53 revisions = _fetch_range_from_gitiles(start, end, base_url) | 53 revisions = _fetch_range_from_gitiles(start, end, base_url) |
| 54 # The response from gitiles includes the end revision and is ordered | 54 # The response from gitiles includes the end revision and is ordered |
| 55 # from latest to earliest. | 55 # from latest to earliest. |
| 56 return [_commit_pair(r) for r in reversed(revisions[1:])] | 56 return [_commit_pair(r) for r in reversed(revisions)] |
| 57 | 57 |
| 58 | 58 |
| 59 def _fetch_range_from_gitiles(start, end, base_url): | 59 def _fetch_range_from_gitiles(start, end, base_url): |
| 60 """Fetches a list of revision dicts from gitiles. | 60 """Fetches a list of revision dicts from gitiles. |
| 61 | 61 |
| 62 Make multiple requests to get multiple pages, if necessary. | 62 Make multiple requests to get multiple pages, if necessary. |
| 63 """ | 63 """ |
| 64 revisions = [] | 64 revisions = [] |
| 65 url = '%s/+log/%s..%s?format=json&n=%d' % (base_url, start, end, _PAGE_SIZE) | 65 url = '%s/+log/%s..%s?format=json&n=%d' % (base_url, start, end, _PAGE_SIZE) |
| 66 current_page_url = url | 66 current_page_url = url |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 93 parser.add_argument('end') | 93 parser.add_argument('end') |
| 94 parser.add_argument('url') | 94 parser.add_argument('url') |
| 95 args = parser.parse_args() | 95 args = parser.parse_args() |
| 96 revision_pairs = fetch_intervening_revisions( | 96 revision_pairs = fetch_intervening_revisions( |
| 97 args.start, args.end, args.url) | 97 args.start, args.end, args.url) |
| 98 print json.dumps(revision_pairs) | 98 print json.dumps(revision_pairs) |
| 99 | 99 |
| 100 | 100 |
| 101 if __name__ == '__main__': | 101 if __name__ == '__main__': |
| 102 main() | 102 main() |
| OLD | NEW |