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

Side by Side Diff: third_party/upload.py

Issue 10332313: Update upload.py @ f218528d3469 (Closed) Base URL: http://src.chromium.org/svn/trunk/tools/depot_tools/
Patch Set: Created 8 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # coding: utf-8 2 # coding: utf-8
3 # 3 #
4 # Copyright 2007 Google Inc. 4 # Copyright 2007 Google Inc.
5 # 5 #
6 # Licensed under the Apache License, Version 2.0 (the "License"); 6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License. 7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at 8 # You may obtain a copy of the License at
9 # 9 #
10 # http://www.apache.org/licenses/LICENSE-2.0 10 # http://www.apache.org/licenses/LICENSE-2.0
(...skipping 1102 matching lines...) Expand 10 before | Expand all | Expand 10 after
1113 # "addition-with-history". See "svn st" for more information. We need to 1113 # "addition-with-history". See "svn st" for more information. We need to
1114 # upload the original file or else diff parsing will fail if the file was 1114 # upload the original file or else diff parsing will fail if the file was
1115 # edited. 1115 # edited.
1116 if status[0] == "A" and status[3] != "+": 1116 if status[0] == "A" and status[3] != "+":
1117 # We'll need to upload the new content if we're adding a binary file 1117 # We'll need to upload the new content if we're adding a binary file
1118 # since diff's output won't contain it. 1118 # since diff's output won't contain it.
1119 mimetype = RunShell(["svn", "propget", "svn:mime-type", 1119 mimetype = RunShell(["svn", "propget", "svn:mime-type",
1120 self._EscapeFilename(filename)], silent_ok=True) 1120 self._EscapeFilename(filename)], silent_ok=True)
1121 base_content = "" 1121 base_content = ""
1122 is_binary = bool(mimetype) and not mimetype.startswith("text/") 1122 is_binary = bool(mimetype) and not mimetype.startswith("text/")
1123 if is_binary and self.IsImage(filename): 1123 if is_binary:
1124 new_content = self.ReadFile(filename) 1124 new_content = self.ReadFile(filename)
1125 elif (status[0] in ("M", "D", "R") or 1125 elif (status[0] in ("M", "D", "R") or
1126 (status[0] == "A" and status[3] == "+") or # Copied file. 1126 (status[0] == "A" and status[3] == "+") or # Copied file.
1127 (status[0] == " " and status[1] == "M")): # Property change. 1127 (status[0] == " " and status[1] == "M")): # Property change.
1128 args = [] 1128 args = []
1129 if self.options.revision: 1129 if self.options.revision:
1130 # filename must not be escaped. We already add an ampersand here. 1130 # filename must not be escaped. We already add an ampersand here.
1131 url = "%s/%s@%s" % (self.svn_base, filename, self.rev_start) 1131 url = "%s/%s@%s" % (self.svn_base, filename, self.rev_start)
1132 else: 1132 else:
1133 # Don't change filename, it's needed later. 1133 # Don't change filename, it's needed later.
(...skipping 11 matching lines...) Expand all
1145 # this test for binary is exactly the test prescribed by the 1145 # this test for binary is exactly the test prescribed by the
1146 # official SVN docs at 1146 # official SVN docs at
1147 # http://subversion.apache.org/faq.html#binary-files 1147 # http://subversion.apache.org/faq.html#binary-files
1148 is_binary = (bool(mimetype) and 1148 is_binary = (bool(mimetype) and
1149 not mimetype.startswith("text/") and 1149 not mimetype.startswith("text/") and
1150 mimetype not in ("image/x-xbitmap", "image/x-xpixmap")) 1150 mimetype not in ("image/x-xbitmap", "image/x-xpixmap"))
1151 if status[0] == " ": 1151 if status[0] == " ":
1152 # Empty base content just to force an upload. 1152 # Empty base content just to force an upload.
1153 base_content = "" 1153 base_content = ""
1154 elif is_binary: 1154 elif is_binary:
1155 if self.IsImage(filename): 1155 get_base = True
1156 get_base = True 1156 if status[0] == "M":
1157 if status[0] == "M": 1157 if not self.rev_end:
1158 if not self.rev_end: 1158 new_content = self.ReadFile(filename)
1159 new_content = self.ReadFile(filename) 1159 else:
1160 else: 1160 url = "%s/%s@%s" % (self.svn_base, filename, self.rev_end)
1161 url = "%s/%s@%s" % (self.svn_base, filename, self.rev_end) 1161 new_content = RunShell(["svn", "cat", url],
1162 new_content = RunShell(["svn", "cat", url], 1162 universal_newlines=True, silent_ok=True)
1163 universal_newlines=True, silent_ok=True)
1164 else:
1165 base_content = ""
1166 else: 1163 else:
1167 get_base = True 1164 get_base = True
1168 1165
1169 if get_base: 1166 if get_base:
1170 if is_binary: 1167 if is_binary:
1171 universal_newlines = False 1168 universal_newlines = False
1172 else: 1169 else:
1173 universal_newlines = True 1170 universal_newlines = True
1174 if self.rev_start: 1171 if self.rev_start:
1175 # "svn cat -r REV delete_file.txt" doesn't work. cat requires 1172 # "svn cat -r REV delete_file.txt" doesn't work. cat requires
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
1345 base_content = "" 1342 base_content = ""
1346 elif not hash_after: 1343 elif not hash_after:
1347 status = "D" 1344 status = "D"
1348 else: 1345 else:
1349 status = "M" 1346 status = "M"
1350 1347
1351 is_binary = self.IsBinaryData(base_content) 1348 is_binary = self.IsBinaryData(base_content)
1352 is_image = self.IsImage(filename) 1349 is_image = self.IsImage(filename)
1353 1350
1354 # Grab the before/after content if we need it. 1351 # Grab the before/after content if we need it.
1355 # We should include file contents if it's text or it's an image. 1352 # Grab the base content if we don't have it already.
1356 if not is_binary or is_image: 1353 if base_content is None and hash_before:
1357 # Grab the base content if we don't have it already. 1354 base_content = self.GetFileContent(hash_before, is_binary)
1358 if base_content is None and hash_before: 1355 # Only include the "after" file if it's an image; otherwise it
1359 base_content = self.GetFileContent(hash_before, is_binary) 1356 # it is reconstructed from the diff.
1360 # Only include the "after" file if it's an image; otherwise it 1357 if is_image and hash_after:
1361 # it is reconstructed from the diff. 1358 new_content = self.GetFileContent(hash_after, is_binary)
1362 if is_image and hash_after:
1363 new_content = self.GetFileContent(hash_after, is_binary)
1364 1359
1365 return (base_content, new_content, is_binary, status) 1360 return (base_content, new_content, is_binary, status)
1366 1361
1367 1362
1368 class CVSVCS(VersionControlSystem): 1363 class CVSVCS(VersionControlSystem):
1369 """Implementation of the VersionControlSystem interface for CVS.""" 1364 """Implementation of the VersionControlSystem interface for CVS."""
1370 1365
1371 def __init__(self, options): 1366 def __init__(self, options):
1372 super(CVSVCS, self).__init__(options) 1367 super(CVSVCS, self).__init__(options)
1373 1368
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
1526 base_content = RunShell(["hg", "cat", "-r", base_rev, oldrelpath], 1521 base_content = RunShell(["hg", "cat", "-r", base_rev, oldrelpath],
1527 silent_ok=True) 1522 silent_ok=True)
1528 is_binary = self.IsBinaryData(base_content) 1523 is_binary = self.IsBinaryData(base_content)
1529 if status != "R": 1524 if status != "R":
1530 new_content = open(relpath, "rb").read() 1525 new_content = open(relpath, "rb").read()
1531 is_binary = is_binary or self.IsBinaryData(new_content) 1526 is_binary = is_binary or self.IsBinaryData(new_content)
1532 if is_binary and base_content: 1527 if is_binary and base_content:
1533 # Fetch again without converting newlines 1528 # Fetch again without converting newlines
1534 base_content = RunShell(["hg", "cat", "-r", base_rev, oldrelpath], 1529 base_content = RunShell(["hg", "cat", "-r", base_rev, oldrelpath],
1535 silent_ok=True, universal_newlines=False) 1530 silent_ok=True, universal_newlines=False)
1536 if not is_binary or not self.IsImage(relpath): 1531 if not is_binary:
1537 new_content = None 1532 new_content = None
1538 return base_content, new_content, is_binary, status 1533 return base_content, new_content, is_binary, status
1539 1534
1540 1535
1541 class PerforceVCS(VersionControlSystem): 1536 class PerforceVCS(VersionControlSystem):
1542 """Implementation of the VersionControlSystem interface for Perforce.""" 1537 """Implementation of the VersionControlSystem interface for Perforce."""
1543 1538
1544 def __init__(self, options): 1539 def __init__(self, options):
1545 1540
1546 def ConfirmLogin(): 1541 def ConfirmLogin():
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
1847 if not revision: 1842 if not revision:
1848 ErrorExit("Couldn't find base revision for file %s" % filename) 1843 ErrorExit("Couldn't find base revision for file %s" % filename)
1849 is_base_binary = self.IsBaseBinary(base_filename) 1844 is_base_binary = self.IsBaseBinary(base_filename)
1850 base_content = self.GetFileContent(base_filename, 1845 base_content = self.GetFileContent(base_filename,
1851 revision, 1846 revision,
1852 is_base_binary) 1847 is_base_binary)
1853 1848
1854 is_binary = self.IsPendingBinary(filename) 1849 is_binary = self.IsPendingBinary(filename)
1855 if status != "D" and status != "SKIP": 1850 if status != "D" and status != "SKIP":
1856 relpath = self.GetLocalFilename(filename) 1851 relpath = self.GetLocalFilename(filename)
1857 if is_binary and self.IsImage(relpath): 1852 if is_binary:
1858 new_content = open(relpath, "rb").read() 1853 new_content = open(relpath, "rb").read()
1859 1854
1860 return base_content, new_content, is_binary, status 1855 return base_content, new_content, is_binary, status
1861 1856
1862 # NOTE: The SplitPatch function is duplicated in engine.py, keep them in sync. 1857 # NOTE: The SplitPatch function is duplicated in engine.py, keep them in sync.
1863 def SplitPatch(data): 1858 def SplitPatch(data):
1864 """Splits a patch into separate pieces for each file. 1859 """Splits a patch into separate pieces for each file.
1865 1860
1866 Args: 1861 Args:
1867 data: A string containing the output of svn diff. 1862 data: A string containing the output of svn diff.
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after
2349 os.environ['LC_ALL'] = 'C' 2344 os.environ['LC_ALL'] = 'C'
2350 RealMain(sys.argv) 2345 RealMain(sys.argv)
2351 except KeyboardInterrupt: 2346 except KeyboardInterrupt:
2352 print 2347 print
2353 StatusUpdate("Interrupted.") 2348 StatusUpdate("Interrupted.")
2354 sys.exit(1) 2349 sys.exit(1)
2355 2350
2356 2351
2357 if __name__ == "__main__": 2352 if __name__ == "__main__":
2358 main() 2353 main()
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698