| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 | #!/usr/bin/env python# git-changelog## version 2.0, by John Wiegley## The purpose of this code is to turn "git log" output into a complete# ChangeLog, for projects who wish to begin using a ChangeLog, but haven't# been.## This version of git-changelog depends on GitPython:#   git://gitorious.org/git-python/mainline.gitimport timeimport stringimport sysimport reimport osfrom git import *               # GitPythonfrom subprocess import *repo = Repo(os.getcwd())ref  = 'origin/master..'path = ''# Usage: git changelog [COMMITISH] [-- [PATH]]saw_dashdash = Falseif len(sys.argv) > 1:    for arg in sys.argv[1:]:        if arg == "--":            saw_dashdash = True        elif saw_dashdash:            path = arg        else:            ref = argfor commit in repo.iter_commits(ref, paths=path):    hash_id  = commit.sha    author   = commit.author    date     = commit.committed_date    log_text = commit.message.split('\n')[0]    log_text_remainder = commit.message.split('\n\n')[1:]    while len(log_text_remainder) > 0 and not log_text_remainder[0]:        log_text_remainder = log_text_remainder[1:]    log_text_remainder = string.join(log_text_remainder, '\n\t')    if log_text_remainder:        log_text_remainder = '\n\t' + log_text_remainder    diff = commit.diff(commit.parents[0])    files = []    for f in diff:        p = f.a_blob.path or f.b_blob.path        p2 = re.sub('^' + path + '/', '', p)        if p != p2:            files.append(p2)    fp = Popen(["fmt", "-72"], shell = True, stdin = PIPE, stdout = PIPE)    fp.stdin.write("\t* %s: %s" % (string.join(files, ",\n\t"), log_text))    fp.stdin.close()    log_text = fp.stdout.read()    del fp    print "%s  %s  <%s>\n\n%s%s" % \        (time.strftime("%Y-%m-%d", time.gmtime(date)),         author.name, author.email, log_text, log_text_remainder)# git-changelog ends here
 |