Skip to content

Instantly share code, notes, and snippets.

@Jd007
Created April 23, 2013 19:09
Show Gist options
  • Save Jd007/5446475 to your computer and use it in GitHub Desktop.
Save Jd007/5446475 to your computer and use it in GitHub Desktop.
Gitlog extraction
def extract_git_log_by_hashes(hash_file_path, raw_log_path, output_file_path):
f = open(hash_file_path, 'r')
hashes = []
for h in f:
hashes.append(str(h).strip())
f.close()
raw_log_file = open(raw_log_path, 'r')
processed_data = {}
is_in_block = False
current_block_text = ''
current_hash = ''
for line in raw_log_file:
if not is_in_block:
for h in hashes:
start_trigger = 'commit ' + h
if start_trigger in str(line):
current_block_text += line
current_hash = h
is_in_block = True
break
else:
current_block_text += line
if 'file' in line and 'changed' in line and ('insertion' in line or 'deletion' in line):
processed_data[current_hash] = current_block_text
current_block_text = ''
current_hash = ''
is_in_block = False
raw_log_file.close()
log_file = open(output_file_path, 'w')
for h in hashes:
log_file.write(processed_data.get(h, ''))
log_file.write('\n======================================================================================\n\n')
log_file.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment