Last active
April 17, 2018 12:41
-
-
Save tepie/8d353525e4afebf971f14b5b2b3ee857 to your computer and use it in GitHub Desktop.
cvs_patch_from_log.py will take a changelog from CVS and generate diff commands for that given files to execute for code review. run_codereivew.sh is an example of how to execute, CODEREVIEW.LOG contains the cvs changelog, CODEREVIEW.SH contains the diff commands generated which can be executed and then examined for code review.
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
#!/usr/bin/python | |
import os, sys, re, time | |
if __name__ == '__main__': | |
cvs_log = open(sys.argv[1]) | |
patch_file = None | |
if len(sys.argv) > 2: | |
patch_file = sys.argv[2] | |
sys.stderr.write("patch_file value is %s\n" % patch_file) | |
start_row = False | |
log_row = 0 | |
log_file = None | |
new_rev = None | |
old_rev = None | |
re_start = re.compile("Checking in") | |
review_dir = "review-%s" % time.time() | |
sys.stdout.write("mkdir ../%s \n" % (review_dir)) | |
line_num = 0 | |
for line in cvs_log: | |
#sys.stderr.write(line) | |
is_start = re_start.search(line) | |
if not is_start == None: | |
start_row = True | |
log_row = 1 | |
log_file = None | |
new_rev = None | |
old_rev = None | |
#sys.stderr.write("Line matches the start of a cvs log entry\n") | |
elif start_row: | |
#sys.stderr.write("log_row value is %s\n" % log_row) | |
#sys.stderr.write("log_file value is %s\n" % log_file) | |
if log_row == 1: | |
log_file = re.split(",",line)[0].lstrip() | |
log_file = re.sub("^.*/home/cvs/ecomaurora/","",log_file) | |
log_row = 2 | |
elif log_row == 2: | |
rev_parts = re.split("; ",line) | |
new_rev = re.split(": ",rev_parts[0])[1] | |
#sys.stderr.write("new_rev value is '%s'\n" % new_rev) | |
if len(rev_parts) == 2: | |
old_rev = re.split(": ",rev_parts[1])[1].rstrip() | |
else: | |
old_rev = None | |
log_row = 3 | |
elif log_row == 3: | |
start_row = False | |
log_row = 0 | |
log_file_short = re.split("/",log_file)[-1] | |
if not old_rev == None: | |
if patch_file == None: | |
out_diff_name = "../%s/%s - %s - %s - %s.diff" % (review_dir,line_num,log_file_short,new_rev,old_rev) | |
sys.stdout.write("cvs diff -u -r %s -r %s %s > \"%s\" \n" % (old_rev,new_rev,log_file, out_diff_name)) | |
else: | |
out_diff_name = "../%s/%s" % (review_dir,patch_file) | |
sys.stdout.write("cvs diff -u -r %s -r %s %s >> \"%s\" \n" % (old_rev,new_rev,log_file, out_diff_name)) | |
else: | |
sys.stderr.write("%s has no old revision, must be new\n" % log_file) | |
line_num = line_num + 1 | |
cvs_log.close() |
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
python cvs_patch_from_log.py ../CODEREVIEW.LOG CODEREVIEW.DIFF > ../CODEREVIEW.SH; source ../CODEREVIEW.SH; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment