소스 검색

Use core.quotePath=false for more git diffs

This includes a minor refactor so that some gclient_scm methods
can all share the same core.quotePath specifier.

R=iannucci

Bug: 792302
Change-Id: Iaadf190f5c0666787cf7c2ccda88d6dba9aace9b
Reviewed-on: https://chromium-review.googlesource.com/823131
Reviewed-by: Robbie Iannucci <iannucci@chromium.org>
Commit-Queue: Aaron Gable <agable@chromium.org>
Aaron Gable 7 년 전
부모
커밋
f4068aa3ea
6개의 변경된 파일26개의 추가작업 그리고 17개의 파일을 삭제
  1. 1 1
      checkout.py
  2. 15 10
      gclient_scm.py
  3. 2 1
      git_cl.py
  4. 2 1
      git_upstream_diff.py
  5. 4 2
      scm.py
  6. 2 2
      tests/gclient_scm_test.py

+ 1 - 1
checkout.py

@@ -301,7 +301,7 @@ class GitCheckout(CheckoutBase):
     if errors:
       raise PatchApplicationFailed(errors, verbose)
     found_files = self._check_output_git(
-        ['diff', '--ignore-submodules',
+        ['-c', 'core.quotePath=false', 'diff', '--ignore-submodules',
          '--name-only', '--staged']).splitlines(False)
     if sorted(patches.filenames) != sorted(found_files):
       extra_files = sorted(set(found_files) - set(patches.filenames))

+ 15 - 10
gclient_scm.py

@@ -270,12 +270,19 @@ class GitWrapper(SCMWrapper):
     # time-stamp of the currently checked out revision.
     return self._Capture(['log', '-n', '1', '--format=%ai'])
 
+  def _GetDiffFilenames(self, base):
+    """Returns the names of files modified since base."""
+    return self._Capture(
+      # Filter to remove base if it is None.
+      filter(bool, ['-c', 'core.quotePath=false', 'diff', '--name-only', base])
+    ).split()
+
   def diff(self, options, _args, _file_list):
     try:
       merge_base = [self._Capture(['merge-base', 'HEAD', self.remote])]
     except subprocess2.CalledProcessError:
       merge_base = []
-    self._Run(['diff'] + merge_base, options)
+    self._Run(['-c', 'core.quotePath=false', 'diff'] + merge_base, options)
 
   def pack(self, _options, _args, _file_list):
     """Generates a patch file which can be applied to the root of the
@@ -360,7 +367,6 @@ class GitWrapper(SCMWrapper):
               self.Print('FAILED to break lock: %s: %s' % (to_break, ex))
               raise
 
-
   def update(self, options, args, file_list):
     """Runs git to update or transparently checkout the working copy.
 
@@ -628,8 +634,7 @@ class GitWrapper(SCMWrapper):
         raise gclient_utils.Error(switch_error)
     else:
       # case 3 - the default case
-      rebase_files = self._Capture(
-          ['diff', upstream_branch, '--name-only']).split()
+      rebase_files = self._GetDiffFilenames(upstream_branch)
       if verbose:
         self.Print('Trying fast-forward merge to branch : %s' % upstream_branch)
       try:
@@ -733,7 +738,6 @@ class GitWrapper(SCMWrapper):
 
     return self._Capture(['rev-parse', '--verify', 'HEAD'])
 
-
   def revert(self, options, _args, file_list):
     """Reverts local modifications.
 
@@ -767,7 +771,7 @@ class GitWrapper(SCMWrapper):
       return self.update(options, [], file_list)
 
     if file_list is not None:
-      files = self._Capture(['diff', deps_revision, '--name-only']).split()
+      files = self._GetDiffFilenames(deps_revision)
 
     self._Scrub(deps_revision, options)
     self._Run(['clean', '-f', '-d'], options)
@@ -792,10 +796,11 @@ class GitWrapper(SCMWrapper):
         merge_base = [self._Capture(['merge-base', 'HEAD', self.remote])]
       except subprocess2.CalledProcessError:
         merge_base = []
-      self._Run(['diff', '--name-status'] + merge_base, options,
-                stdout=self.out_fh, always=options.verbose)
+      self._Run(
+          ['-c', 'core.quotePath=false', 'diff', '--name-status'] + merge_base,
+          options, stdout=self.out_fh, always=options.verbose)
       if file_list is not None:
-        files = self._Capture(['diff', '--name-only'] + merge_base).split()
+        files = self._GetDiffFilenames(merge_base[0] if merge_base else None)
         file_list.extend([os.path.join(self.checkout_path, f) for f in files])
 
   def GetUsableRev(self, rev, options):
@@ -960,7 +965,7 @@ class GitWrapper(SCMWrapper):
                      branch=None, printed_path=False, merge=False):
     """Attempt to rebase onto either upstream or, if specified, newbase."""
     if files is not None:
-      files.extend(self._Capture(['diff', upstream, '--name-only']).split())
+      files.extend(self._GetDiffFilenames(upstream))
     revision = upstream
     if newbase:
       revision = newbase

+ 2 - 1
git_cl.py

@@ -5885,7 +5885,8 @@ def CMDowners(parser, args):
 def BuildGitDiffCmd(diff_type, upstream_commit, args):
   """Generates a diff command."""
   # Generate diff for the current branch's changes.
-  diff_cmd = ['diff', '--no-ext-diff', '--no-prefix', diff_type,
+  diff_cmd = ['-c', 'core.quotePath=false', 'diff',
+              '--no-ext-diff', '--no-prefix', diff_type,
               upstream_commit, '--']
 
   if args:

+ 2 - 1
git_upstream_diff.py

@@ -34,7 +34,8 @@ def main(args):
     print 'fatal: No upstream configured for branch \'%s\'' % opts.branch
     return 1
 
-  cmd = [git.GIT_EXE, 'diff', '--patience', '-C', '-C']
+  cmd = [git.GIT_EXE, '-c', 'core.quotePath=false',
+         'diff', '--patience', '-C', '-C']
   if opts.wordwise:
     cmd += ['--word-diff=color', r'--word-diff-regex=(\w+|[^[:space:]])']
   cmd += [git.get_or_create_merge_base(opts.branch, par)]

+ 4 - 2
scm.py

@@ -277,7 +277,8 @@ class GIT(object):
     files, usually in the prospect to apply the patch for a try job."""
     if not branch:
       branch = GIT.GetUpstreamBranch(cwd)
-    command = ['diff', '-p', '--no-color', '--no-prefix', '--no-ext-diff',
+    command = ['-c', 'core.quotePath=false', 'diff',
+               '-p', '--no-color', '--no-prefix', '--no-ext-diff',
                branch + "..." + branch_head]
     if full_move:
       command.append('--no-renames')
@@ -300,7 +301,8 @@ class GIT(object):
     """Returns the list of modified files between two branches."""
     if not branch:
       branch = GIT.GetUpstreamBranch(cwd)
-    command = ['diff', '--name-only', branch + "..." + branch_head]
+    command = ['-c', 'core.quotePath=false', 'diff',
+               '--name-only', branch + "..." + branch_head]
     return GIT.Capture(command, cwd=cwd).splitlines(False)
 
   @staticmethod

+ 2 - 2
tests/gclient_scm_test.py

@@ -340,7 +340,7 @@ class ManagedGitWrapperTestCase(BaseGitWrapperTestCase):
     scm.status(options, self.args, file_list)
     self.assertEquals(file_list, [file_path])
     self.checkstdout(
-        ('\n________ running \'git diff --name-status '
+        ('\n________ running \'git -c core.quotePath=false diff --name-status '
          '069c602044c5388d2d15c3f875b057c852003458\' in \'%s\'\nM\ta\n') %
             join(self.root_dir, '.'))
 
@@ -360,7 +360,7 @@ class ManagedGitWrapperTestCase(BaseGitWrapperTestCase):
     expected_file_list = [join(self.base_path, x) for x in ['a', 'b']]
     self.assertEquals(sorted(file_list), expected_file_list)
     self.checkstdout(
-        ('\n________ running \'git diff --name-status '
+        ('\n________ running \'git -c core.quotePath=false diff --name-status '
          '069c602044c5388d2d15c3f875b057c852003458\' in \'%s\'\nM\ta\nM\tb\n') %
             join(self.root_dir, '.'))