Commit 3cdb7f36 authored by maruel@chromium.org's avatar maruel@chromium.org

Complete apply_issue.py.

This is to be able to apply patches directly from rietveld for the try server.

TEST=tested on both svn and git with binary files. unit tests will follow up.
R=dpranke@chromium.org
BUG=

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@84255 0039d316-1c4b-4281-b951-d872f2087c98
parent 2e64fa1d
......@@ -8,11 +8,15 @@
import logging
import optparse
import os
import sys
import breakpad # pylint: disable=W0611
import checkout
import fix_encoding
import rietveld
import scm
def main():
......@@ -26,12 +30,11 @@ def main():
parser.add_option(
'-r',
'--root_dir',
action='store',
default=os.getcwd(),
help='Root directory to apply the patch')
parser.add_option(
'-s',
'--server',
action='store',
default='http://codereview.chromium.org',
help='Rietveld server')
options, args = parser.parse_args()
......@@ -53,7 +56,21 @@ def main():
options.patchset = obj.get_issue_properties(
options.issue, False)['patchsets'][-1]
logging.info('Using patchset %d' % options.patchset)
obj.get_patch(options.issue, options.patchset)
# Download the patch.
patchset = obj.get_patch(options.issue, options.patchset)
scm_type = scm.determine_scm(options.root_dir)
if scm_type == 'svn':
scm_obj = checkout.SvnCheckout(options.root_dir, None, None, None, None)
elif scm_type == 'git':
scm_obj = checkout.GitCheckoutBase(options.root_dir, None, None)
elif scm_type == None:
scm_obj = checkout.RawCheckout(options.root_dir, None)
else:
parser.error('Couldn\'t determine the scm')
# Apply the patch.
scm_obj.apply_patch(patchset)
return 0
......
......@@ -62,11 +62,13 @@ class CheckoutBase(object):
def __init__(self, root_dir, project_name):
self.root_dir = root_dir
self.project_name = project_name
self.project_path = os.path.join(self.root_dir, self.project_name)
if self.project_name is None:
self.project_path = self.root_dir
else:
self.project_path = os.path.join(self.root_dir, self.project_name)
# Only used for logging purposes.
self._last_seen_revision = None
assert self.root_dir
assert self.project_name
assert self.project_path
def get_settings(self, key):
......@@ -229,10 +231,10 @@ class SvnCheckout(CheckoutBase, SvnMixIn):
self.commit_pwd = commit_pwd
self.svn_url = svn_url
assert bool(self.commit_user) >= bool(self.commit_pwd)
assert self.svn_url
def prepare(self):
# Will checkout if the directory is not present.
assert self.svn_url
if not os.path.isdir(self.project_path):
logging.info('Checking out %s in %s' %
(self.project_name, self.project_path))
......@@ -346,13 +348,13 @@ class GitCheckoutBase(CheckoutBase):
self.remote = 'origin'
self.remote_branch = remote_branch
self.working_branch = 'working_branch'
assert self.remote_branch
def prepare(self):
"""Resets the git repository in a clean state.
Checks it out if not present and deletes the working branch.
"""
assert self.remote_branch
assert os.path.isdir(self.project_path)
self._check_call_git(['reset', '--hard', '--quiet'])
branches, active = self._branches()
......@@ -372,9 +374,10 @@ class GitCheckoutBase(CheckoutBase):
post_processor = post_processor or []
# It this throws, the checkout is corrupted. Maybe worth deleting it and
# trying again?
self._check_call_git(
['checkout', '-b', self.working_branch,
'%s/%s' % (self.remote, self.remote_branch), '--quiet'])
if self.remote_branch:
self._check_call_git(
['checkout', '-b', self.working_branch,
'%s/%s' % (self.remote, self.remote_branch), '--quiet'])
for p in patches:
try:
stdout = ''
......
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