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

Unified Diff: checkout.py

Issue 7054057: Add support for empty files, __init__.py is a common example. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Created 9 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') | rietveld.py » ('j') | 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 a5cf5801f1a8251e1b26f971c7a2dbfb1ba6a486..21c283e8cbd4e3860f8a52fbe01f2e7bcbc9ea1f 100644
--- a/checkout.py
+++ b/checkout.py
@@ -127,10 +127,14 @@ class RawCheckout(CheckoutBase):
with open(os.path.join(filename), 'wb') as f:
f.write(p.get())
else:
- stdout = subprocess2.check_output(
- ['patch', '-p%s' % p.patchlevel],
- stdin=p.get(),
- cwd=self.project_path)
+ if p.diff_hunks:
+ stdout = subprocess2.check_output(
+ ['patch', '-p%s' % p.patchlevel],
+ stdin=p.get(),
+ cwd=self.project_path)
+ elif p.is_new:
+ # There is only a header. Just create the file.
+ open(os.path.join(self.project_path, p.filename), 'w').close()
for post in post_processor:
post(self, p)
except OSError, e:
@@ -258,8 +262,6 @@ class SvnCheckout(CheckoutBase, SvnMixIn):
stdout += self._check_output_svn(
['delete', p.filename, '--force'], credentials=False)
else:
- new = not os.path.exists(p.filename)
-
# svn add while creating directories otherwise svn add on the
# contained files will silently fail.
# First, find the root directory that exists.
@@ -278,10 +280,14 @@ class SvnCheckout(CheckoutBase, SvnMixIn):
with open(os.path.join(self.project_path, p.filename), 'wb') as f:
f.write(p.get())
else:
- cmd = ['patch', '-p%s' % p.patchlevel, '--forward', '--force']
- stdout += subprocess2.check_output(
- cmd, stdin=p.get(), cwd=self.project_path)
- if new:
+ if p.diff_hunks:
+ cmd = ['patch', '-p%s' % p.patchlevel, '--forward', '--force']
+ stdout += subprocess2.check_output(
+ cmd, stdin=p.get(), cwd=self.project_path)
+ elif p.is_new:
+ # There is only a header. Just create the file.
+ open(os.path.join(self.project_path, p.filename), 'w').close()
+ if p.is_new:
stdout += self._check_output_svn(
['add', p.filename, '--force'], credentials=False)
for prop in p.svn_properties:
@@ -410,6 +416,8 @@ class GitCheckoutBase(CheckoutBase):
f.write(p.get())
stdout += self._check_output_git(['add', p.filename])
else:
+ # No need to do anything special with p.is_new or if not
+ # p.diff_hunks. git apply manages all that already.
stdout += self._check_output_git(
['apply', '--index', '-p%s' % p.patchlevel], stdin=p.get())
for prop in p.svn_properties:
« no previous file with comments | « apply_issue.py ('k') | rietveld.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698