From 49e3d807fd22521b9e5c6e40fe51bcf8f9d95e35 Mon Sep 17 00:00:00 2001 From: "maruel@chromium.org" Date: Wed, 18 Jul 2012 23:54:45 +0000 Subject: [PATCH] Fix stats output to be always the same and coherent with what is committed. git cl dcommit statistics were not using --find-copies-harder, scaring the user off. R=cmp@chromium.org BUG= TEST= Review URL: https://chromiumcodereview.appspot.com/10795003 git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@147343 0039d316-1c4b-4281-b951-d872f2087c98 --- git_cl.py | 26 +++++++++++++++----------- tests/git_cl_test.py | 4 ++-- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/git_cl.py b/git_cl.py index 5bd6d1be4..fa7007bd2 100755 --- a/git_cl.py +++ b/git_cl.py @@ -135,6 +135,19 @@ def MatchSvnGlob(url, base_url, glob_spec, allow_wildcards): return None +def print_stats(args): + """Prints statistics about the change to the user.""" + # --no-ext-diff is broken in some versions of Git, so try to work around + # this by overriding the environment (but there is still a problem if the + # git config key "diff.external" is used). + env = os.environ.copy() + if 'GIT_EXTERNAL_DIFF' in env: + del env['GIT_EXTERNAL_DIFF'] + return subprocess2.call( + ['git', 'diff', '--no-ext-diff', '--stat', '--find-copies-harder'] + args, + env=env) + + class Settings(object): def __init__(self): self.default_server = None @@ -1126,16 +1139,7 @@ def CMDupload(parser, args): if not options.reviewers and hook_results.reviewers: options.reviewers = hook_results.reviewers - # --no-ext-diff is broken in some versions of Git, so try to work around - # this by overriding the environment (but there is still a problem if the - # git config key "diff.external" is used). - env = os.environ.copy() - if 'GIT_EXTERNAL_DIFF' in env: - del env['GIT_EXTERNAL_DIFF'] - subprocess2.call( - ['git', 'diff', '--no-ext-diff', '--stat', '--find-copies-harder'] + args, - env=env) - + print_stats(args) if settings.GetIsGerrit(): return GerritUpload(options, args, cl) return RietveldUpload(options, args, cl) @@ -1265,7 +1269,7 @@ def SendUpstream(parser, args, cmd): branches = [base_branch, cl.GetBranchRef()] if not options.force: - subprocess2.call(['git', 'diff', '--stat'] + branches) + print_stats(branches) ask_for_data('About to commit; enter to confirm.') # We want to squash all this branch's commits into one commit with the proper diff --git a/tests/git_cl_test.py b/tests/git_cl_test.py index 7e9014084..5ae17f914 100755 --- a/tests/git_cl_test.py +++ b/tests/git_cl_test.py @@ -192,8 +192,8 @@ class TestGitCl(TestCase): @classmethod def _dcommit_calls_3(cls): return [ - ((['git', 'diff', '--stat', 'refs/remotes/origin/master', - 'refs/heads/working'],), + ((['git', 'diff', '--no-ext-diff', '--stat', '--find-copies-harder', + 'refs/remotes/origin/master', 'refs/heads/working'],), (' PRESUBMIT.py | 2 +-\n' ' 1 files changed, 1 insertions(+), 1 deletions(-)\n')), (('About to commit; enter to confirm.',), None),