| OLD | NEW |
| (Empty) |
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 # Use of this source code is governed by a BSD-style license that can be | |
| 3 # found in the LICENSE file. | |
| 4 | |
| 5 class FileChangeInfo(object): | |
| 6 """Represents a file change (add/delete/modify/rename/copy/etc).""" | |
| 7 def __init__(self, change_type, old_path, new_path): | |
| 8 self.change_type = change_type | |
| 9 self.old_path = old_path | |
| 10 self.new_path = new_path | |
| 11 | |
| 12 def ToDict(self): | |
| 13 return { | |
| 14 'change_type': self.change_type, | |
| 15 'old_path': self.old_path, | |
| 16 'new_path': self.new_path | |
| 17 } | |
| 18 | |
| 19 @staticmethod | |
| 20 def FromDict(info): | |
| 21 return FileChangeInfo( | |
| 22 info['change_type'], info['old_path'], info['new_path']) | |
| 23 | |
| 24 | |
| 25 class ChangeLog(object): | |
| 26 """Represents the change log of a revision.""" | |
| 27 | |
| 28 def __init__(self, author_name, author_email, author_time, committer_name, | |
| 29 committer_email, committer_time, revision, commit_position, | |
| 30 message, touched_files, commit_url, code_review_url=None, | |
| 31 reverted_revision=None): | |
| 32 self.author_name = author_name | |
| 33 self.author_email = author_email | |
| 34 self.author_time = author_time | |
| 35 self.committer_name = committer_name | |
| 36 self.committer_email = committer_email | |
| 37 self.committer_time = committer_time | |
| 38 self.revision = revision | |
| 39 self.commit_position = commit_position | |
| 40 self.touched_files = touched_files | |
| 41 self.message = message | |
| 42 self.commit_url = commit_url | |
| 43 self.code_review_url = code_review_url | |
| 44 self.reverted_revision = reverted_revision | |
| 45 | |
| 46 def ToDict(self): | |
| 47 """Returns the change log as a JSON object.""" | |
| 48 json_data = { | |
| 49 'author_name': self.author_name, | |
| 50 'author_email': self.author_email, | |
| 51 'author_time': self.author_time, | |
| 52 'committer_name': self.committer_name, | |
| 53 'committer_email': self.committer_email, | |
| 54 'committer_time': self.committer_time, | |
| 55 'revision': self.revision, | |
| 56 'commit_position': self.commit_position, | |
| 57 'touched_files': [], | |
| 58 'message': self.message, | |
| 59 'commit_url': self.commit_url, | |
| 60 'code_review_url': self.code_review_url, | |
| 61 'reverted_revision': self.reverted_revision, | |
| 62 } | |
| 63 for touched_file in self.touched_files: | |
| 64 json_data['touched_files'].append(touched_file.ToDict()) | |
| 65 return json_data | |
| 66 | |
| 67 @staticmethod | |
| 68 def FromDict(info): | |
| 69 """Returns a ChangeLog instance represented by the given JSON info.""" | |
| 70 touched_files = [] | |
| 71 for touched_file_info in info['touched_files']: | |
| 72 touched_files.append(FileChangeInfo.FromDict(touched_file_info)) | |
| 73 | |
| 74 return ChangeLog( | |
| 75 info['author_name'], info['author_email'], info['author_time'], | |
| 76 info['committer_name'], info['committer_email'], info['committer_time'], | |
| 77 info['revision'], info['commit_position'], info['message'], | |
| 78 touched_files, info['commit_url'], info['code_review_url'], | |
| 79 info['reverted_revision'] | |
| 80 ) | |
| OLD | NEW |