Last active
August 29, 2015 14:00
-
-
Save sangheestyle/11187957 to your computer and use it in GitHub Desktop.
git filter among repos
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
from subprocess import check_output, CalledProcessError | |
def get_repo_paths(root=None): | |
repo_paths = [] | |
for dir, _, _ in os.walk(root): | |
if dir.endswith('/.git'): | |
repo_paths.append(dir[:-5]) | |
return repo_paths | |
def get_commit_ids_by_permission(repo_path=None, permission=None): | |
if permission is None: | |
permission = '.*' | |
current_path = os.getcwd() | |
os.chdir(repo_path) | |
template_git_command = ["git", "log", "--pretty=format:%h"] | |
permission_rex = "<.*uses-permission.*\." + permission + ".*/>" | |
template_permission = ["-G", permission_rex] | |
template_path = ["--", "*AndroidManifest.xml"] | |
command = [] | |
command.extend(template_git_command) | |
command.extend(template_permission) | |
command.extend(template_path) | |
output = check_output(command) | |
try: | |
output = check_output(command) | |
except CalledProcessError: | |
commit_ids = [] | |
os.chdir(current_path) | |
commit_ids = output.split() | |
return commit_ids | |
root = '../repo' | |
for repo_path in get_repo_paths(root): | |
print ">>>", repo_path | |
print len(get_commit_ids_by_permission(repo_path)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The following result represent that `../repo/github/android' repo has 10 commits related to all permisissions in all AndroidManifest.xml.
FIXME:
However, some repositories make
fatal
error due to no head which means that the repository is not well formed. I can't handle that kind of error even I used try and except.