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

Side by Side Diff: trychange.py

Issue 399009: Reapply 32057, 32058, 32059, 32062 and fixes problems introduced by these changes. (Closed)
Patch Set: Created 11 years, 1 month 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
« no previous file with comments | « tests/trychange_unittest.py ('k') | 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/python 1 #!/usr/bin/python
2 # Copyright (c) 2009 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2009 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 """Client-side script to send a try job to the try server. It communicates to 5 """Client-side script to send a try job to the try server. It communicates to
6 the try server by either writting to a svn repository or by directly connecting 6 the try server by either writting to a svn repository or by directly connecting
7 to the server by HTTP. 7 to the server by HTTP.
8 """ 8 """
9 9
10 10
11 import datetime 11 import datetime
12 import getpass 12 import getpass
13 import logging 13 import logging
14 import optparse 14 import optparse
15 import os 15 import os
16 import shutil 16 import shutil
17 import socket 17 import socket
18 import subprocess 18 import subprocess
19 import sys 19 import sys
20 import tempfile 20 import tempfile
21 import urllib 21 import urllib
22 22
23 import gcl 23 import gcl
24 import gclient_scm 24 import scm
25 import presubmit_support 25 import presubmit_support
26 import upload 26 import upload
27 27
28 __version__ = '1.1.1' 28 __version__ = '1.1.2'
29 29
30 30
31 # Constants 31 # Constants
32 HELP_STRING = "Sorry, Tryserver is not available." 32 HELP_STRING = "Sorry, Tryserver is not available."
33 USAGE = r"""%prog [change_name] [options] 33 USAGE = r"""%prog [change_name] [options]
34 34
35 Client-side script to send a try job to the try server. It communicates to 35 Client-side script to send a try job to the try server. It communicates to
36 the try server by either writting to a svn repository or by directly connecting 36 the try server by either writting to a svn repository or by directly connecting
37 to the server by HTTP. 37 to the server by HTTP.
38 38
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 The files in the list should either be absolute paths or relative to the 143 The files in the list should either be absolute paths or relative to the
144 given root. If no root directory is provided, the repository root will be 144 given root. If no root directory is provided, the repository root will be
145 used. 145 used.
146 """ 146 """
147 previous_cwd = os.getcwd() 147 previous_cwd = os.getcwd()
148 if root is None: 148 if root is None:
149 os.chdir(gcl.GetRepositoryRoot()) 149 os.chdir(gcl.GetRepositoryRoot())
150 else: 150 else:
151 os.chdir(root) 151 os.chdir(root)
152 152
153 diff = [] 153 # Directories will return None so filter them out.
154 for filename in files: 154 diff = filter(None, [scm.SVN.DiffItem(f) for f in files])
155 # Use svn info output instead of os.path.isdir because the latter fails
156 # when the file is deleted.
157 if gclient_scm.CaptureSVNInfo(filename).get("Node Kind") in (
158 "dir", "directory"):
159 continue
160 # If the user specified a custom diff command in their svn config file,
161 # then it'll be used when we do svn diff, which we don't want to happen
162 # since we want the unified diff. Using --diff-cmd=diff doesn't always
163 # work, since they can have another diff executable in their path that
164 # gives different line endings. So we use a bogus temp directory as the
165 # config directory, which gets around these problems.
166 if sys.platform.startswith("win"):
167 parent_dir = tempfile.gettempdir()
168 else:
169 parent_dir = sys.path[0] # tempdir is not secure.
170 bogus_dir = os.path.join(parent_dir, "temp_svn_config")
171 if not os.path.exists(bogus_dir):
172 os.mkdir(bogus_dir)
173 # Grabs the diff data.
174 data = gcl.RunShell(["svn", "diff", "--config-dir", bogus_dir, filename])
175
176 # We know the diff will be incorrectly formatted. Fix it.
177 if gcl.IsSVNMoved(filename):
178 # The file is "new" in the patch sense. Generate a homebrew diff.
179 # We can't use ReadFile() since it's not using binary mode.
180 file_handle = open(filename, 'rb')
181 file_content = file_handle.read()
182 file_handle.close()
183 # Prepend '+' to every lines.
184 file_content = ['+' + i for i in file_content.splitlines(True)]
185 nb_lines = len(file_content)
186 # We need to use / since patch on unix will fail otherwise.
187 filename = filename.replace('\\', '/')
188 data = "Index: %s\n" % filename
189 data += ("============================================================="
190 "======\n")
191 # Note: Should we use /dev/null instead?
192 data += "--- %s\n" % filename
193 data += "+++ %s\n" % filename
194 data += "@@ -0,0 +1,%d @@\n" % nb_lines
195 data += ''.join(file_content)
196 diff.append(data)
197 os.chdir(previous_cwd) 155 os.chdir(previous_cwd)
198 return "".join(diff) 156 return "".join(diff)
199 157
200 def GetFileNames(self): 158 def GetFileNames(self):
201 """Return the list of files in the diff.""" 159 """Return the list of files in the diff."""
202 return self.change_info.GetFileNames() 160 return self.change_info.GetFileNames()
203 161
204 def GetLocalRoot(self): 162 def GetLocalRoot(self):
205 """Return the path of the repository root.""" 163 """Return the path of the repository root."""
206 return self.change_info.GetLocalRoot() 164 return self.change_info.GetLocalRoot()
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 NOTE: Very similar to upload.GuessVCS. Doesn't look for hg since we don't 358 NOTE: Very similar to upload.GuessVCS. Doesn't look for hg since we don't
401 support it yet. 359 support it yet.
402 360
403 This examines the current directory, guesses which SCM we're using, and 361 This examines the current directory, guesses which SCM we're using, and
404 returns an instance of the appropriate class. Exit with an error if we can't 362 returns an instance of the appropriate class. Exit with an error if we can't
405 figure it out. 363 figure it out.
406 364
407 Returns: 365 Returns:
408 A SCM instance. Exits if the SCM can't be guessed. 366 A SCM instance. Exits if the SCM can't be guessed.
409 """ 367 """
368 __pychecker__ = 'no-returnvalues'
410 # Subversion has a .svn in all working directories. 369 # Subversion has a .svn in all working directories.
411 if os.path.isdir('.svn'): 370 if os.path.isdir('.svn'):
412 logging.info("Guessed VCS = Subversion") 371 logging.info("Guessed VCS = Subversion")
413 return SVN(options) 372 return SVN(options)
414 373
415 # Git has a command to test if you're in a git tree. 374 # Git has a command to test if you're in a git tree.
416 # Try running it, but don't die if we don't have git installed. 375 # Try running it, but don't die if we don't have git installed.
417 try: 376 try:
418 out, returncode = gcl.RunShellWithReturnCode(["git", "rev-parse", 377 out, returncode = gcl.RunShellWithReturnCode(["git", "rev-parse",
419 "--is-inside-work-tree"]) 378 "--is-inside-work-tree"])
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
605 except (InvalidScript, NoTryServerAccess), e: 564 except (InvalidScript, NoTryServerAccess), e:
606 if swallow_exception: 565 if swallow_exception:
607 return 1 566 return 1
608 print e 567 print e
609 return 1 568 return 1
610 return 0 569 return 0
611 570
612 571
613 if __name__ == "__main__": 572 if __name__ == "__main__":
614 sys.exit(TryChange(None, None, False)) 573 sys.exit(TryChange(None, None, False))
OLDNEW
« no previous file with comments | « tests/trychange_unittest.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698