1# Copyright 2014, VIXL authors 2# All rights reserved. 3# 4# Redistribution and use in source and binary forms, with or without 5# modification, are permitted provided that the following conditions are met: 6# 7# * Redistributions of source code must retain the above copyright notice, 8# this list of conditions and the following disclaimer. 9# * Redistributions in binary form must reproduce the above copyright notice, 10# this list of conditions and the following disclaimer in the documentation 11# and/or other materials provided with the distribution. 12# * Neither the name of ARM Limited nor the names of its contributors may be 13# used to endorse or promote products derived from this software without 14# specific prior written permission. 15# 16# THIS SOFTWARE IS PROVIDED BY ARM LIMITED AND CONTRIBUTORS "AS IS" AND ANY 17# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19# DISCLAIMED. IN NO EVENT SHALL ARM LIMITED BE LIABLE FOR ANY DIRECT, INDIRECT, 20# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 22# OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 23# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 24# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 25# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 27import re 28import util 29import os.path 30from pipes import quote 31 32def is_git_repository_root(path): 33 command = 'git -C ' + quote(path) + ' rev-parse --show-toplevel' 34 status, toplevel = util.getstatusoutput(command) 35 if status != 0: return False 36 return os.path.samefile(toplevel, path) 37 38def get_tracked_files(): 39 command = 'git ls-tree HEAD -r --full-tree --name-only' 40 41 status, tracked = util.getstatusoutput(command) 42 if status != 0: util.abort('Failed to list tracked files.') 43 44 return tracked 45 46 47# Get untracked files in src/, test/, and tools/. 48def get_untracked_files(): 49 status, output = util.getstatusoutput('git status -s') 50 if status != 0: util.abort('Failed to get git status.') 51 52 untracked_regexp = re.compile('\?\?.*(src/|test/|tools/).*(.cc$|.h$)') 53 files_in_watched_folder = lambda n: untracked_regexp.search(n) != None 54 untracked_files = filter(files_in_watched_folder, output.split('\n')) 55 56 return untracked_files 57