Commit 1c5518ea authored by maruel@chromium.org's avatar maruel@chromium.org

Update upload.py to r705.

R=dpranke@chromium.org
BUG=
TEST=

Review URL: http://codereview.chromium.org/6889002

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@82495 0039d316-1c4b-4281-b951-d872f2087c98
parent dfaecd2b
...@@ -35,6 +35,7 @@ against by using the '--rev' option. ...@@ -35,6 +35,7 @@ against by using the '--rev' option.
import ConfigParser import ConfigParser
import cookielib import cookielib
import errno
import fnmatch import fnmatch
import getpass import getpass
import logging import logging
...@@ -674,10 +675,10 @@ def GetContentType(filename): ...@@ -674,10 +675,10 @@ def GetContentType(filename):
# Use a shell for subcommands on Windows to get a PATH search. # Use a shell for subcommands on Windows to get a PATH search.
use_shell = sys.platform.startswith("win") use_shell = sys.platform.startswith("win")
def RunShellWithReturnCode(command, print_output=False, def RunShellWithReturnCodeAndStderr(command, print_output=False,
universal_newlines=True, universal_newlines=True,
env=os.environ): env=os.environ):
"""Executes a command and returns the output from stdout and the return code. """Executes a command and returns the output from stdout, stderr and the return code.
Args: Args:
command: Command to execute. command: Command to execute.
...@@ -686,9 +687,11 @@ def RunShellWithReturnCode(command, print_output=False, ...@@ -686,9 +687,11 @@ def RunShellWithReturnCode(command, print_output=False,
universal_newlines: Use universal_newlines flag (default: True). universal_newlines: Use universal_newlines flag (default: True).
Returns: Returns:
Tuple (output, return code) Tuple (stdout, stderr, return code)
""" """
logging.info("Running %s", command) logging.info("Running %s", command)
env = env.copy()
env['LC_MESSAGES'] = 'C'
p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
shell=use_shell, universal_newlines=universal_newlines, shell=use_shell, universal_newlines=universal_newlines,
env=env) env=env)
...@@ -709,8 +712,15 @@ def RunShellWithReturnCode(command, print_output=False, ...@@ -709,8 +712,15 @@ def RunShellWithReturnCode(command, print_output=False,
print >>sys.stderr, errout print >>sys.stderr, errout
p.stdout.close() p.stdout.close()
p.stderr.close() p.stderr.close()
return output, p.returncode return output, errout, p.returncode
def RunShellWithReturnCode(command, print_output=False,
universal_newlines=True,
env=os.environ):
"""Executes a command and returns the output from stdout and the return code."""
out, err, retcode = RunShellWithReturnCodeAndStderr(command, print_output,
universal_newlines, env)
return out, retcode
def RunShell(command, silent_ok=False, universal_newlines=True, def RunShell(command, silent_ok=False, universal_newlines=True,
print_output=False, env=os.environ): print_output=False, env=os.environ):
...@@ -1012,10 +1022,16 @@ class SubversionVCS(VersionControlSystem): ...@@ -1012,10 +1022,16 @@ class SubversionVCS(VersionControlSystem):
dirname, relfilename = os.path.split(filename) dirname, relfilename = os.path.split(filename)
if dirname not in self.svnls_cache: if dirname not in self.svnls_cache:
cmd = ["svn", "list", "-r", self.rev_start, dirname or "."] cmd = ["svn", "list", "-r", self.rev_start, dirname or "."]
out, returncode = RunShellWithReturnCode(cmd) out, err, returncode = RunShellWithReturnCodeAndStderr(cmd)
if returncode: if returncode:
ErrorExit("Failed to get status for %s." % filename) # Directory might not yet exist at start revison
old_files = out.splitlines() # svn: Unable to find repository location for 'abc' in revision nnn
if re.match('^svn: Unable to find repository location for .+ in revision \d+', err):
old_files = ()
else:
ErrorExit("Failed to get status for %s:\n%s" % (filename, err))
else:
old_files = out.splitlines()
args = ["svn", "list"] args = ["svn", "list"]
if self.rev_end: if self.rev_end:
args += ["-r", self.rev_end] args += ["-r", self.rev_end]
...@@ -1214,19 +1230,8 @@ class GitVCS(VersionControlSystem): ...@@ -1214,19 +1230,8 @@ class GitVCS(VersionControlSystem):
# git config key "diff.external" is used). # git config key "diff.external" is used).
env = os.environ.copy() env = os.environ.copy()
if 'GIT_EXTERNAL_DIFF' in env: del env['GIT_EXTERNAL_DIFF'] if 'GIT_EXTERNAL_DIFF' in env: del env['GIT_EXTERNAL_DIFF']
# -M/-C will not print the diff for the deleted file when a file is renamed. return RunShell(["git", "diff", "--no-ext-diff", "--full-index", "-M"]
# This is confusing because the original file will not be shown on the + extra_args, env=env)
# review when a file is renamed. So first get the diff of all deleted files,
# then the diff of everything except deleted files with rename and copy
# support enabled.
cmd = ["git", "diff", "--no-ext-diff", "--full-index"]
diff = RunShell(cmd + ["--diff-filter=D"] + extra_args, env=env,
silent_ok=True)
diff += RunShell(cmd + ["-C", "--diff-filter=ACMRT"] + extra_args, env=env,
silent_ok=True)
if not diff:
ErrorExit("No output from %s" % (cmd + extra_args))
return diff
def GetUnknownFiles(self): def GetUnknownFiles(self):
status = RunShell(["git", "ls-files", "--exclude-standard", "--others"], status = RunShell(["git", "ls-files", "--exclude-standard", "--others"],
...@@ -1849,16 +1854,26 @@ def GuessVCSName(options): ...@@ -1849,16 +1854,26 @@ def GuessVCSName(options):
if attribute.startswith("p4") and value != None: if attribute.startswith("p4") and value != None:
return (VCS_PERFORCE, None) return (VCS_PERFORCE, None)
def RunDetectCommand(vcs_type, command):
"""Helper to detect VCS by executing command.
Returns:
A pair (vcs, output) or None. Throws exception on error.
"""
try:
out, returncode = RunShellWithReturnCode(command)
if returncode == 0:
return (vcs_type, out.strip())
except OSError, (errcode, message):
if errcode != errno.ENOENT: # command not found code
raise
# Mercurial has a command to get the base directory of a repository # Mercurial has a command to get the base directory of a repository
# Try running it, but don't die if we don't have hg installed. # Try running it, but don't die if we don't have hg installed.
# NOTE: we try Mercurial first as it can sit on top of an SVN working copy. # NOTE: we try Mercurial first as it can sit on top of an SVN working copy.
try: res = RunDetectCommand(VCS_MERCURIAL, ["hg", "root"])
out, returncode = RunShellWithReturnCode(["hg", "root"]) if res != None:
if returncode == 0: return res
return (VCS_MERCURIAL, out.strip())
except OSError, (errno, message):
if errno != 2: # ENOENT -- they don't have hg installed.
raise
# Subversion has a .svn in all working directories. # Subversion has a .svn in all working directories.
if os.path.isdir('.svn'): if os.path.isdir('.svn'):
...@@ -1867,23 +1882,15 @@ def GuessVCSName(options): ...@@ -1867,23 +1882,15 @@ def GuessVCSName(options):
# Git has a command to test if you're in a git tree. # Git has a command to test if you're in a git tree.
# Try running it, but don't die if we don't have git installed. # Try running it, but don't die if we don't have git installed.
try: res = RunDetectCommand(VCS_GIT, ["git", "rev-parse",
out, returncode = RunShellWithReturnCode(["git", "rev-parse", "--is-inside-work-tree"])
"--is-inside-work-tree"]) if res != None:
if returncode == 0: return res
return (VCS_GIT, None)
except OSError, (errno, message):
if errno != 2: # ENOENT -- they don't have git installed.
raise
# detect CVS repos use `cvs status && $? == 0` rules # detect CVS repos use `cvs status && $? == 0` rules
try: res = RunDetectCommand(VCS_CVS, ["cvs", "status"])
out, returncode = RunShellWithReturnCode(["cvs", "status"]) if res != None:
if returncode == 0: return res
return (VCS_CVS, None)
except OSError, (errno, message):
if errno != 2:
raise
return (VCS_UNKNOWN, None) return (VCS_UNKNOWN, None)
...@@ -2207,6 +2214,9 @@ def RealMain(argv, data=None): ...@@ -2207,6 +2214,9 @@ def RealMain(argv, data=None):
def main(): def main():
try: try:
logging.basicConfig(format=("%(asctime).19s %(levelname)s %(filename)s:"
"%(lineno)s %(message)s "))
os.environ['LC_ALL'] = 'C'
RealMain(sys.argv) RealMain(sys.argv)
except KeyboardInterrupt: except KeyboardInterrupt:
print print
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment