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

本文介绍了一款用于分析Git日志的工具,该工具能够记录有效的提交(包括撤销的提交),并能输出每个提交涉及的文件状态到指定文件中。此外,还提供了将不同状态的文件名归类记录的功能。
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.

出现 'Error: Trunk or Hybrid port(s) can not be added or deleted in this manner.' 错误,意味着不能以当前方式添加或删除 Trunk 或 Hybrid 端口到 VLAN。下面是可能的解决方法: #### 1. 检查端口类型并转换 若端口为 Trunk 或 Hybrid 类型,要先把端口类型转换为 Access 类型,之后再添加到 VLAN。示例代码如下: ```plaintext <HuaWei-S5700-01>system-view [HuaWei-S5700-01]interface GigabitEthernet 0/0/1 [HuaWei-S5700-01-GigabitEthernet0/0/1]port link-type access [HuaWei-S5700-01-GigabitEthernet0/0/1]port access vlan 2 [HuaWei-S5700-01-GigabitEthernet0/0/1]quit ``` #### 2. 使用 Trunk 或 Hybrid 端口专门的配置方法 如果需要端口保持 Trunk 或 Hybrid 类型,就使用专门的配置方法。 对于 Trunk 端口: ```plaintext <HuaWei-S5700-01>system-view [HuaWei-S5700-01]interface GigabitEthernet 0/0/1 [HuaWei-S5700-01-GigabitEthernet0/0/1]port link-type trunk [HuaWei-S5700-01-GigabitEthernet0/0/1]port trunk allow-pass vlan 2 [HuaWei-S5700-01-GigabitEthernet0/0/1]quit ``` 对于 Hybrid 端口: ```plaintext <HuaWei-S5700-01>system-view [HuaWei-S5700-01]interface GigabitEthernet 0/0/1 [HuaWei-S5700-01-GigabitEthernet0/0/1]port link-type hybrid [HuaWei-S5700-01-GigabitEthernet0/0/1]port hybrid tagged vlan 2 [HuaWei-S5700-01-GigabitEthernet0/0/1]quit ``` #### 3. 检查端口状态 要保证端口没有处于错误禁用或者其他异常状态,可使用 `display interface GigabitEthernet 0/0/1` 命令查看端口状态,若端口异常,使用 `undo shutdown` 命令开启端口。 ```plaintext <HuaWei-S5700-01>display interface GigabitEthernet 0/0/1 <HuaWei-S5700-01>system-view [HuaWei-S5700-01]interface GigabitEthernet 0/0/1 [HuaWei-S5700-01-GigabitEthernet0/0/1]undo shutdown [HuaWei-S5700-01-GigabitEthernet0/0/1]quit ```
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值