Bug 1387035 - Update clang-format methods to use mozversioncontrol for hg/git detection r?sylvestre,gps draft
authorXavier ALT <dex@phoenix-ind.net>
Tue, 15 Aug 2017 23:23:30 +0200
changeset 647625 46b04b2e7c7a
parent 647624 07ce8c96222d
child 726580 8e0f51b9fac8
push id74485
push userbmo:dex@phoenix-ind.net
push dateWed, 16 Aug 2017 17:42:46 +0000
reviewerssylvestre, gps
bugs1387035
milestone57.0a1
Bug 1387035 - Update clang-format methods to use mozversioncontrol for hg/git detection r?sylvestre,gps MozReview-Commit-ID: IZTPYtTxuKu
tools/mach_commands.py
--- a/tools/mach_commands.py
+++ b/tools/mach_commands.py
@@ -12,16 +12,17 @@ import errno
 
 from mach.decorators import (
     CommandArgument,
     CommandProvider,
     Command,
 )
 
 from mozbuild.base import MachCommandBase, MozbuildObject
+import mozversioncontrol
 
 
 @CommandProvider
 class SearchProvider(object):
     @Command('dxr', category='misc',
              description='Search for something in DXR.')
     @CommandArgument('term', nargs='+', help='Term(s) to search for.')
     def dxr(self, term):
@@ -256,17 +257,17 @@ class FormatProvider(MachCommandBase):
             os.rename(temp, target)
         return target
 
     def run_clang_format_diff(self, clang_format_diff, show):
         # Run clang-format on the diff
         # Note that this will potentially miss a lot things
         from subprocess import Popen, PIPE
 
-        if os.path.exists(".hg"):
+        if isinstance(self.repository, mozversioncontrol.HgRepository):
             diff_process = Popen(["hg", "diff", "-U0", "-r", ".^",
                                   "--include", "glob:**.c", "--include", "glob:**.cpp",
                                   "--include", "glob:**.h",
                                   "--exclude", "listfile:.clang-format-ignore"], stdout=PIPE)
         else:
 	    diff_process = Popen(["git", "diff", "--no-color", "-U0", "HEAD","--","*.c","*.cpp","*.h"], stdout=PIPE)
         args = [sys.executable, clang_format_diff, "-p1"]
         if not show:
@@ -318,17 +319,17 @@ class FormatProvider(MachCommandBase):
             return
 
         args += path_list
 
         # Run clang-format
         cf_process = Popen(args)
         if show:
             # show the diff
-            if os.path.exists(".hg"):
+            if isinstance(self.repository, mozversioncontrol.HgRepository):
                 cf_process = Popen(["hg", "diff"] + path_list)
             else:
                 cf_process = Popen(["git", "diff"] + path_list)
         return cf_process.communicate()[0]
 
 
 def mozregression_import():
     # Lazy loading of mozregression.