Chinaunix首页 | 论坛 | 博客
  • 博客访问: 233760
  • 博文数量: 53
  • 博客积分: 1910
  • 博客等级: 中尉
  • 技术积分: 1130
  • 用 户 组: 普通用户
  • 注册时间: 2010-05-10 14:56
文章分类

全部博文(53)

文章存档

2013年(1)

2012年(17)

2011年(33)

2010年(2)

分类: Python/Ruby

2012-05-16 08:57:07

git log 本来很好用,但只对一个project ,对andorid 一般对于一个人工作在多个project 上的情况,要是要查某人某段时间commit 了什么
比较麻烦,于是给repo 打个补丁,添加一条repo revision  命令,

命令格式:
repo revision  [--since=date] [--before=date] [author=name] [project_name]

date 只能是日期,包含了time 后,git log 查出来不准,不知道为什么?

修改方法
1.为了输出醒目一点,要给term 一点颜色,repo  里也有color 的class 但是比较麻烦
 网上下了个termcolor.py
2.prject.py 做点修改
  头上加上:
from termcolor import colored
ID_RE = re.compile('^[0-9a-f]{40}$')
末尾加上:
  def PrintLogs111(self,since,after,author):
    """Prints  .
    """

    out = StatusColoring(self.config)
    cmd=['log']
    if since.__len__()!=0:
      param='--since="'+since+'"'
      cmd.extend([param])

    if after.__len__()!=0:
      param='--until="'+after+'"'
      cmd.extend([param])
  
    
     p = GitCommand(self,
                   cmd,
     #bare=False,
                   capture_stdout = True,
                   capture_stderr = True)
    bfirst=1
    
    print_clist=[]
    commit_list=[]
    add_plist = True
    project_line=[self.name, 'green','on_red']
    #secno=0
    for line in p.process.stdout:

     #find commit
        str=line[:-1]
 str.lstrip()
 str.rstrip()
 #if str=='':
 #  continue
 #stmp=str.split(' ')
 str1=str[:7]
 str1=str1[:-1]
 str2=str[7:]
 #print str

 if str1=='commit':
   if ID_RE.match(str2):
      # finded!
      if (commit_list) and (add_plist==True):
         # add to print_clist
  #print commit_list
                print_clist.extend(commit_list)

             add_plist = True
      commit_list=[]
      startline='|**********************************************|'
      tmp1=[startline, 'yellow',None]
             commit_list.append(tmp1)
        elif (author.__len__()!=0) and (str1=='Author'):
   #print  'judge author'
   if str2.rfind(author)==-1:
      add_plist=False

        #find comment
 if str.startswith(" "):
    tmp1=[str,'green',None] 
        else:
    tmp1=[str,None,None]
       
 #print tmp1
        commit_list.append(tmp1)


        #print line
        #print line[:-1]  # remove 0x0d
 #out.write(str)
 #out.nl()
 #strs=line.spilit()
 #if bfirst==1 and strs[0]='commit':
   
    if (commit_list) and (add_plist==True):
       print_clist.extend(commit_list)
   
    p.Wait()
   
    if print_clist:
       print ""
       print colored(project_line[0],project_line[1],project_line[2])
       for item in print_clist:
          print colored(item[0],item[1],item[2])



3.添加一个revision.py 命令:

from command import PagedCommand #(for diff)

#from command import InteractiveCommand

class Revision(PagedCommand):
  common = True
  helpSummary = "git all procject log"
  helpUsage = """
%prog [datetime ...]
"""
  def _Options(self, p):
    p.add_option('--since',
                 type='string',dest='since', action='store',
                 help='since date')
    p.add_option('--before',
                 type='string',dest='after', action='store',
                 help='after date')

    p.add_option('--author',
                 type='string',dest='author', action='store',
                 help='author')

  def Execute(self, opt, args):
    since =""
    after =""
    author =""

    #if not args:
    #  self.Usage()

    if opt.since:
       since=opt.since

    if opt.after:
       after=opt.after

    if opt.author:
       author=opt.author


    for project in self.GetProjects(args):
      project.PrintLogs111(since,after,author)
    
  
输入命令:
repo revision --since=2009-08-13  --after=2009-08-14  --author=xxx
可以了解下xxx 8/13 号,在所有project 上做了那些修改

termcolor.py : termcolor.zip   

(转载请注名出处)

阅读(2100) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~
评论热议
请登录后评论。

登录 注册