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

Unified Diff: checkout.py

Issue 11358165: Enforce 15 minutes timeout for all operations and 30 minutes for checkouts. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Created 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: checkout.py
diff --git a/checkout.py b/checkout.py
index a303b338aca4d2b35ff0caea8c81f3536b8c39dd..da2d86f73a9ab4a40f9371faf894f043d4f9e492 100644
--- a/checkout.py
+++ b/checkout.py
@@ -22,6 +22,13 @@ import scm
import subprocess2
+# Default timeout of 15 minutes.
+GLOBAL_TIMEOUT = 15*60
+# Use a larger timeout for checkout since it can be a genuinely slower
+# operation.
+FETCH_TIMEOUT = 30*60
+
+
def get_code_review_setting(path, key,
codereview_settings_file='codereview.settings'):
"""Parses codereview.settings and return the value for the key if present.
@@ -197,7 +204,8 @@ class RawCheckout(CheckoutBase):
cmd,
stdin=p.get(False),
stderr=subprocess2.STDOUT,
- cwd=self.project_path))
+ cwd=self.project_path,
+ timeout=GLOBAL_TIMEOUT))
elif p.is_new and not os.path.exists(filepath):
# There is only a header. Just create the file.
open(filepath, 'w').close()
@@ -276,8 +284,10 @@ class SvnMixIn(object):
"""Runs svn and throws an exception if the command failed."""
kwargs.setdefault('cwd', self.project_path)
kwargs.setdefault('stdout', self.VOID)
+ kwargs.setdefault('timeout', GLOBAL_TIMEOUT)
return subprocess2.check_call_out(
- self._add_svn_flags(args, False), **kwargs)
+ self._add_svn_flags(args, False),
+ **kwargs)
def _check_output_svn(self, args, credentials=True, **kwargs):
"""Runs svn and throws an exception if the command failed.
@@ -288,6 +298,7 @@ class SvnMixIn(object):
return subprocess2.check_output(
self._add_svn_flags(args, True, credentials),
stderr=subprocess2.STDOUT,
+ timeout=GLOBAL_TIMEOUT,
**kwargs)
@staticmethod
@@ -387,7 +398,10 @@ class SvnCheckout(CheckoutBase, SvnMixIn):
]
stdout.append(
subprocess2.check_output(
- cmd, stdin=p.get(False), cwd=self.project_path))
+ cmd,
+ stdin=p.get(False),
+ cwd=self.project_path,
+ timeout=GLOBAL_TIMEOUT))
elif p.is_new and not os.path.exists(filepath):
# There is only a header. Just create the file if it doesn't
# exist.
@@ -483,11 +497,14 @@ class SvnCheckout(CheckoutBase, SvnMixIn):
logging.info(
'Directory %s is not present, checking it out.' % self.project_path)
self._check_call_svn(
- ['checkout', self.svn_url, self.project_path] + flags, cwd=None)
+ ['checkout', self.svn_url, self.project_path] + flags,
+ cwd=None,
+ timeout=FETCH_TIMEOUT)
Peter Mayo 2012/11/08 19:04:59 I would think checkout and update may be different
M-A Ruel 2012/11/08 19:07:57 I think it's fine. I'll change otherwise but I'm c
else:
+ # TODO(maruel): This command will shell out without a timeout.
scm.SVN.Revert(self.project_path, no_ignore=True)
# Revive files that were deleted in scm.SVN.Revert().
- self._check_call_svn(['update', '--force'] + flags)
+ self._check_call_svn(['update', '--force'] + flags, timeout=FETCH_TIMEOUT)
return self._get_revision()
def _get_revision(self):
@@ -537,8 +554,7 @@ class GitCheckoutBase(CheckoutBase):
try:
revision = self._check_output_git(['rev-parse', revision])
except subprocess.CalledProcessError:
- self._check_call_git(
- ['fetch', self.remote, self.remote_branch, '--quiet'])
+ self._fetch_remote()
revision = self._check_output_git(['rev-parse', revision])
self._check_call_git(['checkout', '--force', '--quiet', revision])
else:
@@ -649,18 +665,23 @@ class GitCheckoutBase(CheckoutBase):
def _check_call_git(self, args, **kwargs):
kwargs.setdefault('cwd', self.project_path)
kwargs.setdefault('stdout', self.VOID)
- return subprocess2.check_call_out(['git'] + args, **kwargs)
+ kwargs.setdefault('timeout', GLOBAL_TIMEOUT)
+ return subprocess2.check_call_out(
+ ['git'] + args, **kwargs)
def _call_git(self, args, **kwargs):
"""Like check_call but doesn't throw on failure."""
kwargs.setdefault('cwd', self.project_path)
kwargs.setdefault('stdout', self.VOID)
- return subprocess2.call(['git'] + args, **kwargs)
+ return subprocess2.call(['git'] + args, timeout=GLOBAL_TIMEOUT, **kwargs)
def _check_output_git(self, args, **kwargs):
kwargs.setdefault('cwd', self.project_path)
return subprocess2.check_output(
- ['git'] + args, stderr=subprocess2.STDOUT, **kwargs)
+ ['git'] + args,
+ stderr=subprocess2.STDOUT,
+ timeout=GLOBAL_TIMEOUT,
+ **kwargs)
def _branches(self):
"""Returns the list of branches and the active one."""
@@ -695,7 +716,9 @@ class GitCheckout(GitCheckoutBase):
"""Git checkout implementation."""
def _fetch_remote(self):
# git fetch is always verbose even with -q -q so redirect its output.
- self._check_output_git(['fetch', self.remote, self.remote_branch])
+ self._check_call_git(
+ ['fetch', self.remote, self.remote_branch, '--quiet'],
Peter Mayo 2012/11/08 19:04:59 Add quiet to CL description.
+ timeout=FETCH_TIMEOUT)
class ReadOnlyCheckout(object):
« 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