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.
import ConfigParser
import cookielib
import errno
import fnmatch
import getpass
import logging
......@@ -674,10 +675,10 @@ def GetContentType(filename):
# Use a shell for subcommands on Windows to get a PATH search.
use_shell = sys.platform.startswith("win")
def RunShellWithReturnCode(command, print_output=False,
def RunShellWithReturnCodeAndStderr(command, print_output=False,
universal_newlines=True,
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:
command: Command to execute.
......@@ -686,9 +687,11 @@ def RunShellWithReturnCode(command, print_output=False,
universal_newlines: Use universal_newlines flag (default: True).
Returns:
Tuple (output, return code)
Tuple (stdout, stderr, return code)
"""
logging.info("Running %s", command)
env = env.copy()
env['LC_MESSAGES'] = 'C'
p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
shell=use_shell, universal_newlines=universal_newlines,
env=env)
......@@ -709,8 +712,15 @@ def RunShellWithReturnCode(command, print_output=False,
print >>sys.stderr, errout
p.stdout.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,
print_output=False, env=os.environ):
......@@ -1012,9 +1022,15 @@ class SubversionVCS(VersionControlSystem):
dirname, relfilename = os.path.split(filename)
if dirname not in self.svnls_cache:
cmd = ["svn", "list", "-r", self.rev_start, dirname or "."]
out, returncode = RunShellWithReturnCode(cmd)
out, err, returncode = RunShellWithReturnCodeAndStderr(cmd)
if returncode:
ErrorExit("Failed to get status for %s." % filename)
# Directory might not yet exist at start revison
# 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"]
if self.rev_end:
......@@ -1214,19 +1230,8 @@ class GitVCS(VersionControlSystem):
# git config key "diff.external" is used).
env = os.environ.copy()
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.
# This is confusing because the original file will not be shown on the
# 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
return RunShell(["git", "diff", "--no-ext-diff", "--full-index", "-M"]
+ extra_args, env=env)
def GetUnknownFiles(self):
status = RunShell(["git", "ls-files", "--exclude-standard", "--others"],
......@@ -1849,17 +1854,27 @@ def GuessVCSName(options):
if attribute.startswith("p4") and value != None:
return (VCS_PERFORCE, None)
# 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.
# NOTE: we try Mercurial first as it can sit on top of an SVN working copy.
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(["hg", "root"])
out, returncode = RunShellWithReturnCode(command)
if returncode == 0:
return (VCS_MERCURIAL, out.strip())
except OSError, (errno, message):
if errno != 2: # ENOENT -- they don't have hg installed.
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
# 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.
res = RunDetectCommand(VCS_MERCURIAL, ["hg", "root"])
if res != None:
return res
# Subversion has a .svn in all working directories.
if os.path.isdir('.svn'):
logging.info("Guessed VCS = Subversion")
......@@ -1867,23 +1882,15 @@ def GuessVCSName(options):
# 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:
out, returncode = RunShellWithReturnCode(["git", "rev-parse",
res = RunDetectCommand(VCS_GIT, ["git", "rev-parse",
"--is-inside-work-tree"])
if returncode == 0:
return (VCS_GIT, None)
except OSError, (errno, message):
if errno != 2: # ENOENT -- they don't have git installed.
raise
if res != None:
return res
# detect CVS repos use `cvs status && $? == 0` rules
try:
out, returncode = RunShellWithReturnCode(["cvs", "status"])
if returncode == 0:
return (VCS_CVS, None)
except OSError, (errno, message):
if errno != 2:
raise
res = RunDetectCommand(VCS_CVS, ["cvs", "status"])
if res != None:
return res
return (VCS_UNKNOWN, None)
......@@ -2207,6 +2214,9 @@ def RealMain(argv, data=None):
def main():
try:
logging.basicConfig(format=("%(asctime).19s %(levelname)s %(filename)s:"
"%(lineno)s %(message)s "))
os.environ['LC_ALL'] = 'C'
RealMain(sys.argv)
except KeyboardInterrupt:
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