mirror of
https://github.com/flatcar/scripts.git
synced 2026-02-26 18:11:45 +01:00
Update cros_changelog to support sort-by-date option.
Other changes:
1. Clean up revision handling to be more forgiving if people want to use
things that don't start with "cros/". Instead, we only enforce that
people use tags if they want to use the one-argument version of
cros_changelog.
2. Tags are quoted in the command-line so that people can, for instance,
diff 'cros/master{2 days ago}' vs 'cros/master{1 day ago}'.
Change-Id: I28c7d77ae83256d4c28411ef589f3e726cc81d80
BUG=chromium-os:8205
TEST=Ran ( ./cros_changelog 0.9.104.0 cros/master > /tmp/test1.html &&
./cros_changelog --sort-by-date 0.9.104.0 cros/master > /tmp/test2.html )
Both commands print changes between 0.9.104.0 and master, but the second command prints results sorted by date.
Review URL: http://codereview.chromium.org/4130009
This commit is contained in:
parent
f8b650ac1a
commit
6ceddf089f
@ -8,6 +8,8 @@
|
||||
|
||||
import cgi
|
||||
from datetime import datetime
|
||||
import operator
|
||||
import optparse
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
@ -136,7 +138,7 @@ def _GrabChanges(path, tag1, tag2):
|
||||
cmd = 'cd %s && git config --get remote.cros.projectname' % path
|
||||
projectname = _GrabOutput(cmd).strip()
|
||||
log_fmt = '%x00%H\t%ce\t%cd\t%s\t%b'
|
||||
cmd_fmt = 'cd %s && git log --format="%s" --date=local %s..%s'
|
||||
cmd_fmt = 'cd %s && git log --format="%s" --date=local "%s..%s"'
|
||||
cmd = cmd_fmt % (path, log_fmt, tag1, tag2)
|
||||
output = _GrabOutput(cmd)
|
||||
commits = []
|
||||
@ -147,29 +149,33 @@ def _GrabChanges(path, tag1, tag2):
|
||||
commits.append(change)
|
||||
return commits
|
||||
|
||||
def _ParseArgs():
|
||||
parser = optparse.OptionParser()
|
||||
parser.add_option("--sort-by-date", dest="sort_by_date", default=False,
|
||||
action='store_true', help="Sort commits by date.")
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
def main():
|
||||
tags = _GrabTags()
|
||||
tag1 = None
|
||||
if len(sys.argv) == 3:
|
||||
tag1 = sys.argv[1]
|
||||
tag2 = sys.argv[2]
|
||||
elif len(sys.argv) == 2:
|
||||
tag2 = sys.argv[1]
|
||||
options, args = _ParseArgs()
|
||||
if len(args) == 2:
|
||||
tag1, tag2 = args
|
||||
elif len(args) == 1:
|
||||
tag2, = args
|
||||
if tag2 in tags:
|
||||
tag1 = tags[tags.index(tag2) + 1]
|
||||
else:
|
||||
print >>sys.stderr, 'Unrecognized tag: %s' % tag2
|
||||
sys.exit(1)
|
||||
else:
|
||||
print >>sys.stderr, 'Usage: %s [tag1] tag2' % sys.argv[0]
|
||||
print >>sys.stderr, 'If only one tag is specified, we view the differences'
|
||||
print >>sys.stderr, 'between that tag and the previous tag. You can also'
|
||||
print >>sys.stderr, 'specify cros/master to show differences with'
|
||||
print >>sys.stderr, 'tip-of-tree.'
|
||||
sys.exit(1)
|
||||
if not tag2.startswith('cros/') and tag2 not in tags:
|
||||
print >>sys.stderr, 'Unrecognized tag: %s' % tag2
|
||||
sys.exit(1)
|
||||
if not tag1:
|
||||
tag1 = tags[tags.index(tag2) + 1]
|
||||
if not tag1.startswith('cros/') and tag1 not in tags:
|
||||
print >>sys.stderr, 'Unrecognized tag: %s' % tag1
|
||||
print >>sys.stderr, 'E.g. %s %s cros/master' % (sys.argv[0], tags[0])
|
||||
sys.exit(1)
|
||||
|
||||
print >>sys.stderr, 'Finding differences between %s and %s' % (tag1, tag2)
|
||||
@ -185,7 +191,11 @@ def main():
|
||||
cols = ['Project', 'Date', 'Commit', 'Committer', 'Bugs', 'Subject']
|
||||
print '<table border="1" cellpadding="4">'
|
||||
print '<tr><th>%s</th>' % ('</th><th>'.join(cols))
|
||||
for change in sorted(changes):
|
||||
if options.sort_by_date:
|
||||
changes.sort(key=operator.attrgetter("commit_date"))
|
||||
else:
|
||||
changes.sort()
|
||||
for change in changes:
|
||||
print change.AsHTMLTableRow()
|
||||
print '</table>'
|
||||
print '</html>'
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user