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

Unified Diff: git_drover.py

Issue 2067653002: drover win: Use --stdin so update-index doesn't fail on long cmdline (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: fix mocky methods Created 4 years, 6 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 | « no previous file | tests/git_drover_test.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: git_drover.py
diff --git a/git_drover.py b/git_drover.py
index ad6d0e13c745b7dc3e1e0c1983c52ac8339f84ef..c9a4af31527e3299d346f6fe724866f0c96c4d8c 100755
--- a/git_drover.py
+++ b/git_drover.py
@@ -265,8 +265,9 @@ class _Drover(object):
repo_status = self._run_git_command(['status', '--porcelain']).splitlines()
extra_files = [f[3:] for f in repo_status if f[:2] == ' D']
if extra_files:
- self._run_git_command(['update-index', '--skip-worktree', '--'] +
- extra_files)
+ self._run_git_command_with_stdin(
+ ['update-index', '--skip-worktree', '--stdin'],
+ stdin='\n'.join(extra_files) + '\n')
def _upload_and_land(self):
if self._dry_run:
@@ -314,6 +315,32 @@ class _Drover(object):
else:
raise Error('Command %r failed: %s' % (' '.join(args), e))
+ def _run_git_command_with_stdin(self, args, stdin):
+ """Runs a git command with a provided stdin.
+
+ Args:
+ args: A list of strings containing the args to pass to git.
+ stdin: A string to provide on stdin.
+
+ Raises:
+ Error: The command failed to complete successfully.
+ """
+ cwd = self._workdir if self._workdir else self._parent_repo
+ logging.debug('Running git %s (cwd %r)', ' '.join('%s' % arg
+ for arg in args), cwd)
+
+ # Discard stderr unless verbose is enabled.
+ stderr = None if self._verbose else _DEV_NULL_FILE
+
+ try:
+ popen = subprocess.Popen(['git'] + args, shell=False, cwd=cwd,
+ stderr=stderr, stdin=subprocess.PIPE)
+ popen.communicate(stdin)
+ if popen.returncode != 0:
+ raise Error('Command %r failed' % ' '.join(args))
+ except OSError as e:
+ raise Error('Command %r failed: %s' % (' '.join(args), e))
+
def cherry_pick_change(branch, revision, parent_repo, dry_run, verbose=False):
"""Cherry-picks a change into a branch.
« no previous file with comments | « no previous file | tests/git_drover_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698