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

Side by Side Diff: trychange.py

Issue 391075: Revert 32057, 32058, 32059, 32062 because they still have unwanted side-effects. (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 scm 24 import gclient_scm
25 import presubmit_support 25 import presubmit_support
26 import upload 26 import upload
27 27
28 __version__ = '1.1.2' 28 __version__ = '1.1.1'
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 # Directories will return None so filter them out. 153 diff = []
154 diff = filter(None, [scm.SVN.DiffItem(f) for f in files]) 154 for filename 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)
155 os.chdir(previous_cwd) 197 os.chdir(previous_cwd)
156 return "".join(diff) 198 return "".join(diff)
157 199
158 def GetFileNames(self): 200 def GetFileNames(self):
159 """Return the list of files in the diff.""" 201 """Return the list of files in the diff."""
160 return self.change_info.GetFileNames() 202 return self.change_info.GetFileNames()
161 203
162 def GetLocalRoot(self): 204 def GetLocalRoot(self):
163 """Return the path of the repository root.""" 205 """Return the path of the repository root."""
164 return self.change_info.GetLocalRoot() 206 return self.change_info.GetLocalRoot()
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 NOTE: Very similar to upload.GuessVCS. Doesn't look for hg since we don't 400 NOTE: Very similar to upload.GuessVCS. Doesn't look for hg since we don't
359 support it yet. 401 support it yet.
360 402
361 This examines the current directory, guesses which SCM we're using, and 403 This examines the current directory, guesses which SCM we're using, and
362 returns an instance of the appropriate class. Exit with an error if we can't 404 returns an instance of the appropriate class. Exit with an error if we can't
363 figure it out. 405 figure it out.
364 406
365 Returns: 407 Returns:
366 A SCM instance. Exits if the SCM can't be guessed. 408 A SCM instance. Exits if the SCM can't be guessed.
367 """ 409 """
368 __pychecker__ = 'no-returnvalues'
369 # Subversion has a .svn in all working directories. 410 # Subversion has a .svn in all working directories.
370 if os.path.isdir('.svn'): 411 if os.path.isdir('.svn'):
371 logging.info("Guessed VCS = Subversion") 412 logging.info("Guessed VCS = Subversion")
372 return SVN(options) 413 return SVN(options)
373 414
374 # Git has a command to test if you're in a git tree. 415 # Git has a command to test if you're in a git tree.
375 # Try running it, but don't die if we don't have git installed. 416 # Try running it, but don't die if we don't have git installed.
376 try: 417 try:
377 out, returncode = gcl.RunShellWithReturnCode(["git", "rev-parse", 418 out, returncode = gcl.RunShellWithReturnCode(["git", "rev-parse",
378 "--is-inside-work-tree"]) 419 "--is-inside-work-tree"])
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
564 except (InvalidScript, NoTryServerAccess), e: 605 except (InvalidScript, NoTryServerAccess), e:
565 if swallow_exception: 606 if swallow_exception:
566 return 1 607 return 1
567 print e 608 print e
568 return 1 609 return 1
569 return 0 610 return 0
570 611
571 612
572 if __name__ == "__main__": 613 if __name__ == "__main__":
573 sys.exit(TryChange(None, None, False)) 614 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