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

Unified Diff: checkout.py

Issue 10391033: Improve error message in patch application failure. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Created 8 years, 7 months 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 | « apply_issue.py ('k') | 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 fa732e8c77fc19d4313e9c713dba3bf55f540cb8..2260ab3480f8b9a738b9fe67247e59cd6a6d37e8 100644
--- a/checkout.py
+++ b/checkout.py
@@ -49,11 +49,24 @@ def get_code_review_setting(path, key,
class PatchApplicationFailed(Exception):
"""Patch failed to be applied."""
- def __init__(self, filename, status):
- super(PatchApplicationFailed, self).__init__(filename, status)
- self.filename = filename
+ def __init__(self, p, status):
+ super(PatchApplicationFailed, self).__init__(p, status)
+ self.patch = p
self.status = status
+ @property
+ def filename(self):
+ if self.patch:
+ return self.patch.filename
+
+ def __str__(self):
+ out = []
+ if self.filename:
+ out.append('Failed to apply patch for %s:' % self.filename)
+ if self.status:
+ out.append(self.status)
+ return '\n'.join(out)
+
class CheckoutBase(object):
# Set to None to have verbose output.
@@ -140,12 +153,12 @@ class RawCheckout(CheckoutBase):
if p.source_filename:
if not p.is_new:
raise PatchApplicationFailed(
- p.filename,
+ p,
'File has a source filename specified but is not new')
# Copy the file first.
if os.path.isfile(filepath):
raise PatchApplicationFailed(
- p.filename, 'File exist but was about to be overwriten')
+ p, 'File exist but was about to be overwriten')
shutil.copy2(
os.path.join(self.project_path, p.source_filename), filepath)
if p.diff_hunks:
@@ -160,10 +173,10 @@ class RawCheckout(CheckoutBase):
for post in post_processors:
post(self, p)
except OSError, e:
- raise PatchApplicationFailed(p.filename, '%s%s' % (stdout, e))
+ raise PatchApplicationFailed(p, '%s%s' % (stdout, e))
except subprocess.CalledProcessError, e:
raise PatchApplicationFailed(
- p.filename, '%s%s' % (stdout, getattr(e, 'stdout', None)))
+ p, '%s%s' % (stdout, getattr(e, 'stdout', None)))
def commit(self, commit_message, user):
"""Stubbed out."""
@@ -307,12 +320,12 @@ class SvnCheckout(CheckoutBase, SvnMixIn):
if p.source_filename:
if not p.is_new:
raise PatchApplicationFailed(
- p.filename,
+ p,
'File has a source filename specified but is not new')
# Copy the file first.
if os.path.isfile(filepath):
raise PatchApplicationFailed(
- p.filename, 'File exist but was about to be overwriten')
+ p, 'File exist but was about to be overwriten')
self._check_output_svn(
[
'copy',
@@ -347,10 +360,10 @@ class SvnCheckout(CheckoutBase, SvnMixIn):
for post in post_processors:
post(self, p)
except OSError, e:
- raise PatchApplicationFailed(p.filename, '%s%s' % (stdout, e))
+ raise PatchApplicationFailed(p, '%s%s' % (stdout, e))
except subprocess.CalledProcessError, e:
raise PatchApplicationFailed(
- p.filename,
+ p,
'While running %s;\n%s%s' % (
' '.join(e.cmd), stdout, getattr(e, 'stdout', '')))
@@ -503,10 +516,10 @@ class GitCheckoutBase(CheckoutBase):
for post in post_processors:
post(self, p)
except OSError, e:
- raise PatchApplicationFailed(p.filename, '%s%s' % (stdout, e))
+ raise PatchApplicationFailed(p, '%s%s' % (stdout, e))
except subprocess.CalledProcessError, e:
raise PatchApplicationFailed(
- p.filename, '%s%s' % (stdout, getattr(e, 'stdout', None)))
+ p, '%s%s' % (stdout, getattr(e, 'stdout', None)))
# Once all the patches are processed and added to the index, commit the
# index.
self._check_call_git(['commit', '-m', 'Committed patch'])
« no previous file with comments | « apply_issue.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698