Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(24)

Side by Side Diff: third_party/WebKit/Tools/Scripts/webkitpy/common/checkout/diff_parser.py

Issue 2014063002: Run format-webkit on webkitpy code (without string conversion). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 # Copyright (C) 2009 Google Inc. All rights reserved. 1 # Copyright (C) 2009 Google Inc. All rights reserved.
2 # 2 #
3 # Redistribution and use in source and binary forms, with or without 3 # Redistribution and use in source and binary forms, with or without
4 # modification, are permitted provided that the following conditions are 4 # modification, are permitted provided that the following conditions are
5 # met: 5 # met:
6 # 6 #
7 # * Redistributions of source code must retain the above copyright 7 # * Redistributions of source code must retain the above copyright
8 # notice, this list of conditions and the following disclaimer. 8 # notice, this list of conditions and the following disclaimer.
9 # * Redistributions in binary form must reproduce the above 9 # * Redistributions in binary form must reproduce the above
10 # copyright notice, this list of conditions and the following disclaimer 10 # copyright notice, this list of conditions and the following disclaimer
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 if diff_git_pattern.match(line): 80 if diff_git_pattern.match(line):
81 return git_diff_to_svn_diff 81 return git_diff_to_svn_diff
82 return svn_diff_to_svn_diff 82 return svn_diff_to_svn_diff
83 83
84 _INITIAL_STATE = 1 84 _INITIAL_STATE = 1
85 _DECLARED_FILE_PATH = 2 85 _DECLARED_FILE_PATH = 2
86 _PROCESSING_CHUNK = 3 86 _PROCESSING_CHUNK = 3
87 87
88 88
89 class DiffFile(object): 89 class DiffFile(object):
90
90 """Contains the information for one file in a patch. 91 """Contains the information for one file in a patch.
qyearsley 2016/05/27 16:06:03 Blank line before class docstring is not necessari
Dirk Pranke 2016/06/01 00:06:47 I'm not particularly a fan of the blank line.
qyearsley 2016/06/01 21:24:22 Alright -- changed formatter/main.py to not add th
91 92
92 The field "lines" is a list which contains tuples in this format: 93 The field "lines" is a list which contains tuples in this format:
93 (deleted_line_number, new_line_number, line_string) 94 (deleted_line_number, new_line_number, line_string)
94 If deleted_line_number is zero, it means this line is newly added. 95 If deleted_line_number is zero, it means this line is newly added.
95 If new_line_number is zero, it means this line is deleted. 96 If new_line_number is zero, it means this line is deleted.
96 """ 97 """
97 # FIXME: Tuples generally grow into classes. We should consider 98 # FIXME: Tuples generally grow into classes. We should consider
98 # adding a DiffLine object. 99 # adding a DiffLine object.
99 100
100 def added_or_modified_line_numbers(self): 101 def added_or_modified_line_numbers(self):
(...skipping 11 matching lines...) Expand all
112 def add_deleted_line(self, line_number, line): 113 def add_deleted_line(self, line_number, line):
113 self.lines.append((line_number, 0, line)) 114 self.lines.append((line_number, 0, line))
114 115
115 def add_unchanged_line(self, deleted_line_number, new_line_number, line): 116 def add_unchanged_line(self, deleted_line_number, new_line_number, line):
116 self.lines.append((deleted_line_number, new_line_number, line)) 117 self.lines.append((deleted_line_number, new_line_number, line))
117 118
118 119
119 # If this is going to be called DiffParser, it should be a re-useable parser. 120 # If this is going to be called DiffParser, it should be a re-useable parser.
120 # Otherwise we should rename it to ParsedDiff or just Diff. 121 # Otherwise we should rename it to ParsedDiff or just Diff.
121 class DiffParser(object): 122 class DiffParser(object):
123
122 """A parser for a patch file. 124 """A parser for a patch file.
123 125
124 The field "files" is a dict whose key is the filename and value is 126 The field "files" is a dict whose key is the filename and value is
125 a DiffFile object. 127 a DiffFile object.
126 """ 128 """
127 129
128 def __init__(self, diff_input): 130 def __init__(self, diff_input):
129 """Parses a diff. 131 """Parses a diff.
130 132
131 Args: 133 Args:
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 current_file.add_unchanged_line(old_diff_line, new_diff_line , line[1:]) 176 current_file.add_unchanged_line(old_diff_line, new_diff_line , line[1:])
175 old_diff_line += 1 177 old_diff_line += 1
176 new_diff_line += 1 178 new_diff_line += 1
177 elif line == '\\ No newline at end of file': 179 elif line == '\\ No newline at end of file':
178 # Nothing to do. We may still have some added lines. 180 # Nothing to do. We may still have some added lines.
179 pass 181 pass
180 else: 182 else:
181 _log.error('Unexpected diff format when parsing a ' 183 _log.error('Unexpected diff format when parsing a '
182 'chunk: %r' % line) 184 'chunk: %r' % line)
183 return files 185 return files
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698