Created
March 15, 2016 14:22
-
-
Save acmisiti/184a607babab60f1c56a to your computer and use it in GitHub Desktop.
search_commits.py
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, sys | |
from time import mktime | |
from datetime import datetime | |
from git import Repo, InvalidGitRepositoryError | |
| |
MAX_COMMITS_TO_GO_BACK = 200 | |
BRANCH_TO_SEARCH = 'analytics-caching' | |
| |
def display_commit(current_commit, previous_commit): | |
changed_files = [] | |
try: | |
for x in current_commit.diff(previous_commit): | |
if x.a_blob.path not in changed_files: | |
changed_files.append(x.a_blob.path) | |
if x.b_blob is not None and x.b_blob.path not in changed_files: | |
changed_files.append(x.b_blob.path) | |
committed_date_str = datetime.fromtimestamp(current_commit.committed_date) | |
for f in changed_files: | |
print "{date}, {author}, {sha}, {file_name}".format( | |
date=committed_date_str, | |
author=current_commit.author.name, | |
file_name=f, | |
sha=current_commit.hexsha[0:12]) | |
except AttributeError, exp: | |
pass | |
| |
def serach_repo(q=None): | |
repo = Repo(os.path.dirname(os.path.realpath(__file__))) | |
commits_list = list(repo.iter_commits(BRANCH_TO_SEARCH, max_count=MAX_COMMITS_TO_GO_BACK)) | |
N = len(commits_list) | |
for i in range(N-1): | |
current_commit = commits_list[i] | |
previous_commit = commits_list[i+1] | |
display_commit(current_commit, previous_commit) | |
| |
| |
| |
| |
if __name__ == "__main__": | |
sys.exit(serach_repo()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment