Bug 1393242 - Use hglib for get_files_in_working_directory(); r?mshal draft
authorGregory Szorc <gps@mozilla.com>
Wed, 23 Aug 2017 15:21:16 -0700
changeset 657536 be93678e693d1fa9f36433fac50ba8d5ad9b55bd
parent 657535 78e75f2d7e7ea6c7d18099d3654030d901783124
child 729456 b1c6f81aca726f8a39465c5d7d77ef6d92e88e71
push id77552
push usergszorc@mozilla.com
push dateFri, 01 Sep 2017 16:20:16 +0000
reviewersmshal
bugs1393242
milestone57.0a1
Bug 1393242 - Use hglib for get_files_in_working_directory(); r?mshal And convert consumers to context managers because hglib requires that. MozReview-Commit-ID: Ckf1yBYeUlm
config/check_js_msg_encoding.py
config/check_macroassembler_style.py
config/check_spidermonkey_style.py
python/mozversioncontrol/mozversioncontrol/__init__.py
--- a/config/check_js_msg_encoding.py
+++ b/config/check_js_msg_encoding.py
@@ -42,24 +42,24 @@ def check_single_file(filename):
             log_fail(filename, 'not in {} encoding'.format(expected_encoding))
 
     log_pass(filename, 'ok')
     return True
 
 def check_files():
     result = True
 
-    repo = get_repository_from_env()
-    root = repo.path
+    with get_repository_from_env() as repo:
+        root = repo.path
 
-    for filename in repo.get_files_in_working_directory():
-        if filename.endswith('.msg'):
-            if filename not in ignore_files:
-                if not check_single_file(os.path.join(root, filename)):
-                    result = False
+        for filename in repo.get_files_in_working_directory():
+            if filename.endswith('.msg'):
+                if filename not in ignore_files:
+                    if not check_single_file(os.path.join(root, filename)):
+                        result = False
 
     return result
 
 def main():
     if not check_files():
         sys.exit(1)
 
     sys.exit(0)
--- a/config/check_macroassembler_style.py
+++ b/config/check_macroassembler_style.py
@@ -237,31 +237,30 @@ def generate_file_content(signatures):
 
 def check_style():
     # We read from the header file the signature of each function.
     decls = dict()      # type: dict(signature => ['x86', 'x64'])
 
     # We infer from each file the signature of each MacroAssembler function.
     defs = dict()       # type: dict(signature => ['x86', 'x64'])
 
-    repo = get_repository_from_env()
+    with get_repository_from_env() as repo:
+        # Select the appropriate files.
+        for filename in repo.get_files_in_working_directory():
+            if not filename.startswith('js/src/jit/'):
+                continue
+            if 'MacroAssembler' not in filename:
+                continue
 
-    # Select the appropriate files.
-    for filename in repo.get_files_in_working_directory():
-        if not filename.startswith('js/src/jit/'):
-            continue
-        if 'MacroAssembler' not in filename:
-            continue
+            filename = os.path.join(repo.path, filename)
 
-        filename = os.path.join(repo.path, filename)
-
-        if filename.endswith('MacroAssembler.h'):
-            decls = append_signatures(decls, get_macroassembler_declaration(filename))
-        else:
-            defs = append_signatures(defs, get_macroassembler_definitions(filename))
+            if filename.endswith('MacroAssembler.h'):
+                decls = append_signatures(decls, get_macroassembler_declaration(filename))
+            else:
+                defs = append_signatures(defs, get_macroassembler_definitions(filename))
 
     # Compare declarations and definitions output.
     difflines = difflib.unified_diff(generate_file_content(decls),
                                      generate_file_content(defs),
                                      fromfile='check_macroassembler_style.py declared syntax',
                                      tofile='check_macroassembler_style.py found definitions')
     ok = True
     for diffline in difflines:
--- a/config/check_spidermonkey_style.py
+++ b/config/check_spidermonkey_style.py
@@ -244,34 +244,33 @@ def check_style():
     # - "js/src/vm/String.h"        -> "vm/String.h"
 
     non_js_dirnames = ('mfbt/',
                        'memory/mozalloc/',
                        'mozglue/')  # type: tuple(str)
     non_js_inclnames = set()        # type: set(inclname)
     js_names = dict()               # type: dict(filename, inclname)
 
-    repo = get_repository_from_env()
-
-    # Select the appropriate files.
-    for filename in repo.get_files_in_working_directory():
-        for non_js_dir in non_js_dirnames:
-            if filename.startswith(non_js_dir) and filename.endswith('.h'):
-                inclname = 'mozilla/' + filename.split('/')[-1]
-                non_js_inclnames.add(inclname)
+    with get_repository_from_env() as repo:
+        # Select the appropriate files.
+        for filename in repo.get_files_in_working_directory():
+            for non_js_dir in non_js_dirnames:
+                if filename.startswith(non_js_dir) and filename.endswith('.h'):
+                    inclname = 'mozilla/' + filename.split('/')[-1]
+                    non_js_inclnames.add(inclname)
 
-        if filename.startswith('js/public/') and filename.endswith('.h'):
-            inclname = 'js/' + filename[len('js/public/'):]
-            js_names[filename] = inclname
+            if filename.startswith('js/public/') and filename.endswith('.h'):
+                inclname = 'js/' + filename[len('js/public/'):]
+                js_names[filename] = inclname
 
-        if filename.startswith('js/src/') and \
-           not filename.startswith(tuple(ignored_js_src_dirs)) and \
-           filename.endswith(('.c', '.cpp', '.h', '.tbl', '.msg')):
-            inclname = filename[len('js/src/'):]
-            js_names[filename] = inclname
+            if filename.startswith('js/src/') and \
+               not filename.startswith(tuple(ignored_js_src_dirs)) and \
+               filename.endswith(('.c', '.cpp', '.h', '.tbl', '.msg')):
+                inclname = filename[len('js/src/'):]
+                js_names[filename] = inclname
 
     all_inclnames = non_js_inclnames | set(js_names.values())
 
     edges = dict()      # type: dict(inclname, set(inclname))
 
     # We don't care what's inside the MFBT and MOZALLOC files, but because they
     # are #included from JS files we have to add them to the inclusion graph.
     for inclname in non_js_inclnames:
--- a/python/mozversioncontrol/mozversioncontrol/__init__.py
+++ b/python/mozversioncontrol/mozversioncontrol/__init__.py
@@ -199,17 +199,18 @@ class HgRepository(Repository):
         self._run(*args)
 
     def forget_add_remove_files(self, path):
         self._run('forget', path)
 
     def get_files_in_working_directory(self):
         # Can return backslashes on Windows. Normalize to forward slashes.
         return list(p.replace('\\', '/') for p in
-                    self._run('files', '-0').split('\0'))
+                    self._run_in_client([b'files', b'-0']).split(b'\0')
+                    if p)
 
 
 class GitRepository(Repository):
     '''An implementation of `Repository` for Git repositories.'''
     def __init__(self, path, git='git'):
         super(GitRepository, self).__init__(path, tool=git)
 
     @property
@@ -228,17 +229,17 @@ class GitRepository(Repository):
 
     def add_remove_files(self, path):
         self._run('add', path)
 
     def forget_add_remove_files(self, path):
         self._run('reset', path)
 
     def get_files_in_working_directory(self):
-        return self._run('ls-files', '-z').split('\0')
+        return self._run('ls-files', '-z').split(b'\0')
 
 
 class InvalidRepoPath(Exception):
     """Represents a failure to find a VCS repo at a specified path."""
 
 
 def get_repository_object(path, hg='hg', git='git'):
     '''Get a repository object for the repository at `path`.