check how many files are added or modified or deleted by git command and python

来源:互联网 发布:linux enca 编辑:程序博客网 时间:2024/06/05 03:38
1. search_all_effective_commit_include_reverted

def remember_commit(file_name, commit_id):
    print "remember_commit:"
    print commit_id;
    read = file(file_name,'a+')
    read.write(commit_id)
    read.write("\n")
    read.close()

def search_all_effective_commit_include_reverted():
    commit_tag = "commit"
    commit_len = 6
    commit_begin = False
    # not found
    found = -1
    read = open("git.log")
    key_not_check = ("Revert", "Other")
    record_commit = True;
    commit_id = "start:";
    line=read.readline()  
    while line:
        equal = cmp(line[0:commit_len],commit_tag)
        if equal == 0:
            if record_commit == True:
                remember_commit("commit_found", commit_id)
            else:
                print "find record_commit is false"
            record_commit = True
            commit_id = line[7:]
                
        else:
            for i in range(2):
                found = line.find(key_not_check[i])
                if found >= 0:
                    print "found integrate or revert"
                    record_commit = False
        line=read.readline()

2. output name-status for each commit to file_list

def produce_file_list():
    read = open("commit_found")
    line=read.readline()  
    while line:
        if len(line) > 1:
            command = "git show "
            line = line.strip('\n')
            command += line
            command += " --name-status --oneline >> ~/file_list.txt"
            print command
            commands.getoutput(command)
        line=read.readline()
    read.close()

3. thought file status, to put file name into different kind record.txt

def write_to_file(file_name,line):
    read = file(file_name,'a+')
    read.write(line)
    read.write("\n")
    read.close()

def format_file_list():
    read = open("/home/demo/file_list.txt")
    line=read.readline()
    str_name = ""  
    while line:
        if cmp(line[0], 'M') == 0:
            str_name = line[1:].strip()
            print str_name
            write_to_file("/home/demo/m.txt",str_name)
        if cmp(line[0], 'A') == 0:
            str_name = line[1:].strip()
            print str_name
            write_to_file("/home/demo/a.txt",str_name)
        if cmp(line[0], 'D') == 0:
            str_name = line[1:].strip()
            print str_name
            write_to_file("/home/demo/d.txt",str_name)
        line=read.readline()
    read.close()

4. manualy remove reverted files from git.log, this can be programed in future.
   it is complicated, for there is double revert.

0 0