自动从svn log中逐一分析是否修改过某字符串

来源:互联网 发布:pdf修改器mac版 编辑:程序博客网 时间:2024/06/08 10:44

刚才我在n个月前待过的一个组的同学问我的某个文件的某几行代码是不是我提交的,为什么要那么写。在感慨岁月不饶人记忆力急剧衰退的同时,我也发出了这样的疑问,这玩意是我造的么,怎么看都不像啊。看着这个文件上百次的svn提交log,一阵晕,这要找到,得等到新玛雅历了。。。我决定还是来段脚本吧。

 

#!/usr/bin/python# -*- coding:utf-8 -*-'''先取最新100个记录,如果还没找到,从上一次批量查询里最老版本号,继续增量往前找。'''import osimport sysimport readlinesvnpath = "http://svn.xx.com/xxxxx/../xx.cc";step=100pattern = "pthread_mutex_lock"def thankyou():  print "thank you, bye."  sys.exit()def seek(_vers, _filepath, _pattern):  for i in range(len(_vers)-1):    content = ""    isfound = False    cmd = "svn diff -r%s:%s %s" % (_vers[i+1], _vers[i], _filepath)    for line in os.popen(cmd) :      content += line      if line.find(_pattern)>=0 :        isfound = True    if isfound:      print content      while True :        try:          cmd = raw_input("Continue?(Y/N)")        except EOFError:          thankyou()        except KeyboardInterrupt:          thankyou()        if cmd.upper() == 'Y':          break        else:          thankyou()def getvers(_ver, _step, _filepath):  _vers = []  if _ver:    cmd = "svn log --quiet -r%d:1 --limit %d %s | grep -o -e 'r[0-9]\+'" % (_ver, _step, _filepath)  else:    cmd = "svn log --quiet --limit %d %s | grep -o -e 'r[0-9]\+'" % (_step, _filepath)  for line in os.popen(cmd):    _vers.append(line.strip()[1:])  return _versif __name__ == "__main__":  lastver = 1  while lastver:    lastver -= 1    versions = getvers(lastver, step, svnpath)    lens = len(versions)    if lens :      seek(versions, svnpath, pattern)      if lens == step:        lastver = int(versions[lens-1])+1      else:        lastver = 0
原创粉丝点击